Cypress 3.2.0 exports mocha/chai globally
See original GitHub issueCurrent behavior:
I can’t exactly pinpoint the cause of this, but I think after this change:
All third party @types have been moved from Cypress dependencies into devDependencies.
This should fix situations where user's type dependencies were conflicting with Cypress's third
party type definitions. Fixes #3371 and #1227.
Pull request was 3425
We are having duplicate conflicts between Cypress and our packages. In our case, we use Typescript with Mocha and Chai to write type-safe unit tests, and because they are exported globally by Mocha and Chai itself we get duplicate exports between Cypress and Chai/Mocha. Our linter reports the following:
ERROR in C:/Development/alloy-vue/node_modules/@types/chai/index.d.ts
40:17 Duplicate identifier 'Operator'.
38 | }
39 |
> 40 | export type Operator = string; // "==" | "===" | ">" | ">=" | "<" | "<=" | "!=" | "!==";
| ^
41 |
42 | export type OperatorComparable = boolean | null | number | string | undefined | Date;
43 |
Version: typescript 3.3.4000, tslint 5.14.0
ERROR in C:/Development/alloy-vue/node_modules/@types/chai/index.d.ts
42:17 Duplicate identifier 'OperatorComparable'.
40 | export type Operator = string; // "==" | "===" | ">" | ">=" | "<" | "<=" | "!=" | "!==";
41 |
> 42 | export type OperatorComparable = boolean | null | number | string | undefined | Date;
| ^
43 |
44 | interface ShouldAssertion {
45 | equal(value1: any, value2: any, message?: string): void;
ERROR in C:/Development/alloy-vue/node_modules/@types/chai/index.d.ts
1691:18 Duplicate identifier 'AssertionError'.
1689 | }
1690 |
> 1691 | export class AssertionError {
| ^
1692 | constructor(message: string, _props?: any, ssf?: Function);
1693 | name: string;
1694 | message: string;
ERROR in C:/Development/alloy-vue/node_modules/@types/chai/index.d.ts
1700:15 Cannot redeclare block-scoped variable 'chai'.
1698 | }
1699 |
> 1700 | declare const chai: Chai.ChaiStatic;
| ^
1701 |
1702 | declare module "chai" {
1703 | export = chai;
ERROR in C:/Development/alloy-vue/node_modules/@types/chai/index.d.ts
1703:14 Cannot redeclare block-scoped variable 'chai'.
1701 |
1702 | declare module "chai" {
> 1703 | export = chai;
| ^
1704 | }
1705 |
1706 | interface Object {
ERROR in C:/Development/alloy-vue/node_modules/@types/mocha/index.d.ts
17:1 Definitions of the following identifiers conflict with those in another file: setup, teardown, suiteSetup, suiteTeardown, before, after, beforeEach, afterEach, mocha, MochaDone, ReporterConstructor, Mocha
15 | * @see https://mochajs.org/api/mocha
16 | */
> 17 | declare class Mocha {
| ^
18 | private _growl;
19 | private _reporter;
20 | private _ui;
ERROR in C:/Development/alloy-vue/node_modules/@types/mocha/index.d.ts
2837:11 Interface 'MochaSetupOptions' incorrectly extends interface 'MochaOptions'.
Types of property 'ui' are incompatible.
Type 'string | undefined' is not assignable to type '"bdd" | "tdd" | "qunit" | "exports" | undefined'.
Type 'string' is not assignable to type '"bdd" | "tdd" | "qunit" | "exports" | undefined'.
2835 | * Options to pass to `mocha.setup` in the browser.
2836 | */
> 2837 | interface MochaSetupOptions extends Mocha.MochaOptions {
| ^
2838 | /** @deprecated This is not used by Mocha. Use `files` instead. */
2839 | require?: string[];
2840 | fullTrace?: boolean;
ERROR in C:/Development/alloy-vue/node_modules/cypress/types/chai/index.d.ts
40:17 Duplicate identifier 'Operator'.
38 | }
39 |
> 40 | export type Operator = string; // "==" | "===" | ">" | ">=" | "<" | "<=" | "!=" | "!==";
| ^
41 |
42 | export type OperatorComparable = boolean | null | number | string | undefined | Date;
43 |
ERROR in C:/Development/alloy-vue/node_modules/cypress/types/chai/index.d.ts
42:17 Duplicate identifier 'OperatorComparable'.
40 | export type Operator = string; // "==" | "===" | ">" | ">=" | "<" | "<=" | "!=" | "!==";
41 |
> 42 | export type OperatorComparable = boolean | null | number | string | undefined | Date;
| ^
43 |
44 | interface ShouldAssertion {
45 | equal(value1: any, value2: any, message?: string): void;
ERROR in C:/Development/alloy-vue/node_modules/cypress/types/chai/index.d.ts
1607:18 Duplicate identifier 'AssertionError'.
1605 | }
1606 |
> 1607 | export class AssertionError {
| ^
1608 | constructor(message: string, _props?: any, ssf?: Function);
1609 | name: string;
1610 | message: string;
ERROR in C:/Development/alloy-vue/node_modules/cypress/types/chai/index.d.ts
1616:15 Cannot redeclare block-scoped variable 'chai'.
1614 | }
1615 |
> 1616 | declare const chai: Chai.ChaiStatic;
| ^
1617 |
1618 | declare module "chai" {
1619 | export = chai;
ERROR in C:/Development/alloy-vue/node_modules/cypress/types/chai/index.d.ts
1619:14 Cannot redeclare block-scoped variable 'chai'.
1617 |
1618 | declare module "chai" {
> 1619 | export = chai;
| ^
1620 | }
1621 |
1622 | interface Object {
ERROR in C:/Development/alloy-vue/node_modules/cypress/types/mocha/index.d.ts
6:1 Definitions of the following identifiers conflict with those in another file: setup, teardown, suiteSetup, suiteTeardown, before, after, beforeEach, afterEach, mocha, MochaDone, ReporterConstructor, Mocha
4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5 |
> 6 | interface MochaSetupOptions {
| ^
7 | //milliseconds to wait before considering a test slow
8 | slow?: number;
9 |
ERROR in C:/Development/alloy-vue/node_modules/cypress/types/mocha/index.d.ts
36:13 Subsequent variable declarations must have the same type. Variable 'describe' must be of type 'SuiteFunction', but here has type 'IContextDefinition'.
34 |
35 | declare var mocha: Mocha;
> 36 | declare var describe: Mocha.IContextDefinition;
| ^
37 | declare var xdescribe: Mocha.IContextDefinition;
38 | // alias for `describe`
39 | declare var context: Mocha.IContextDefinition;
ERROR in C:/Development/alloy-vue/node_modules/cypress/types/mocha/index.d.ts
37:13 Subsequent variable declarations must have the same type. Variable 'xdescribe' must be of type 'PendingSuiteFunction', but here has type 'IContextDefinition'.
35 | declare var mocha: Mocha;
36 | declare var describe: Mocha.IContextDefinition;
> 37 | declare var xdescribe: Mocha.IContextDefinition;
| ^
38 | // alias for `describe`
39 | declare var context: Mocha.IContextDefinition;
40 | // alias for `describe`
ERROR in C:/Development/alloy-vue/node_modules/cypress/types/mocha/index.d.ts
39:13 Subsequent variable declarations must have the same type. Variable 'context' must be of type 'SuiteFunction', but here has type 'IContextDefinition'.
37 | declare var xdescribe: Mocha.IContextDefinition;
38 | // alias for `describe`
> 39 | declare var context: Mocha.IContextDefinition;
| ^
40 | // alias for `describe`
41 | declare var suite: Mocha.IContextDefinition;
42 | declare var it: Mocha.ITestDefinition;
ERROR in C:/Development/alloy-vue/node_modules/cypress/types/mocha/index.d.ts
41:13 Subsequent variable declarations must have the same type. Variable 'suite' must be of type 'SuiteFunction', but here has type 'IContextDefinition'.
39 | declare var context: Mocha.IContextDefinition;
40 | // alias for `describe`
> 41 | declare var suite: Mocha.IContextDefinition;
| ^
42 | declare var it: Mocha.ITestDefinition;
43 | declare var xit: Mocha.ITestDefinition;
44 | // alias for `it`
ERROR in C:/Development/alloy-vue/node_modules/cypress/types/mocha/index.d.ts
42:13 Subsequent variable declarations must have the same type. Variable 'it' must be of type 'TestFunction', but here has type 'ITestDefinition'.
40 | // alias for `describe`
41 | declare var suite: Mocha.IContextDefinition;
> 42 | declare var it: Mocha.ITestDefinition;
| ^
43 | declare var xit: Mocha.ITestDefinition;
44 | // alias for `it`
45 | declare var test: Mocha.ITestDefinition;
ERROR in C:/Development/alloy-vue/node_modules/cypress/types/mocha/index.d.ts
43:13 Subsequent variable declarations must have the same type. Variable 'xit' must be of type 'PendingTestFunction', but here has type 'ITestDefinition'.
41 | declare var suite: Mocha.IContextDefinition;
42 | declare var it: Mocha.ITestDefinition;
> 43 | declare var xit: Mocha.ITestDefinition;
| ^
44 | // alias for `it`
45 | declare var test: Mocha.ITestDefinition;
46 | declare var specify: Mocha.ITestDefinition;
ERROR in C:/Development/alloy-vue/node_modules/cypress/types/mocha/index.d.ts
45:13 Subsequent variable declarations must have the same type. Variable 'test' must be of type 'TestFunction', but here has type 'ITestDefinition'.
43 | declare var xit: Mocha.ITestDefinition;
44 | // alias for `it`
> 45 | declare var test: Mocha.ITestDefinition;
| ^
46 | declare var specify: Mocha.ITestDefinition;
47 |
48 | // Used with the --delay flag; see https://mochajs.org/#hooks
ERROR in C:/Development/alloy-vue/node_modules/cypress/types/mocha/index.d.ts
46:13 Subsequent variable declarations must have the same type. Variable 'specify' must be of type 'TestFunction', but here has type 'ITestDefinition'.
44 | // alias for `it`
45 | declare var test: Mocha.ITestDefinition;
> 46 | declare var specify: Mocha.ITestDefinition;
| ^
47 |
48 | // Used with the --delay flag; see https://mochajs.org/#hooks
49 | declare function run(): void;
So we can see that, for example Chai is exporting type definitions globally, but so is Cypress so they conflict with each other.
This is fixed on our side if we rollback to Cypress to 3.1.5 or if we remove Chai from our npm packages.
Desired behavior:
I don’t think Cypress should be exporting the packages globally, or at least keep it self contained within it’s own package.
Steps to reproduce: (app code and test code)
To exactly reproduce our case:
- Create a clean vue typescript project with vue-cli (https://vuejs.org/v2/guide/installation.html)
- Make sure to install Mocha, Chai and Cypress as part of it, all latest versions
- Setup TSLint if you want to get the same errors as above
- Run the vue-cli
serve
, wait for the linter to finish, notice the errors
Versions
Cypress version: 3.2.0 Operating system: Windows 10 Browser: Chrome Version 73.0.3683.86 (Official Build) (64-bit)
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
I created a new issue in our docs to document the global exports here: https://github.com/cypress-io/cypress-documentation/issues/1524. Our documentation is open source and contributions are welcome. 😄
Didn’t see this until now, but you can circumvent this by using Cypress types for example:
So you won’t have to import Chai.