diff --git a/packages/instrumenter/package.json b/packages/instrumenter/package.json index aab95800b6..9308bbe55d 100644 --- a/packages/instrumenter/package.json +++ b/packages/instrumenter/package.json @@ -42,7 +42,7 @@ "devDependencies": { "@babel/preset-react": "~7.10.4", "@stryker-mutator/test-helpers": "4.0.0-beta.4", - "@types/babel__core": "~7.1.7", + "@types/babel__core": "~7.1.9", "@types/babel__generator": "~7.6.1", "@types/babel__parser": "~7.1.1", "@types/chai-jest-snapshot": "~1.3.5", diff --git a/packages/instrumenter/src/mutant-placers/conditional-expression-mutant-placer.ts b/packages/instrumenter/src/mutant-placers/conditional-expression-mutant-placer.ts index d9109b464e..bf2ff674ed 100644 --- a/packages/instrumenter/src/mutant-placers/conditional-expression-mutant-placer.ts +++ b/packages/instrumenter/src/mutant-placers/conditional-expression-mutant-placer.ts @@ -12,7 +12,7 @@ function nameAnonymousClassOrFunctionExpression(path: NodePath } else if ( path.parentPath.isObjectProperty() && types.isIdentifier(path.parentPath.node.key) && - path.getStatementParent().isVariableDeclaration() + path.getStatementParent()?.isVariableDeclaration() ) { path.node.id = path.parentPath.node.key; } diff --git a/packages/instrumenter/test/unit/parsers/js-parser.spec.ts b/packages/instrumenter/test/unit/parsers/js-parser.spec.ts index fd123e63f5..f2391f4632 100644 --- a/packages/instrumenter/test/unit/parsers/js-parser.spec.ts +++ b/packages/instrumenter/test/unit/parsers/js-parser.spec.ts @@ -23,10 +23,8 @@ describe('js-parser', () => { describe('with features', () => { const itShouldSupportAst = createActArrangeAndAssertHelper((name) => `https://babeljs.io/docs/en/babel-plugin-syntax-${name}`); itShouldSupportAst('async-generators', 'async function* agf() { await 1;}', (t) => t.isFunctionDeclaration() && t.node.generator); - // @ts-expect-error isImport is not (yet) defined in the types itShouldSupportAst('dynamic-import', 'import("fs").then(console.log)', (t) => t.isImport()); itShouldSupportAst('import-meta', 'console.log(import.meta);', (t) => t.isMetaProperty()); - // @ts-expect-error is not (yet) defined in the types itShouldSupportAst('big-int', 'const theBiggestInt = 9007199254740991n', (t) => t.isBigIntLiteral()); itShouldSupportAst('logical-assignment-operators', 'a &&= b;', (t) => t.isAssignmentExpression() && t.node.operator === '&&='); }); @@ -38,9 +36,7 @@ describe('js-parser', () => { itShouldSupportAst('do-expressions', 'let a = do { if(x > 10) { "big"; } else { "small"; } }', (t) => t.isDoExpression()); itShouldSupportAst('object-rest-spread', 'let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };', (t) => t.isRestElement()); itShouldSupportAst('class-properties', 'class Foo { bar = "baz" }', (t) => t.isClassProperty()); - // @ts-expect-error not (yet) defined in the types itShouldSupportAst('class-properties (private properties)', 'class Foo { #bar = "baz" }', (t) => t.isClassPrivateProperty()); - // @ts-expect-error not (yet) defined in the types itShouldSupportAst('class-properties (private methods)', 'class Foo { #bar(){ return "baz"; } }', (t) => t.isClassPrivateMethod()); itShouldSupportAst('export-default-from', 'export v from "mod";', (t) => t.isExportNamedDeclaration()); @@ -51,7 +47,6 @@ describe('js-parser', () => { ); itShouldSupportAst('numeric-separator', 'let budget = 1_000_000_000_000;', (t) => t.isNumericLiteral()); itShouldSupportAst('optional-catch-binding', 'try{ throw 0; } catch { }', (t) => t.isCatchClause() && t.node.param === null); - // @ts-expect-error isOptionalMemberExpression is not (yet) defined in the types itShouldSupportAst('optional-chaining', 'const baz = obj?.foo?.bar?.baz;', (t) => t.isOptionalMemberExpression()); itShouldSupportAst('pipeline-operator', 'let result = "hello" |> doubleSay |> capitalize |> exclaim;', (t) => t.isBinaryExpression()); itShouldSupportAst( diff --git a/packages/instrumenter/test/unit/parsers/ts-parser.spec.ts b/packages/instrumenter/test/unit/parsers/ts-parser.spec.ts index c5c6e2ee3f..35b4406c5f 100644 --- a/packages/instrumenter/test/unit/parsers/ts-parser.spec.ts +++ b/packages/instrumenter/test/unit/parsers/ts-parser.spec.ts @@ -15,7 +15,6 @@ describe('ts-parser', () => { expect(format).eq(expected.format); expect(rawContent).eq(expected.rawContent); expect(originFileName).eq(expected.originFileName); - // @ts-expect-error is not added to type definitions yet expectAst(root, (p) => p.isTSTypeAnnotation()); }); diff --git a/packages/instrumenter/test/unit/transformers/babel-transformer.spec.ts b/packages/instrumenter/test/unit/transformers/babel-transformer.spec.ts index 5cf657ff4f..d96dca308b 100644 --- a/packages/instrumenter/test/unit/transformers/babel-transformer.spec.ts +++ b/packages/instrumenter/test/unit/transformers/babel-transformer.spec.ts @@ -81,7 +81,6 @@ describe('babel-transformer', () => { it('should skip type annotations', () => { const ast = createTSAst({ rawContent: 'const foo: string;' }); transformBabel(ast, mutantCollectorMock, context); - // @ts-expect-error expectMutateNotCalledWith((t) => t.isTSTypeAnnotation()); }); diff --git a/packages/mocha-runner/schema/mocha-runner-options.json b/packages/mocha-runner/schema/mocha-runner-options.json index 48fb90ac67..d0d749b5d6 100644 --- a/packages/mocha-runner/schema/mocha-runner-options.json +++ b/packages/mocha-runner/schema/mocha-runner-options.json @@ -56,10 +56,6 @@ "type": "boolean", "description": "Explicit turn off [mocha config file](https://mochajs.org/#-config-path)" }, - "timeout": { - "description": "Set mocha's [`timeout` option](https://mochajs.org/#-t---timeout-ms)", - "type": "number" - }, "async-only": { "description": "Set mocha's [`async-only` option](https://mochajs.org/#-async-only-a)", "type": "boolean" diff --git a/packages/mocha-runner/src/MochaOptionsLoader.ts b/packages/mocha-runner/src/MochaOptionsLoader.ts index 6ea0165aa2..9360cde69b 100644 --- a/packages/mocha-runner/src/MochaOptionsLoader.ts +++ b/packages/mocha-runner/src/MochaOptionsLoader.ts @@ -22,7 +22,6 @@ export const DEFAULT_MOCHA_OPTIONS: Readonly = Object.freeze({ ignore: [], opts: './test/mocha.opts', spec: ['test'], - timeout: 2000, ui: 'bdd', 'no-package': false, 'no-opts': false, @@ -34,7 +33,7 @@ export default class MochaOptionsLoader { public static inject = tokens(commonTokens.logger); constructor(private readonly log: Logger) {} - public load(strykerOptions: MochaRunnerWithStrykerOptions): MochaOptions { + public load(strykerOptions: MochaRunnerWithStrykerOptions) { const mochaOptions = { ...strykerOptions.mochaOptions } as MochaOptions; return { ...DEFAULT_MOCHA_OPTIONS, ...this.loadMochaOptions(mochaOptions), ...mochaOptions }; } @@ -111,10 +110,6 @@ export default class MochaOptionsLoader { } mochaRunnerOptions.require.push(...args); break; - case '--timeout': - case '-t': - mochaRunnerOptions.timeout = this.parseNextInt(args, DEFAULT_MOCHA_OPTIONS.timeout!); - break; case '--async-only': case '-A': mochaRunnerOptions['async-only'] = true; @@ -140,14 +135,6 @@ export default class MochaOptionsLoader { return mochaRunnerOptions; } - private parseNextInt(args: string[], otherwise: number): number { - if (args.length > 1) { - return parseInt(args[1], 10); - } else { - return otherwise; - } - } - private parseNextString(args: string[]): string | undefined { if (args.length > 1) { return args[1]; diff --git a/packages/mocha-runner/src/MochaTestRunner.ts b/packages/mocha-runner/src/MochaTestRunner.ts index 609d004a0b..39fd0768a6 100644 --- a/packages/mocha-runner/src/MochaTestRunner.ts +++ b/packages/mocha-runner/src/MochaTestRunner.ts @@ -88,6 +88,7 @@ export class MochaTestRunner implements TestRunner2 { const mocha = this.mochaAdapter.create({ reporter: StrykerMochaReporter as any, bail: true, + timeout: false as any, // Mocha 5 doesn't support `0` rootHooks: this.rootHooks, } as Mocha.MochaOptions); this.configure(mocha); @@ -145,7 +146,6 @@ export class MochaTestRunner implements TestRunner2 { } setIfDefined(options['async-only'], (asyncOnly) => asyncOnly && mocha.asyncOnly()); - setIfDefined(options.timeout, mocha.timeout); setIfDefined(options.ui, mocha.ui); setIfDefined(options.grep, mocha.grep); } diff --git a/packages/mocha-runner/test/helpers/factories.ts b/packages/mocha-runner/test/helpers/factories.ts index 7f3c8e3097..05b6ca555f 100644 --- a/packages/mocha-runner/test/helpers/factories.ts +++ b/packages/mocha-runner/test/helpers/factories.ts @@ -1,6 +1,6 @@ import { MochaOptions } from '../../src-generated/mocha-runner-options'; import { DEFAULT_MOCHA_OPTIONS } from '../../src/MochaOptionsLoader'; -export function createMochaOptions(overrides: Partial): MochaOptions { +export function createMochaOptions(overrides?: Partial): MochaOptions { return { ...DEFAULT_MOCHA_OPTIONS, ...overrides }; } diff --git a/packages/mocha-runner/test/integration/MochaFileResolving.spec.ts b/packages/mocha-runner/test/integration/MochaFileResolving.it.spec.ts similarity index 100% rename from packages/mocha-runner/test/integration/MochaFileResolving.spec.ts rename to packages/mocha-runner/test/integration/MochaFileResolving.it.spec.ts diff --git a/packages/mocha-runner/test/integration/MochaOptionsLoader.it.spec.ts b/packages/mocha-runner/test/integration/MochaOptionsLoader.it.spec.ts index 8f9a9d00ea..6b62072d7f 100644 --- a/packages/mocha-runner/test/integration/MochaOptionsLoader.it.spec.ts +++ b/packages/mocha-runner/test/integration/MochaOptionsLoader.it.spec.ts @@ -28,7 +28,6 @@ describe(`${MochaOptionsLoader.name} integration`, () => { opts: './test/mocha.opts', package: false, // mocha sets package: false after loading it... extension: ['js'], - timeout: 2000, ui: 'bdd', }); }); @@ -42,7 +41,6 @@ describe(`${MochaOptionsLoader.name} integration`, () => { package: false, // mocha sets package: false after loading it... config: configFile, extension: ['json', 'js'], - timeout: 2000, ui: 'bdd', }); }); @@ -56,7 +54,6 @@ describe(`${MochaOptionsLoader.name} integration`, () => { opts: './test/mocha.opts', package: false, // mocha sets package: false after loading it... extension: ['jsonc', 'js'], - timeout: 2000, ui: 'bdd', }); }); @@ -75,7 +72,6 @@ describe(`${MochaOptionsLoader.name} integration`, () => { ignore: ['/path/to/some/excluded/file'], require: ['@babel/register'], spec: ['test/**/*.spec.js'], - timeout: false, ui: 'bdd', }); }); @@ -86,7 +82,6 @@ describe(`${MochaOptionsLoader.name} integration`, () => { expect(actualConfig).deep.include({ ['async-only']: true, extension: ['json'], - timeout: 20, ui: 'tdd', }); }); @@ -97,7 +92,6 @@ describe(`${MochaOptionsLoader.name} integration`, () => { expect(actualConfig).deep.include({ ['async-only']: true, extension: ['js', 'json'], - timeout: 2000, ui: 'bdd', }); }); @@ -109,12 +103,11 @@ describe(`${MochaOptionsLoader.name} integration`, () => { 'no-package': true, 'no-opts': true, }); - const expectedOptions = { + const expectedOptions: MochaOptions = { extension: ['js', 'cjs', 'mjs'], ['no-config']: true, ['no-opts']: true, ['no-package']: true, - timeout: 2000, ui: 'bdd', }; expect(actualConfig).deep.include(expectedOptions); diff --git a/packages/mocha-runner/test/unit/MochaOptionsLoader.spec.ts b/packages/mocha-runner/test/unit/MochaOptionsLoader.spec.ts index 3687f67e0b..d833d61143 100644 --- a/packages/mocha-runner/test/unit/MochaOptionsLoader.spec.ts +++ b/packages/mocha-runner/test/unit/MochaOptionsLoader.spec.ts @@ -66,7 +66,6 @@ describe(MochaOptionsLoader.name, () => { // Following are valid options rawOptions.extension = ['foo']; rawOptions.require = ['bar']; - rawOptions.timeout = 4200; rawOptions['async-only'] = true; rawOptions.ui = 'qunit'; rawOptions.grep = 'quuz'; @@ -76,7 +75,7 @@ describe(MochaOptionsLoader.name, () => { rawOptions.garply = 'waldo'; // this should be filtered out const result = sut.load(options); - const expected: MochaOptions = createMochaOptions({ + const expected = createMochaOptions({ extension: ['foo'], file: ['grault'], grep: 'quuz', @@ -84,11 +83,10 @@ describe(MochaOptionsLoader.name, () => { opts: './test/mocha.opts', require: ['bar'], spec: ['test/**/*.js'], - timeout: 4200, 'async-only': true, ui: 'qunit', }); - expect(result).deep.eq({ ...expected }); + expect(result).deep.contains(expected); }); it('should trace log the mocha call', () => { @@ -104,7 +102,7 @@ describe(MochaOptionsLoader.name, () => { it("should respect mocha's defaults", () => { const actualOptions = sut.load(options); - expect(actualOptions).deep.eq(createMochaOptions()); + expect(actualOptions).deep.contains(createMochaOptions()); }); it('should not allow to set parallel', () => { @@ -177,7 +175,7 @@ describe(MochaOptionsLoader.name, () => { it('should not load default mocha.opts file if not found', () => { existsFileStub.returns(false); const mochaOptions = sut.load(options); - expect(mochaOptions).deep.eq(createMochaOptions()); + expect(mochaOptions).deep.contains(createMochaOptions()); expect(testInjector.logger.debug).calledWith( 'No mocha opts file found, not loading additional mocha options (%s was not defined).', 'mochaOptions.opts' @@ -204,8 +202,6 @@ describe(MochaOptionsLoader.name, () => { }); } - itShouldLoadProperty('--timeout', '2000', { timeout: 2000 }); - itShouldLoadProperty('-t', '2000', { timeout: 2000 }); itShouldLoadProperty('-A', '', { 'async-only': true }); itShouldLoadProperty('--async-only', '', { 'async-only': true }); itShouldLoadProperty('--ui', 'qunit', { ui: 'qunit' }); @@ -225,18 +221,16 @@ describe(MochaOptionsLoader.name, () => { 'async-only': false, opts: 'path/to/opts/file', require: ['ts-node/register'], - timeout: 4000, ui: 'exports', }; const mochaOptions = sut.load(options); - expect(mochaOptions).deep.equal( + expect(mochaOptions).deep.contains( createMochaOptions({ 'async-only': false, extension: ['js'], opts: 'path/to/opts/file', require: ['ts-node/register'], spec: ['test'], - timeout: 4000, ui: 'exports', }) ); @@ -266,12 +260,11 @@ describe(MochaOptionsLoader.name, () => { opts: 'some/mocha.opts/file', }; const mochaOptions = sut.load(options); - expect(mochaOptions).deep.eq( + expect(mochaOptions).deep.contain( createMochaOptions({ extension: ['js'], opts: 'some/mocha.opts/file', spec: ['test'], - timeout: 2000, ui: 'bdd', }) ); @@ -290,7 +283,6 @@ describe(MochaOptionsLoader.name, () => { ignore: [], opts: './test/mocha.opts', spec: ['test'], - timeout: 2000, ui: 'bdd', ...overrides, }; diff --git a/packages/mocha-runner/test/unit/MochaTestRunner.spec.ts b/packages/mocha-runner/test/unit/MochaTestRunner.spec.ts index f8301a38b9..14f4e9bca9 100644 --- a/packages/mocha-runner/test/unit/MochaTestRunner.spec.ts +++ b/packages/mocha-runner/test/unit/MochaTestRunner.spec.ts @@ -66,7 +66,7 @@ describe(MochaTestRunner.name, () => { it('should collect the files', async () => { const expectedTestFileNames = ['foo.js', 'foo.spec.js']; - const mochaOptions = Object.freeze(createMochaOptions({ timeout: 23 })); + const mochaOptions = Object.freeze(createMochaOptions()); mochaOptionsLoaderMock.load.returns(mochaOptions); mochaAdapterMock.collectFiles.returns(expectedTestFileNames); @@ -121,7 +121,6 @@ describe(MochaTestRunner.name, () => { sut.mochaOptions.grep = 'grepme'; sut.mochaOptions.opts = 'opts'; sut.mochaOptions.require = []; - sut.mochaOptions.timeout = 2000; sut.mochaOptions.ui = 'exports'; // Act @@ -129,11 +128,20 @@ describe(MochaTestRunner.name, () => { // Assert expect(mocha.asyncOnly).called; - expect(mocha.timeout).calledWith(2000); expect(mocha.ui).calledWith('exports'); expect(mocha.grep).calledWith('grepme'); }); + it('should force timeout off', async () => { + await actDryRun(); + expect(mochaAdapterMock.create).calledWithMatch({ timeout: false }); + }); + + it('should force bail', async () => { + await actDryRun(); + expect(mochaAdapterMock.create).calledWithMatch({ bail: true }); + }); + it("should don't set asyncOnly if asyncOnly is false", async () => { sut.mochaOptions['async-only'] = false; await actDryRun();