Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Support for ES2018 in Cypress tests? (Object spread operator)

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?

like image 854
Stano Avatar asked Jun 04 '18 07:06

Stano


1 Answers

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.

like image 77
Evgeniya Manolova Avatar answered Sep 29 '22 17:09

Evgeniya Manolova