testing-library / webdriverio-testing-library

🕷️ Simple and complete WebdriverIO DOM testing utilities that encourage good testing practices.
17 stars 14 forks source link

Interface 'Element' cannot simultaneously extend types 'ElementSync' and 'ElementBase' #31

Closed g-farrow closed 3 years ago

g-farrow commented 3 years ago

I am trying to add the @testing-library/webdriverio to my typescript project. However, it is causing the following type errors:

  Named property '$' of types 'ElementSync' and 'ElementBase' are not identical.

14     interface Element extends ElementSync, WebdriverIOSync.Element { }
                 ~~~~~~~

node_modules/webdriverio/sync.d.ts:14:15 - error TS2320: Interface 'Element' cannot simultaneously extend types 'ElementSync' and 'ElementBase'.
  Named property 'execute' of types 'ElementSync' and 'ElementBase' are not identical.

14     interface Element extends ElementSync, WebdriverIOSync.Element { }
                 ~~~~~~~

node_modules/webdriverio/sync.d.ts:14:15 - error TS2320: Interface 'Element' cannot simultaneously extend types 'ElementSync' and 'ElementBase'.
  Named property 'executeAsync' of types 'ElementSync' and 'ElementBase' are not identical.

14     interface Element extends ElementSync, WebdriverIOSync.Element { }

My package.json looks like this:

{
  "name": "webdriverio-sample-appium-tests",
  "version": "1.0.0",
  "description": "Sample tests using webdriverio",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "build": "tsc",
    "appium": "appium",
    "test": "tsc && mocha test",
    "clean": "rm -rf node_modules && rm -f package-lock.json && npm install"
  },
  "mocha": {
    "timeout": "1800000"
  },
  "bundledDependencies": [
    "assert",
    "chai",
    "mocha",
    "webdriverio"
  ],
  "devDependencies": {
    "@testing-library/webdriverio": "^3.0.3",
    "@types/chai": "^4.2.21",
    "@wdio/mocha-framework": "^7.12.0",
    "appium": "^1.21.0",
    "assert": "^2.0.0",
    "chai": "^4.3.4",
    "mocha": "^9.1.1",
    "node": "^16.6.1",
    "node-fetch": "^3.0.0",
    "ts-node": "^10.2.1",
    "typescript": "^4.4.2",
    "webdriverio": "^7.12.1"
  }
}

I'm guessing that there is a conflicting type version between webdriverio and the testing library but I don't know how to resolve it.

Any ideas?

olivierwilkinson commented 3 years ago

Hi there 👋

Thanks for raising this! I'll look into it as soon as I can, probably later today 😄

We use stub types internally to support multiple versions of wdio at once, it looks like the type for execute is incompatible with v7.12.1. I think the type of that stub is just too specific to one version so it should just be a case making it a little looser.

I'll let you know how I get on 👍

olivierwilkinson commented 3 years ago

Btw do you have a link to a public repo I can look at so I can replicate your setup? Or your tsconfig would also be useful if not 😁

g-farrow commented 3 years ago

hi @olivierwilkinson - thanks for responding. I have put together https://github.com/g-farrow/test-appium-project as an example. npm i followed by npm run test should show the error I am seeing.

olivierwilkinson commented 3 years ago

hi @olivierwilkinson - thanks for responding. I have put together https://github.com/g-farrow/test-appium-project as an example. npm i followed by npm run test should show the error I am seeing.

Ah brilliant thank you very much for doing that! I'll have a look as soon as I can 👍

olivierwilkinson commented 3 years ago

@g-farrow just wanted to let you know I've found the issue, thanks for the repo it made it much easier to track down! I'll raise a PR with an explanation and a fix later today after work. 👍

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 3.0.4 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

olivierwilkinson commented 3 years ago

@g-farrow I merged the PR since I was pretty confident it at least fixes a related problem. Let me know if it still doesn't work for you with v3.0.4 and I'll reopen this or create a new issue 👍.

Thanks again for raising this!

g-farrow commented 3 years ago

Hi @olivierwilkinson thanks for the fix.

However, I'm now seeing a whole bunch of different typescript errors. I have bumped all deps in that project to the latest versions and now I get this:

node_modules/@wdio/mocha-framework/node_modules/@wdio/types/build/index.d.ts:23:13 - error TS2374: Duplicate index signature for type 'string'.

23             [key: string]: any;
               ~~~~~~~~~~~~~~~~~~~

node_modules/@wdio/mocha-framework/node_modules/@wdio/types/build/index.d.ts:26:13 - error TS2374: Duplicate index signature for type 'string'.

26             [key: string]: any;
               ~~~~~~~~~~~~~~~~~~~

node_modules/@wdio/mocha-framework/node_modules/@wdio/types/build/index.d.ts:29:13 - error TS2374: Duplicate index signature for type 'string'.

29             [key: string]: any;
               ~~~~~~~~~~~~~~~~~~~

node_modules/@wdio/mocha-framework/node_modules/@wdio/types/build/index.d.ts:43:14 - error TS2300: Duplicate identifier 'Capabilities'.

43         type Capabilities = Capabilities.Capabilities;
                ~~~~~~~~~~~~

  node_modules/@wdio/types/build/index.d.ts:43:14
    43         type Capabilities = Capabilities.Capabilities;
                    ~~~~~~~~~~~~
    'Capabilities' was also declared here.

node_modules/@wdio/mocha-framework/node_modules/@wdio/types/build/index.d.ts:44:14 - error TS2300: Duplicate identifier 'DesiredCapabilities'.

