5

I'm trying to set up a basic automated test in the browser against a react app, using webdriver and Jasmine. I'm using page object models to describe my app under test, like so:

Example page object from JasmineBDD

I'm running Jasmine fine, and slurping up the spec. However after the browser spawns, I get a module error

import { SplashScreen } from './page_models/splash_screen.page'
^^^^^^

SyntaxError: Cannot use import statement outside a module

I'm initiating the test with a local call to wdio, node node_modules/.bin/wdio ./spec/support/wdio.conf.js . How do I run my Jasmine spec code in an environment so that it's inside a module context ?

Thanks :)

ether_joe
  • 841
  • 13
  • 24

2 Answers2

0

Turns out I needed to call babel/register in my jasmine config like so:

   beforeSession: function (config, capabilities, specs) {
      require('@babel/register');
    },
ether_joe
  • 841
  • 13
  • 24
0

ES6 import/export not supported in nodejs version < 13 . You need to use legacy require, or use Babel/Typescript to transform your code from import/export to old syntax.

In nodejs 13+ you can enable ES6 import/export support. This is untested, so might be some underwater rocks. But you can try: https://medium.com/@nodejs/announcing-core-node-js-support-for-ecmascript-modules-c5d6dc29b663

Xotabu4
  • 2,927
  • 12
  • 27