How to import / export es6 in Nightwatch test?

I want to import a utility module into my test file that is written in ES6 and exports a few things that I need. So what i do

import { module } from 'file'

but it throws the error "SyntaxError: Unexpected token import."

I tried:

  • add require('babel-core/register')nightwatch.conf.js to the beginning
  • add require('babel-register')()nightwatch.conf.js to the beginning
  • npm i babel-plugin-add-module-exports --save-dev and add the add-module-exports plugin to the .babelrc configuration file
  • npm i babel-preset-es2015 --save-dev and add the es2015 preset to the .babelrc configuration file
  • add

    required ('Babel-core') required ('Babel-loader') require ('Babel-plug-in-add-module-export') required ('babel-polyfill') required ('Babel-programmed stage-2') required ('pandemonium-preloaded es2015')

at the top of nightwatch.conf.js

. , /?

,

+4
1

, , , :

"presets": [
    ["es2015", { "modules": false }]
  ],

{ "modules": false} . , / :

1 nightwatch.config

require('babel-register')() // or require('babel-core/register')

2.babelrc

{
  "presets": ["es2015"],
  "plugins": [
    "add-module-exports",
  ]
}

3 babel

npm i babel-plugin-add-module-exports babel-core babel-preset-es2015 --save-dev
+7

Source: https://habr.com/ru/post/1668653/


All Articles