I am trying to use cypress select tests but facing the following exception. Did anyone face this issue before?
cypress/plugins/index.ts
const TC_GROUPING = require('cypress-select-tests/grep')
module.exports = (on, config) => {
require('cypress-terminal-report/src/installLogsPrinter')(on, {
printLogsToConsole: 'always'
}
)
on('file:preprocessor', TC_GROUPING(config))
on('task', {
// Returns the customer Object of type: Customer
createCustomer: () => {
console.log("This is Sample Function")
}
})
return config
}
Error Message:
SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (17:0)
at Parser.pp$4.raise (/Users/saahithg/workspace/ElmoCypressFinal/src/ElmoCypress/node_modules/acorn/dist/acorn.js:2927:15)
at Parser.pp$1.parseStatement (/Users/saahithg/workspace/ElmoCypressFinal/src/ElmoCypress/node_modules/acorn/dist/acorn.js:870:18)
at Parser.pp$1.parseTopLevel (/Users/saahithg/workspace/ElmoCypressFinal/src/ElmoCypress/node_modules/acorn/dist/acorn.js:755:23)
at Parser.parse (/Users/saahithg/workspace/ElmoCypressFinal/src/ElmoCypress/node_modules/acorn/dist/acorn.js:555:17)
at Function.parse (/Users/saahithg/workspace/ElmoCypressFinal/src/ElmoCypress/node_modules/acorn/dist/acorn.js:578:37)
at Object.parse (/Users/saahithg/workspace/ElmoCypressFinal/src/ElmoCypress/node_modules/acorn/dist/acorn.js:5143:19)
at module.exports (/Users/saahithg/workspace/ElmoCypressFinal/src/ElmoCypress/node_modules/falafel/index.js:23:22)
at Object.findTests (/Users/saahithg/workspace/ElmoCypressFinal/src/ElmoCypress/node_modules/cypress-select-tests/src/spec-parser.js:95:3)
at process (/Users/saahithg/workspace/ElmoCypressFinal/src/ElmoCypress/node_modules/cypress-select-tests/src/itify.js:18:33)
at Stream.onend (/Users/saahithg/workspace/ElmoCypressFinal/src/ElmoCypress/node_modules/cypress-select-tests/src/itify.js:52:18)
at _end (/Users/saahithg/workspace/ElmoCypressFinal/src/ElmoCypress/node_modules/through/index.js:65:9)
at Stream.stream.end (/Users/saahithg/workspace/ElmoCypressFinal/src/ElmoCypress/node_modules/through/index.js:74:5)
at DestroyableTransform.onend (/Users/saahithg/workspace/ElmoCypressFinal/src/ElmoCypress/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:577:10)
at Object.onceWrapper (events.js:416:28)
at DestroyableTransform.emit (events.js:322:22)
at endReadableNT (/Users/saahithg/workspace/ElmoCypressFinal/src/ElmoCypress/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:1010:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
Error: The following error was thrown by a plugin. We stopped running your tests because a plugin crashed. Please check your plugins file (`/Users/saahithg/workspace/ElmoCypressFinal/src/ElmoCypress/cypress/plugins/index.ts`)
at Object.get (/private/tmp/cypress_cache/5.4.0/Cypress.app/Contents/Resources/app/packages/server/lib/errors.js:968:15)
at EventEmitter.handleError (/private/tmp/cypress_cache/5.4.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/index.js:159:20)
at EventEmitter.emit (events.js:310:20)
at ChildProcess.<anonymous> (/private/tmp/cypress_cache/5.4.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:19:22)
at ChildProcess.emit (events.js:310:20)
at emit (internal/child_process.js:876:12)
at processTicksAndRejections (internal/process/task_queues.js:85:21)
Added the following lines in plugins/index.ts as mentioned in blog: https://en.it1352.com/article/1963119.html but no luck. Did anyone encounter this issue?
const options = {
// send in the options from your webpack.config.js, so it works the same
// as your app's code
webpackOptions: require('../../webpack.config'),
watchOptions: {}
}
on('file:preprocessor', web_pack(options))
webpack.config.js
const path = require('path');
module.exports = {
entry: './src/index.ts',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
};