Codeceptjs: @types/mocha dependency in 2.3.6 breaks when using jest

Created on 27 Nov 2019  路  8Comments  路  Source: codeceptjs/CodeceptJS

What are you trying to achieve?

I am using jest as my unit test framework for a typescript project and wish to use codeceptjs to run browser tests. I am able to run both with [email protected] but upgrading to [email protected] causes breaks when building my application.

It looks like the inclusion of @types/mocha as a dependency in the 2.3.6 release is conflicting with my local @types/jest definitions.

What do you get instead?

When attempting to build the project I get lots of the following errors:

node_modules/@types/mocha/index.d.ts:2680:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'beforeEach' must be of type 'Lifecycle', but here has type 'HookFunction'.

2680 declare var beforeEach: Mocha.HookFunction;
                 ~~~~~~~~~~

  node_modules/@types/jest/index.d.ts:34:13
    34 declare var beforeEach: jest.Lifecycle;
                   ~~~~~~~~~~
    'beforeEach' was also declared here.

node_modules/@types/mocha/index.d.ts:2698:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'afterEach' must be of type 'Lifecycle', but here has type 'HookFunction'.

2698 declare var afterEach: Mocha.HookFunction;
                 ~~~~~~~~~

  node_modules/@types/jest/index.d.ts:36:13
    36 declare var afterEach: jest.Lifecycle;
                   ~~~~~~~~~
    'afterEach' was also declared here.

node_modules/@types/mocha/index.d.ts:2714:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'describe' must be of type 'Describe', but here has type 'SuiteFunction'.

2714 declare var describe: Mocha.SuiteFunction;

Provide test source code if related

branch using 2.3.6
https://github.com/diversemix/bootstrap-typescript-starter/tree/codeceptjs-2.3.6-upgrade

branch using 2.3.5
https://github.com/diversemix/bootstrap-typescript-starter/tree/master

run:
yarn
yarn build

Details

  • CodeceptJS version: 2.3.6
  • NodeJS Version: v10.15.3
  • Operating System: OSX10.15.1
  • Configuration file:
exports.config = {
  tests: './tests/*.js',
  output: './output',
  helpers: {
    Puppeteer: {
      url: 'http://localhost:8080',
      show: true
    }
  },
  include: {
    I: './steps_file.js'
  },
  bootstrap: null,
  mocha: {},
  name: 'bootstrap-typescript-starter'
}
bug typescript

Most helpful comment

There is not even about different package.json. @types/... should not be in dependencies section, it's used only to builing package, not in runtime
So, it's definitely a bug

All 8 comments

You can add skipLibCheck for your tsconfig.json and it solved problem)

As possible solution - create inside folder with e2e tests one more tsconfig file, where modules will be listed, which used in e2e tests only

You can add skipLibCheck for your tsconfig.json and it solved problem)

While this will let me build with version 2.3.6, its a bit to heavy handed of a work around which I wouldn't want to have in my master branch, for now I've just left the project at 2.3.5.

As possible solution - create inside folder with e2e tests one more tsconfig file, where modules will be listed, which used in e2e tests only

Thanks for the suggestion, I suppose having a sub-package.json in my /tests directory would prevent my build from being affected by the codeceptjs type dependencies.

I'm new to codeceptJS so not 100% familiar with the whole API, does the inclusion of @types/mocha mean that it's exposing the whole unwrapped mocha library? If not is there was any way that the type defs could be namespaced out 馃

I would use a different package.json for e2e tests. Mocha and jest both testing frameworks and their globals may intersect

I'll close this as the consensus is to have a separate package.json for e2e tests. I did find https://medium.com/@elenasufieva/handling-type-declarations-clash-in-typescript-b05b10723f47 a useful read and possible solution to the problem of needing both jest and mocha with types in one project. I haven't implemented myself for though.

I open this issue because if the tests are in different folders (next to the component as an example) the package.json won't help.

There is not even about different package.json. @types/... should not be in dependencies section, it's used only to builing package, not in runtime
So, it's definitely a bug

@oceandrama I will fix this issue !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vitaly87 picture vitaly87  路  11Comments

zordius picture zordius  路  10Comments

TestdeTester picture TestdeTester  路  10Comments

ebuster picture ebuster  路  16Comments

waryhermit picture waryhermit  路  12Comments