webdriverio / create-wdio

One-line installer for WebdriverIO
https://webdriver.io
MIT License
21 stars 9 forks source link

[πŸ› Bug]: npm script refers to wrong config when using TypeScript #74

Closed MortenGregersen closed 2 years ago

MortenGregersen commented 2 years ago

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

7.16.13

Node.js Version

14.18.2

Mode

Standalone Mode

Which capabilities are you using?

No response

What happened?

When I initialized wdio in my project, selecting TypeScript as compiler, the CLI created a wdio.config.ts (config file in TypeScript). This is fine, but at the same time, it added a npm script to package.json which refers to wdio.config.js (config file in JavaScript).

It also didn't take into account, where the wdio.config.js/ts was located. Even though I used default values for the initialization (expect using Jasmine and TypeScript), it thought my wdio.config.js/ts was located in the root of the project, but itself created it in ./test/.

What is your expected behavior?

I expected that the CLI would know what file extension the wdio config would have, and where it would be created, so the npm script in package.json would be correct.

How to reproduce the bug.

  1. I ran npm init wdio .
  2. Used default values for the questions except for the following:
    • Which framework do you want to use? jasmine
    • Do you want to use a compiler? TypeScript
  3. Now the npm script in package.json would be "wdio": "wdio run wdio.conf.js"

Relevant log output

Running WDIO CLI Wizard...

=========================
WDIO Configuration Helper
=========================

? Where is your automation backend located? On my local machine
? Which framework do you want to use? jasmine
? Do you want to use a compiler? TypeScript (https://www.typescriptlang.org/)
? Where are your test specs located? ./test/specs/**/*.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? ./test/pageobjects/**/*.ts
? Which reporter do you want to use? spec
? Do you want to add a plugin to your test setup? 
? Do you want to add a service to your test setup? chromedriver
? What is the base url? http://localhost

Installing wdio packages:
- @wdio/local-runner
- @wdio/jasmine-framework
- @wdio/spec-reporter
- wdio-chromedriver-service
- chromedriver

up to date, audited 2836 packages in 12s

191 packages are looking for funding
  run `npm fund` for details

56 vulnerabilities (2 low, 47 moderate, 7 high)

To address issues that do not require attention, run:
  npm audit fix

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.

Packages installed successfully, creating configuration file...

Config file installed successfully, creating test files...
To have TypeScript support please add the following packages to your "types" list:
{
  "compilerOptions": {
    "types": ["node", "webdriverio/async", "@wdio/jasmine-framework", "expect-webdriverio"]
  }
}

For for information on TypeScript integration check out: https://webdriver.io/docs/typescript

Configuration file was created successfully!
To run your tests, execute:
$ npx wdio run test/wdio.conf.ts

Adding scripts to package.json

πŸ€– Successfully setup project at /Users/morten/Projects/awesome-project πŸŽ‰
To start the test, run: $ npm run wdio
➜  awesome-project git:(wdio) βœ— npm run wdio

> micro-frontend-tools@0.0.0 wdio
> wdio run wdio.conf.js

? Error: Could not execute "run" due to missing configuration. Would you like to create one? No

Code of Conduct

Is there an existing issue for this?

christian-bromann commented 2 years ago

Thanks for reporting!

It seems there is a problem detecting TypeScript correctly somewhere here: https://github.com/webdriverio/create-wdio/blob/main/src/index.ts#L110

Any contributions that resolves the bug are highly appreciated. Please take a look into our contribution guidelines and let us know if you have any questions. Cheers!

christian-bromann commented 2 years ago

fixed in #86, thanks @vigneshmohan243 πŸ‘