From 86cef39994a0cc975d0081168b84e486b1a2cc98 Mon Sep 17 00:00:00 2001 From: Nico Jansen Date: Wed, 2 Sep 2020 22:09:50 +0200 Subject: [PATCH 1/2] feat(mutate): a more sane default for `mutate` --- e2e/test/jasmine-ts-node/stryker.conf.json | 3 -- .../jest-react-enyme-ts/stryker.conf.json | 4 -- e2e/test/mocha-ts-node/stryker.conf.json | 3 -- .../typescript-transpiling/stryker.conf.json | 3 -- .../vue-cli-javascript-jest/stryker.conf.json | 4 -- .../stryker.conf.json | 4 -- e2e/test/vue-javascript/stryker.conf.json | 3 -- packages/api/schema/stryker-core.json | 7 ++- packages/core/test/helpers/setupMocha.ts | 3 -- .../input/InputFileResolver.it.spec.ts | 47 +++++++++++++++++++ .../input-files/lib/string-utils.js | 0 .../testResources/input-files/src/.mocharc.js | 0 .../input-files/src/__tests__/app.js | 0 .../core/testResources/input-files/src/app.ts | 0 .../calculator/calculator.component.spec.tsx | 0 .../calculator/calculator.component.test.tsx | 0 .../calculator/calculator.component.tsx | 0 .../heading/heading.component.spec.vue | 0 .../components/heading/heading.component.vue | 0 .../testResources/input-files/src/index.html | 0 .../input-files/src/karma.conf.js | 0 .../input-files/src/services/storage.Spec.tsx | 0 .../input-files/src/services/storage.Test.tsx | 0 .../input-files/src/services/storage.ts | 0 .../input-files/src/services/test.ts | 0 .../testResources/input-files/src/test.ts | 0 .../src/utils/__tests__/commonjs.cjs | 0 .../input-files/src/utils/commonjs.cjs | 0 .../input-files/src/utils/esm.mjs | 0 .../input-files/src/utils/esm.spec.mjs | 0 .../testResources/input-files/test/setup.js | 0 31 files changed, 50 insertions(+), 31 deletions(-) create mode 100644 packages/core/test/integration/input/InputFileResolver.it.spec.ts create mode 100644 packages/core/testResources/input-files/lib/string-utils.js create mode 100644 packages/core/testResources/input-files/src/.mocharc.js create mode 100644 packages/core/testResources/input-files/src/__tests__/app.js create mode 100644 packages/core/testResources/input-files/src/app.ts create mode 100644 packages/core/testResources/input-files/src/components/calculator/calculator.component.spec.tsx create mode 100644 packages/core/testResources/input-files/src/components/calculator/calculator.component.test.tsx create mode 100644 packages/core/testResources/input-files/src/components/calculator/calculator.component.tsx create mode 100644 packages/core/testResources/input-files/src/components/heading/heading.component.spec.vue create mode 100644 packages/core/testResources/input-files/src/components/heading/heading.component.vue create mode 100644 packages/core/testResources/input-files/src/index.html create mode 100644 packages/core/testResources/input-files/src/karma.conf.js create mode 100644 packages/core/testResources/input-files/src/services/storage.Spec.tsx create mode 100644 packages/core/testResources/input-files/src/services/storage.Test.tsx create mode 100644 packages/core/testResources/input-files/src/services/storage.ts create mode 100644 packages/core/testResources/input-files/src/services/test.ts create mode 100644 packages/core/testResources/input-files/src/test.ts create mode 100644 packages/core/testResources/input-files/src/utils/__tests__/commonjs.cjs create mode 100644 packages/core/testResources/input-files/src/utils/commonjs.cjs create mode 100644 packages/core/testResources/input-files/src/utils/esm.mjs create mode 100644 packages/core/testResources/input-files/src/utils/esm.spec.mjs create mode 100644 packages/core/testResources/input-files/test/setup.js diff --git a/e2e/test/jasmine-ts-node/stryker.conf.json b/e2e/test/jasmine-ts-node/stryker.conf.json index 7732725892..23f02156f9 100644 --- a/e2e/test/jasmine-ts-node/stryker.conf.json +++ b/e2e/test/jasmine-ts-node/stryker.conf.json @@ -1,8 +1,5 @@ { "$schema": "../../node_modules/@stryker-mutator/core/schema/stryker-schema.json", - "mutate": [ - "{src,lib}/**/*.ts?(x)" - ], "checkers": [ "typescript" ], diff --git a/e2e/test/jest-react-enyme-ts/stryker.conf.json b/e2e/test/jest-react-enyme-ts/stryker.conf.json index 64c1de1e17..1ba1dc735e 100644 --- a/e2e/test/jest-react-enyme-ts/stryker.conf.json +++ b/e2e/test/jest-react-enyme-ts/stryker.conf.json @@ -3,10 +3,6 @@ "packageManager": "npm", "testRunner": "jest", "tempDirName": "stryker-tmp", - "mutate": [ - "src/*.tsx", - "!src/*.spec.tsx" - ], "concurrency": 2, "coverageAnalysis": "off", "reporters": [ diff --git a/e2e/test/mocha-ts-node/stryker.conf.json b/e2e/test/mocha-ts-node/stryker.conf.json index df4521ae4f..1b0d58c7f8 100644 --- a/e2e/test/mocha-ts-node/stryker.conf.json +++ b/e2e/test/mocha-ts-node/stryker.conf.json @@ -1,8 +1,5 @@ { "$schema": "../../node_modules/@stryker-mutator/core/schema/stryker-schema.json", - "mutate": [ - "{src,lib}/**/*.ts?(x)" - ], "packageManager": "npm", "testRunner": "mocha", "concurrency": 1, diff --git a/e2e/test/typescript-transpiling/stryker.conf.json b/e2e/test/typescript-transpiling/stryker.conf.json index c3d042f7e2..4a462fb560 100644 --- a/e2e/test/typescript-transpiling/stryker.conf.json +++ b/e2e/test/typescript-transpiling/stryker.conf.json @@ -1,8 +1,5 @@ { "$schema": "../../node_modules/@stryker-mutator/core/schema/stryker-schema.json", - "mutate": [ - "src/*.ts" - ], "packageManager": "npm", "testRunner": "mocha", "concurrency": 1, diff --git a/e2e/test/vue-cli-javascript-jest/stryker.conf.json b/e2e/test/vue-cli-javascript-jest/stryker.conf.json index 93bcbf1e52..b01864568c 100644 --- a/e2e/test/vue-cli-javascript-jest/stryker.conf.json +++ b/e2e/test/vue-cli-javascript-jest/stryker.conf.json @@ -3,10 +3,6 @@ "mutator": { "plugins": [] }, - "mutate": [ - "{src,lib}/**/*.+(js|vue)", - "!{src,lib}/**/*.spec.js" - ], "tempDirName": "stryker-tmp", "packageManager": "npm", "testRunner": "jest", diff --git a/e2e/test/vue-cli-typescript-mocha/stryker.conf.json b/e2e/test/vue-cli-typescript-mocha/stryker.conf.json index 9499362b01..6e2c1d4c9e 100644 --- a/e2e/test/vue-cli-typescript-mocha/stryker.conf.json +++ b/e2e/test/vue-cli-typescript-mocha/stryker.conf.json @@ -1,9 +1,5 @@ { "$schema": "../../node_modules/@stryker-mutator/core/schema/stryker-schema.json", - "mutate": [ - "{src,lib}/**/*.+(ts|vue)", - "!{src,lib}/**/*.spec.ts" - ], "packageManager": "npm", "testRunner": "mocha", "concurrency": 2, diff --git a/e2e/test/vue-javascript/stryker.conf.json b/e2e/test/vue-javascript/stryker.conf.json index 6d14febc79..2128168691 100644 --- a/e2e/test/vue-javascript/stryker.conf.json +++ b/e2e/test/vue-javascript/stryker.conf.json @@ -1,8 +1,5 @@ { "$schema": "../../node_modules/@stryker-mutator/core/schema/stryker-schema.json", - "mutate": [ - "src/**/*.js", "src/**/*.vue" - ], "testRunner": "karma", "reporters": [ "clear-text", diff --git a/packages/api/schema/stryker-core.json b/packages/api/schema/stryker-core.json index 591e32a8c8..b86d88c340 100644 --- a/packages/api/schema/stryker-core.json +++ b/packages/api/schema/stryker-core.json @@ -294,10 +294,9 @@ "type": "string" }, "default": [ - "{src,lib}/**/*.js?(x)", - "!{src,lib}/**/__tests__/**/*.js?(x)", - "!{src,lib}/**/?(*.)+(spec|test).js?(x)", - "!{src,lib}/**/*+(Spec|Test).js?(x)" + "{src,lib}/**/!(*.+(s|S)pec|*.+(t|T)est).+(cjs|mjs|js|ts|jsx|tsx|html|vue)", + "!{src,lib}/**/__tests__/**/*.+(cjs|mjs|js|ts|jsx|tsx|html|vue)", + "!{src,lib}/+(karma.conf.js|.mocharc.js|test.ts)" ] }, "mutator": { diff --git a/packages/core/test/helpers/setupMocha.ts b/packages/core/test/helpers/setupMocha.ts index 38e4742f13..6d7611cbeb 100644 --- a/packages/core/test/helpers/setupMocha.ts +++ b/packages/core/test/helpers/setupMocha.ts @@ -9,9 +9,6 @@ chai.use(sinonChai); chai.use(chaiAsPromised); export const mochaHooks = { - before() { - console.log('BEFORE ALL!'); - }, afterEach() { sinon.restore(); testInjector.reset(); diff --git a/packages/core/test/integration/input/InputFileResolver.it.spec.ts b/packages/core/test/integration/input/InputFileResolver.it.spec.ts new file mode 100644 index 0000000000..6a73a37b54 --- /dev/null +++ b/packages/core/test/integration/input/InputFileResolver.it.spec.ts @@ -0,0 +1,47 @@ +import path = require('path'); + +import { factory, testInjector } from '@stryker-mutator/test-helpers'; +import { expect } from 'chai'; + +import { coreTokens } from '../../../src/di'; +import InputFileResolver from '../../../src/input/InputFileResolver'; + +const resolveTestResource: typeof path.resolve = path.resolve.bind( + path, + __dirname, + '..' /* input */, + '..' /* integration */, + '..' /* test */, + 'testResources', + 'input-files' +); + +describe(`${InputFileResolver.name} integration`, () => { + let sut: InputFileResolver; + let originalCwd: string; + + beforeEach(() => { + originalCwd = process.cwd(); + sut = testInjector.injector.provideValue(coreTokens.reporter, factory.reporter()).injectClass(InputFileResolver); + }); + + afterEach(() => { + process.chdir(originalCwd); + }); + + it.only('should by default resolve reasonable project source files to be mutated', async () => { + process.chdir(resolveTestResource()); + const inputFiles = await sut.resolve(); + expect(inputFiles.filesToMutate.map((file) => file.name)).deep.eq([ + resolveTestResource('lib', 'string-utils.js'), + resolveTestResource('src', 'app.ts'), + resolveTestResource('src', 'components', 'calculator', 'calculator.component.tsx'), + resolveTestResource('src', 'components', 'heading', 'heading.component.vue'), + resolveTestResource('src', 'index.html'), + resolveTestResource('src', 'services', 'storage.ts'), + resolveTestResource('src', 'services', 'test.ts'), + resolveTestResource('src', 'utils', 'commonjs.cjs'), + resolveTestResource('src', 'utils', 'esm.mjs'), + ]); + }); +}); diff --git a/packages/core/testResources/input-files/lib/string-utils.js b/packages/core/testResources/input-files/lib/string-utils.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/testResources/input-files/src/.mocharc.js b/packages/core/testResources/input-files/src/.mocharc.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/testResources/input-files/src/__tests__/app.js b/packages/core/testResources/input-files/src/__tests__/app.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/testResources/input-files/src/app.ts b/packages/core/testResources/input-files/src/app.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/testResources/input-files/src/components/calculator/calculator.component.spec.tsx b/packages/core/testResources/input-files/src/components/calculator/calculator.component.spec.tsx new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/testResources/input-files/src/components/calculator/calculator.component.test.tsx b/packages/core/testResources/input-files/src/components/calculator/calculator.component.test.tsx new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/testResources/input-files/src/components/calculator/calculator.component.tsx b/packages/core/testResources/input-files/src/components/calculator/calculator.component.tsx new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/testResources/input-files/src/components/heading/heading.component.spec.vue b/packages/core/testResources/input-files/src/components/heading/heading.component.spec.vue new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/testResources/input-files/src/components/heading/heading.component.vue b/packages/core/testResources/input-files/src/components/heading/heading.component.vue new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/testResources/input-files/src/index.html b/packages/core/testResources/input-files/src/index.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/testResources/input-files/src/karma.conf.js b/packages/core/testResources/input-files/src/karma.conf.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/testResources/input-files/src/services/storage.Spec.tsx b/packages/core/testResources/input-files/src/services/storage.Spec.tsx new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/testResources/input-files/src/services/storage.Test.tsx b/packages/core/testResources/input-files/src/services/storage.Test.tsx new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/testResources/input-files/src/services/storage.ts b/packages/core/testResources/input-files/src/services/storage.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/testResources/input-files/src/services/test.ts b/packages/core/testResources/input-files/src/services/test.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/testResources/input-files/src/test.ts b/packages/core/testResources/input-files/src/test.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/testResources/input-files/src/utils/__tests__/commonjs.cjs b/packages/core/testResources/input-files/src/utils/__tests__/commonjs.cjs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/testResources/input-files/src/utils/commonjs.cjs b/packages/core/testResources/input-files/src/utils/commonjs.cjs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/testResources/input-files/src/utils/esm.mjs b/packages/core/testResources/input-files/src/utils/esm.mjs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/testResources/input-files/src/utils/esm.spec.mjs b/packages/core/testResources/input-files/src/utils/esm.spec.mjs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/testResources/input-files/test/setup.js b/packages/core/testResources/input-files/test/setup.js new file mode 100644 index 0000000000..e69de29bb2 From 67cb8b1e6e7a4d1a8e0d0a9aa3cb3719f5139b1d Mon Sep 17 00:00:00 2001 From: Nico Jansen Date: Thu, 3 Sep 2020 09:28:30 +0200 Subject: [PATCH 2/2] Improve patterns --- packages/api/schema/stryker-core.json | 3 +-- .../core/test/integration/input/InputFileResolver.it.spec.ts | 2 +- packages/core/testResources/input-files/src/karma.conf.js | 0 packages/core/testResources/input-files/src/test.ts | 0 4 files changed, 2 insertions(+), 3 deletions(-) delete mode 100644 packages/core/testResources/input-files/src/karma.conf.js delete mode 100644 packages/core/testResources/input-files/src/test.ts diff --git a/packages/api/schema/stryker-core.json b/packages/api/schema/stryker-core.json index b86d88c340..ab13dacc8b 100644 --- a/packages/api/schema/stryker-core.json +++ b/packages/api/schema/stryker-core.json @@ -295,8 +295,7 @@ }, "default": [ "{src,lib}/**/!(*.+(s|S)pec|*.+(t|T)est).+(cjs|mjs|js|ts|jsx|tsx|html|vue)", - "!{src,lib}/**/__tests__/**/*.+(cjs|mjs|js|ts|jsx|tsx|html|vue)", - "!{src,lib}/+(karma.conf.js|.mocharc.js|test.ts)" + "!{src,lib}/**/__tests__/**/*.+(cjs|mjs|js|ts|jsx|tsx|html|vue)" ] }, "mutator": { diff --git a/packages/core/test/integration/input/InputFileResolver.it.spec.ts b/packages/core/test/integration/input/InputFileResolver.it.spec.ts index 6a73a37b54..0f464608c7 100644 --- a/packages/core/test/integration/input/InputFileResolver.it.spec.ts +++ b/packages/core/test/integration/input/InputFileResolver.it.spec.ts @@ -29,7 +29,7 @@ describe(`${InputFileResolver.name} integration`, () => { process.chdir(originalCwd); }); - it.only('should by default resolve reasonable project source files to be mutated', async () => { + it('should by default resolve reasonable project source files to be mutated', async () => { process.chdir(resolveTestResource()); const inputFiles = await sut.resolve(); expect(inputFiles.filesToMutate.map((file) => file.name)).deep.eq([ diff --git a/packages/core/testResources/input-files/src/karma.conf.js b/packages/core/testResources/input-files/src/karma.conf.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/packages/core/testResources/input-files/src/test.ts b/packages/core/testResources/input-files/src/test.ts deleted file mode 100644 index e69de29bb2..0000000000