I am facing an issue while trying to set up a suite of end-to-end tests using wdio. Some of the tests utilize utility classes written in TypeScript.
During the compilation of the test, I encountered the following error:
Spec file(s): D:\TEMP\xx\angular-wdio6-builder-demo\e2e\test\specs\basic.spec.ts
Error: D:\TEMP\xx\angular-wdio6-builder-demo\e2e\test\specs\basic.spec.ts:1
import {Util} from '../util/util.spec';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:1054:16)
at Module._compile (internal/modules/cjs/loader.js:1102:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
at D:\TEMP\xx\angular-wdio6-builder-demo\node_modules\@wdio\jasmine-framework\node_modules\jasmine\lib\jasmine.js:89:5
at Array.forEach (<anonymous>)
at Jasmine.loadSpecs (D:\TEMP\xx\angular-wdio6-builder-demo\node_modules\@wdio\jasmine-framework\node_modules\jasmine\lib\jasmine.js:88:18)
[0-0] RUNNING in chrome - D:\TEMP\xx\angular-wdio6-builder-demo\e2e\test\specs\basic.spec.ts
The above error message is from a version of one of the WebdriverIO Boilerplate Projects. The only modification I made (besides updating chromedriver) was transitioning the sample test to TypeScript and incorporating a utility class.
I have attempted various solutions found online, but none have resolved the issue with executing this basic test. It appears that no babel configuration is being recognized.
You can find the source code at https://github.com/rgansevles/angular-wdio6-builder-demo (cloned from https://github.com/migalons/angular-wdio6-builder-demo)
To replicate the problem, clone my repository and run:
npm install
npm run e2e
If anyone has a solution for enabling the import statement in this particular scenario, your input would be greatly appreciated.
Thank you in advance,
Rob
By the way, here is the content of the failing test file located at e2e/test/specs/basic.spec.ts :
import {Util} from '../util/util.spec';
const util = new Util();
describe('webdriver.io page', () => {
it('should have the right title', () => {
browser.url('');
const title = browser.getTitle();
expect(title).toEqual(util.browserTitle);
});
it('should say app is running', () => {
browser.url('');
const message = $('body > app-root > div.content > div.card.highlight-card.card-small > span').getText();
expect(message).toEqual('angular-wdio6-builder-demo app is running!');
});
});