I'm trying to run a Cypress test with ES2018 syntax:
describe("Cypress test", () => {
const objA = { a: 1, b: 2 };
const objB = { ...objA };
...
}
But when executed, I'm getting:
SyntaxError: /....../cypress/loginTest.js: Unexpected token (29:17)
27 |
28 | const objA = { a: 1, b: 2 };
> 29 | const objB = { ...objA };
| ^
I also tried to check browserify presets with following plugin:
// plugins.js
const browserify = require("@cypress/browserify-preprocessor");
module.exports = (on) => {
const options = browserify.defaultOptions;
// Check presets
console.log(options.browserifyOptions.transform[1][1].presets);
on("file:preprocessor", browserify(options));
};
and it seems to already have babel-preset-env
set-up.
Any ideas, please?
Not sure if this will help, but here's what worked for me:
I've managed to pretty painlessly enable the new es features (incl. spread operator), just using the cypress-webpack-preprocessor
plugin and the examples here
More info can be found in this discussion: https://github.com/cypress-io/cypress/issues/905 and in cypress' documentation
Note, that you also have to include the desired babel presets as node
dependencies in your package.json
file and install them!
I've also found this pre-processor: cypress-babel-esx-preprocessor, but never got to trying it, since the webpacker solution worked straight away.
Finally, you may also want to watch this request for updating Chrome version in cypress's Electron, as it's supposed to enable es-2018 just out of the box.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With