Open HymanZHAN opened 3 years ago
I have the same problem. Seems to me, it's caused by the command using the tsconfig
from the root of the project, instead of the e2e one that is created.
The sandbox example project doesn't have any problems, because its tsconfig defines "module": "commonjs",
. Your (and my) project probably have a different value here.
I am not sure if fixing this is something the schematics should do, or if it's the responsibility of the project that implements them, curious about opinions on this.
@jordydejong @HymanZHAN can you provide some WebdriverIO logs?
I'm facing the same issue. The exact error I'm getting is
ERROR @wdio/config:ConfigParser: Failed loading configuration file: /<path>/wdio.conf.ts: Unexpected token 'export'
Unexpected token 'export'
It seems like the configured module in tsconfig.json (es2020) isn't compatible. If I use with "commonjs", webdriver.io works but not the ng test target. Also, I don't want to change the whole project because of the testing framework being used. Additionally, It seems that using individual ts config files for angular targets is not possible at that stage.
I'm using angular 12.2.10
and webdriver 7.14.1
@christian-bromann please tell me what logs are you looking for
please tell me what logs are you looking for
This error above is all necessary to know. Am I assuming right, that your project is using pure ESM? This could be problematic because WebdriverIO doesn't support this yet. It is on the roadmap.
Indeed, this
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2017",
"module": "es2020",
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
seems to be the actual default configuration when creating new angular projects
Recommend to have a separate tsconfig file that compiles to cjs. You can configure the location of that tsconfig file in autoCompileOpts
.
The main issue here is that wdio
is not able to parse wdio.conf.ts
-> Unexpected token 'export'
Using autoCompileOpts
in the configuration file won't work as we can't parsed the file... ^^'
So I was thinking about exposing a new option tsconfigFile
in the schematics schema and use that option to pass down the autoCompileOpts.tsNodeOpts.project
to the wdio launcher. That way the launcher would knows the tsconfig prior to load the wdio.config.ts
and things would work.
I added the schematics and tried run the e2e tests. However, there was an error where it said error parsing the config file.
Installation Output
```shell > ng add @wdio/schematics ℹ Using package manager: npm ✔ Found compatible package version: @wdio/schematics@1.1.0. ✔ Package information loaded. The package @wdio/schematics@1.1.0 will be installed and executed. Would you like to proceed? Yes ✔ Package successfully installed. ========================= WDIO Configuration Helper ========================= ? Where is your automation backend located? On my local machine ? Which framework do you want to use? cucumber ? Do you want to use a compiler? TypeScript (https://www.typescriptlang.org/) ? Where are your feature files located? ./features/**/*.feature ? Where are your step definitions located? ./features/step-definitions/steps.ts ? Do you want WebdriverIO to autogenerate some test files? Yes ? Do you want to use page objects (https://martinfowler.com/bliki/PageObject.html)? Yes ? Where are your page objects located? ./features/pageobjects/**/*.ts ? Which reporter do you want to use? spec, junit ? Do you want to add a service to your test setup? chromedriver ? What is the base url? http://localhost:4200 Installing wdio packages: - @wdio/local-runner - @wdio/cucumber-framework - @wdio/spec-reporter - @wdio/junit-reporter - wdio-chromedriver-service - ts-node - typescript - chromedriver ```Test output
```shell > ng run frontend:wdio-run ⠴ Generating browser application bundles (phase: building)... warn - You have enabled the JIT engine which is currently in preview. warn - Preview features are not covered by semver, may introduce breaking changes, and can change at any time. ✔ Browser application bundle generation complete. Initial Chunk Files | Names | Size vendor.js | vendor | 2.44 MB polyfills.js | polyfills | 128.50 kB main.js | main | 26.88 kB styles.css | styles | 23.84 kB runtime.js | runtime | 6.62 kB | Initial Total | 2.62 MB Build at: 2021-10-03T23:58:50.874Z - Hash: 0cdc5040b623167c275a - Time: 7367ms ** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ ** ✔ Compiled successfully. 2021-10-03T23:58:51.048Z ERROR @wdio/config:ConfigParser: Failed loading configuration file: /home/xzhan/Development/Projects/desci_online/frontend/wdio.conf.ts: Unexpected token 'export' Unexpected token 'export' ````wdio.conf.ts`
```typescript export const config: WebdriverIO.Config = { // // ==================== // Runner Configuration // ==================== // // // ================== // Specify Test Files // ================== // Define which test specs should run. The pattern is relative to the directory // from which `wdio` was called. // // The specs are defined as an array of spec files (optionally using wildcards // that will be expanded). The test for each spec file will be run in a separate // worker process. In order to have a group of spec files run in the same worker // process simply enclose them in an array within the specs array. // // If you are calling `wdio` from an NPM script (see https://docs.npmjs.com/cli/run-script), // then the current working directory is where your `package.json` resides, so `wdio` // will be called from there. // specs: ['./features/**/*.feature'], // Patterns to exclude. exclude: [ // 'path/to/excluded/files' ], // // ============ // Capabilities // ============ // Define your capabilities here. WebdriverIO can run multiple capabilities at the same // time. Depending on the number of capabilities, WebdriverIO launches several test // sessions. Within your capabilities you can overwrite the spec and exclude options in // order to group specific specs to a specific capability. // // First, you can define how many instances should be started at the same time. Let's // say you have 3 different capabilities (Chrome, Firefox, and Safari) and you have // set maxInstances to 1; wdio will spawn 3 processes. Therefore, if you have 10 spec // files and you set maxInstances to 10, all spec files will get tested at the same time // and 30 processes will get spawned. The property handles how many capabilities // from the same test should run tests. // maxInstances: 10, // // If you have trouble getting all important capabilities together, check out the // Sauce Labs platform configurator - a great tool to configure your capabilities: // https://docs.saucelabs.com/reference/platforms-configurator // capabilities: [ { // maxInstances can get overwritten per capability. So if you have an in-house Selenium // grid with only 5 firefox instances available you can make sure that not more than // 5 instances get started at a time. maxInstances: 5, // browserName: 'chrome', acceptInsecureCerts: true, // If outputDir is provided WebdriverIO can capture driver session logs // it is possible to configure which logTypes to include/exclude. // excludeDriverLogs: ['*'], // pass '*' to exclude all driver session logs // excludeDriverLogs: ['bugreport', 'server'], }, ], // // =================== // Test Configurations // =================== // Define all options that are relevant for the WebdriverIO instance here // // Level of logging verbosity: trace | debug | info | warn | error | silent logLevel: 'info', // // Set specific log levels per logger // loggers: // - webdriver, webdriverio // - @wdio/browserstack-service, @wdio/devtools-service, @wdio/sauce-service // - @wdio/mocha-framework, @wdio/jasmine-framework // - @wdio/local-runner // - @wdio/sumologic-reporter // - @wdio/cli, @wdio/config, @wdio/utils // Level of logging verbosity: trace | debug | info | warn | error | silent // logLevels: { // webdriver: 'info', // '@wdio/appium-service': 'info' // }, // // If you only want to run your tests until a specific amount of tests have failed use // bail (default is 0 - don't bail, run all tests). bail: 0, // // Set a base URL in order to shorten url command calls. If your `url` parameter starts // with `/`, the base url gets prepended, not including the path portion of your baseUrl. // If your `url` parameter starts without a scheme or `/` (like `some/path`), the base url // gets prepended directly. baseUrl: 'http://localhost:4200', // // Default timeout for all waitFor* commands. waitforTimeout: 10000, // // Default timeout in milliseconds for request // if browser driver or grid doesn't send response connectionRetryTimeout: 120000, // // Default request retries count connectionRetryCount: 3, // // Test runner services // Services take over a specific job you don't want to take care of. They enhance // your test setup with almost no effort. Unlike plugins, they don't add new // commands. Instead, they hook themselves up into the test process. services: ['chromedriver'], // Framework you want to run your specs with. // The following are supported: Mocha, Jasmine, and Cucumber // see also: https://webdriver.io/docs/frameworks // // Make sure you have the wdio adapter package for the specific framework installed // before running any tests. framework: 'cucumber', // // The number of times to retry the entire specfile when it fails as a whole // specFileRetries: 1, // // Delay in seconds between the spec file retry attempts // specFileRetriesDelay: 0, // // Whether or not retried specfiles should be retried immediately or deferred to the end of the queue // specFileRetriesDeferred: false, // // Test reporter for stdout. // The only one supported by default is 'dot' // see also: https://webdriver.io/docs/dot-reporter reporters: ['spec', 'junit'], // // If you are using Cucumber you need to specify the location of your step definitions. cucumberOpts: { //I am using Node 14.17.5 and Angular 12.2.8. Any help is appreciated!