webdriverio-community / wdio-electron-service

WebdriverIO service for testing Electron applications
https://webdriver.io
MIT License
35 stars 15 forks source link

TypeScript errors since v7.0.4 #810

Open gavvvr opened 2 days ago

gavvvr commented 2 days ago

Steps to reproduce

  1. (Optional, for clean environment) docker run --rm -it --entrypoint=sh node:22-alpine
  2. npm init wdio@latest electron-e2e-ts, choose Electron app testing + TypeScript
  3. Add typescript to get tsc command: cd electron-e2e-ts/ && npm i -D typescript
  4. Adjust test/specs/test.e2e.ts to add something like await $('aria/Submit').click() (some text editor might be needed in Docker, for example: apk add --no-cache vim)
  5. run TS compiler (npx tsc) you'll see:
test/specs/test.e2e.ts:5:25 - error TS2339: Property 'click' does not exist on type 'Element | Promise<Element> | ChainablePromiseElementBase<Promise<Element>>'.
  Property 'click' does not exist on type 'Promise<Element>'.

5  await $('aria/Submit').click()
                          ~~~~~

Initially I noticed the problem in VSCode:

image

Roll back to v7.0.2 fixes the problem: npm uninstall wdio-electron-service && npm i -D wdio-electron-service@7.0.2. Now npx tsc and VSCode are happy.

SaidbekAbdiganiev commented 2 days ago

Do you have a tsconfig.json in the root of the test folder after installation? If not, create it and copy this config.

{
  "compilerOptions": {
    "types": ["@wdio/globals/types", "wdio-electron-service", "mocha"]
  },
  "include": ["**/*.ts"]
}

I remember this being somewhere in the examples, but I have no idea why cli does not provide it by default

gavvvr commented 18 hours ago

Hi @SaidbekAbdiganiev The wdio starter CLI includes correct (I believe) tsconfig.json and it includes the following:

    "types": [
      "node",
      "@wdio/globals/types",
      "expect-webdriverio",
      "@wdio/mocha-framework"
    ],

Unfortunately, tsc reports errors since v7.0.4