44         type DesiredCapabilities = Capabilities.DesiredCapabilities;
                ~~~~~~~~~~~~~~~~~~~

  node_modules/@wdio/types/build/index.d.ts:44:14
    44         type DesiredCapabilities = Capabilities.DesiredCapabilities;
                    ~~~~~~~~~~~~~~~~~~~
    'DesiredCapabilities' was also declared here.

node_modules/@wdio/types/build/index.d.ts:23:13 - error TS2374: Duplicate index signature for type 'string'.

23             [key: string]: any;
               ~~~~~~~~~~~~~~~~~~~

node_modules/@wdio/types/build/index.d.ts:26:13 - error TS2374: Duplicate index signature for type 'string'.

26             [key: string]: any;
               ~~~~~~~~~~~~~~~~~~~

node_modules/@wdio/types/build/index.d.ts:29:13 - error TS2374: Duplicate index signature for type 'string'.

29             [key: string]: any;
               ~~~~~~~~~~~~~~~~~~~

node_modules/@wdio/types/build/index.d.ts:35:19 - error TS2320: Interface 'Config' cannot simultaneously extend types 'Testrunner' and 'Testrunner'.
  Named property 'after' of types 'Testrunner' and 'Testrunner' are not identical.

35         interface Config extends Options.Testrunner {
                     ~~~~~~

node_modules/@wdio/types/build/index.d.ts:35:19 - error TS2320: Interface 'Config' cannot simultaneously extend types 'Testrunner' and 'Testrunner'.
  Named property 'afterSession' of types 'Testrunner' and 'Testrunner' are not identical.

35         interface Config extends Options.Testrunner {
                     ~~~~~~

node_modules/@wdio/types/build/index.d.ts:35:19 - error TS2320: Interface 'Config' cannot simultaneously extend types 'Testrunner' and 'Testrunner'.
  Named property 'before' of types 'Testrunner' and 'Testrunner' are not identical.

35         interface Config extends Options.Testrunner {
                     ~~~~~~

node_modules/@wdio/types/build/index.d.ts:35:19 - error TS2320: Interface 'Config' cannot simultaneously extend types 'Testrunner' and 'Testrunner'.
  Named property 'beforeSession' of types 'Testrunner' and 'Testrunner' are not identical.

35         interface Config extends Options.Testrunner {
                     ~~~~~~

node_modules/@wdio/types/build/index.d.ts:35:19 - error TS2320: Interface 'Config' cannot simultaneously extend types 'Testrunner' and 'Testrunner'.
  Named property 'capabilities' of types 'Testrunner' and 'Testrunner' are not identical.

35         interface Config extends Options.Testrunner {
                     ~~~~~~

node_modules/@wdio/types/build/index.d.ts:35:19 - error TS2320: Interface 'Config' cannot simultaneously extend types 'Testrunner' and 'Testrunner'.
  Named property 'onComplete' of types 'Testrunner' and 'Testrunner' are not identical.

35         interface Config extends Options.Testrunner {
                     ~~~~~~

node_modules/@wdio/types/build/index.d.ts:35:19 - error TS2320: Interface 'Config' cannot simultaneously extend types 'Testrunner' and 'Testrunner'.
  Named property 'onPrepare' of types 'Testrunner' and 'Testrunner' are not identical.

35         interface Config extends Options.Testrunner {
                     ~~~~~~

node_modules/@wdio/types/build/index.d.ts:35:19 - error TS2320: Interface 'Config' cannot simultaneously extend types 'Testrunner' and 'Testrunner'.
  Named property 'onWorkerStart' of types 'Testrunner' and 'Testrunner' are not identical.

35         interface Config extends Options.Testrunner {
                     ~~~~~~

node_modules/@wdio/types/build/index.d.ts:35:19 - error TS2320: Interface 'Config' cannot simultaneously extend types 'Testrunner' and 'Testrunner'.
  Named property 'services' of types 'Testrunner' and 'Testrunner' are not identical.

35         interface Config extends Options.Testrunner {
                     ~~~~~~

node_modules/@wdio/types/build/index.d.ts:43:14 - error TS2300: Duplicate identifier 'Capabilities'.

43         type Capabilities = Capabilities.Capabilities;
                ~~~~~~~~~~~~

  node_modules/@wdio/mocha-framework/node_modules/@wdio/types/build/index.d.ts:43:14
    43         type Capabilities = Capabilities.Capabilities;
                    ~~~~~~~~~~~~
    'Capabilities' was also declared here.

node_modules/@wdio/types/build/index.d.ts:44:14 - error TS2300: Duplicate identifier 'DesiredCapabilities'.

44         type DesiredCapabilities = Capabilities.DesiredCapabilities;
                ~~~~~~~~~~~~~~~~~~~

  node_modules/@wdio/mocha-framework/node_modules/@wdio/types/build/index.d.ts:44:14
    44         type DesiredCapabilities = Capabilities.DesiredCapabilities;
                    ~~~~~~~~~~~~~~~~~~~
    'DesiredCapabilities' was also declared here.

I have pushed up those changes so you should be able to pull and see the errors yourself.

olivierwilkinson commented 3 years ago

@g-farrow I think that is a problem in the @wdio/mocha-framework package, possibly with the version of Typescript installed? I'm not sure entirely. I raised a PR into your test-appium-project though which fixes the compilation, if you want to talk through anything else that comes up I'm more than happy to do that on the PR 😄

g-farrow commented 3 years ago

Confirmed this works, thanks @olivierwilkinson