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.
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
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'
}
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 !
Most helpful comment
There is not even about different
package.json.@types/...should not be independenciessection, it's used only to builing package, not in runtimeSo, it's definitely a bug