-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(typescript): Add support for TypeScript mutation testing (#376)
Add support for JavaScript transpiled languages (ESvNext, TypesScript, Flow, CoffeeScript, etc). Add the `stryker-typescript` package with mutation testing utilities for TypeScript. New: * Add new plugin type `Mutator`. With this plugin it is possible to mutate source code. See [Mutator.ts](https://github.com/stryker-mutator/stryker/blob/71b8803b49ce7760c13f1ae314f160d83955a472/packages/stryker-api/src/mutant/Mutator.ts) to review the API. * Add new plugin type `Transpiler`. With this plugin it is possible to transpile source code to JavaScript. This transpiler is than be used to transpile all source code as well as each mutant. See the explanation in #344 for more information. See [Transpiler.ts](https://github.com/stryker-mutator/stryker/blob/71b8803b49ce7760c13f1ae314f160d83955a472/packages/stryker-api/src/transpile/Transpiler.ts) for the api details. * Add stryker-typescript package. This package contains the plugins used for typescript mutation testing. See readme for more information about that. BREAKING CHANGE: * Hoist the `Mutator` interface to a higher abstraction. With this interface it was possible to add mutators for specific ES5 AST nodes. As we're moving away from ES5, this plugin abstraction had to be hoisted to a higher level. It is no longer possible to plugin a specific ES5 node mutator. * Update `report` interface: Rename `MutantState.Error` => `MutantState.RuntimeError`.
- Loading branch information
Showing
222 changed files
with
7,168 additions
and
1,785 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
user:actor | ||
stryker:Stryker[a] | ||
plugin:PluginLoader[a] | ||
cfg:ConfigReader[a] | ||
/cfgEditor:ConfigEditor[a] | ||
ro:ReporterOrchestrator[a] | ||
/reporter:Reporter[a] | ||
/transpiler:Transpiler[a] | ||
|
||
user:stryker.runMutationTest(options) | ||
stryker:plugin.load() | ||
stryker:config=cfg.readConfig() | ||
stryker:cfgEditor.new | ||
stryker:cfgEditor.configure(config) | ||
stryker:broadCastReporter=ro.createReporter() | ||
ro:reporter.new | ||
stryker:transpiler.new | ||
[c:See 2.initial-test-run sequence diagram] | ||
stryker:runResult=stryker.initialTestRun()& | ||
[/c] | ||
[c:See 4.run-test sequence diagram] | ||
stryker:mutationTestResult=stryker.mutaionTest | ||
[/c] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
stryker:Stryker[a] | ||
transpiler:Transpiler[a] | ||
sc:SandboxCoordinator[a] | ||
/sandbox:Sandbox[a] | ||
|
||
stryker:sourceMaps,transpiledFiles=transpiler.transpile(sourceFiles) | ||
stryker:runResult=sc.initialTestRun() | ||
sc:sandbox.new | ||
sc:sandbox.initialize() | ||
sandbox:sandbox.fillSandbox(coverageInstrumenter) | ||
sc:runResult=sandbox.run() | ||
[c See 4.RunTest sequence diagram] | ||
sandbox:sandbox.runTest | ||
[/c] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
stryker:Stryker[p] "Stryker" | ||
cfg:ConfigReader[a] | ||
/cfgEditor:ConfigEditor[a] | ||
ro:ReporterOrchestrator[a] | ||
/reporter:Reporter[a] | ||
/transpiler:Transpiler[a] | ||
sc:SandboxCoordinator[a] | ||
sandbox:Sandbox[a] | ||
ConfiguratorPlugin:configurator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
sandbox:Sandbox "Sandbox" | ||
factory:ResilientTestRunnerFactor | ||
/retry:RetryDecorator[a] | ||
/timeout:TimeoutDecorator[a] | ||
/isolated:IsolatedTestRunnerAdapter[a] | ||
/worker:IsolatedTestRunnerAdpaterWorker[a] | ||
plugin:PluginLoader[a] | ||
|
||
sandbox:testRunner=factory.create(config) | ||
factory:retry.new(config) | ||
retry:timeout.new(config) | ||
timeout:isolated.new(config) | ||
[c:childprocess testRunner] | ||
isolated:worker.new(config) | ||
worker:plugin.load(config) | ||
[/c] | ||
sandbox:retry.inialize() | ||
retry:timeout.initialize() | ||
timeout:isolated.initialize() | ||
[c:childprocess testRunner] | ||
isolated:worker.initialize() | ||
[/c] | ||
sandbox:retry.run() | ||
retry:timeout.run() | ||
timeout:isolated.run() | ||
[c:childprocess testRunner] | ||
isolated:worker.run() | ||
[/c] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "test-module", | ||
"version": "0.0.0", | ||
"private": true, | ||
"description": "A module to perform an integration test", | ||
"main": "index.js", | ||
"scripts": { | ||
"pretest": "rimraf \"reports\"", | ||
"test": "stryker run stryker.conf.js", | ||
"posttest": "mocha --require ts-node/register verify/*.ts" | ||
}, | ||
"author": "", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
export function add(num1: number, num2: number) { | ||
return num1 + num2; | ||
} | ||
|
||
export function addOne(n: number) { | ||
n++; | ||
return n; | ||
} | ||
|
||
export function negate(n: number) { | ||
return -n; | ||
} | ||
|
||
export function notCovered(n: number) { | ||
return n > 10; | ||
} | ||
|
||
export function isNegativeNumber(n: number) { | ||
let isNegative = false; | ||
if (n < 0) { | ||
isNegative = true; | ||
} | ||
return isNegative; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function getCircumference(radius: number) { | ||
return 2 * Math.PI * radius; | ||
} | ||
|
||
export function untestedFunction { | ||
const i = 5 / 2 * 3; | ||
} |
17 changes: 17 additions & 0 deletions
17
integrationTest/test/typescript-transpiling/stryker.conf.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = function (config) { | ||
config.set({ | ||
tsconfigFile: 'tsconfig.json', | ||
mutate: ['src/*.ts'], | ||
testFramework: 'mocha', | ||
testRunner: 'mocha', | ||
coverageAnalysis: 'off', | ||
reporter: ['clear-text', 'html', 'event-recorder'], | ||
maxConcurrentTestRunners: 2, | ||
mutator: 'typescript', | ||
logLevel: 'info', | ||
transpilers: [ | ||
'typescript' | ||
], | ||
port: 9264 | ||
}); | ||
}; |
48 changes: 48 additions & 0 deletions
48
integrationTest/test/typescript-transpiling/test/AddSpec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { expect } from 'chai'; | ||
import { add, addOne, isNegativeNumber, notCovered, negate } from '../src/Add'; | ||
|
||
describe('Add', () => { | ||
it('should be able to add two numbers', () => { | ||
const num1 = 2; | ||
const num2 = 5; | ||
const expected = num1 + num2; | ||
|
||
const actual = add(num1, num2); | ||
|
||
expect(actual).to.be.equal(expected); | ||
}); | ||
|
||
it('should be able 1 to a number', () => { | ||
const number = 2; | ||
const expected = 3; | ||
|
||
const actual = addOne(number); | ||
|
||
expect(actual).to.be.equal(expected); | ||
}); | ||
|
||
it('should be able negate a number', () => { | ||
const number = 2; | ||
const expected = -2; | ||
|
||
const actual = negate(number); | ||
|
||
expect(actual).to.be.equal(expected); | ||
}); | ||
|
||
it('should be able to recognize a negative number', () => { | ||
const number = -2; | ||
|
||
const isNegative = isNegativeNumber(number); | ||
|
||
expect(isNegative).to.be.true; | ||
}); | ||
|
||
it('should be able to recognize that 0 is not a negative number', () => { | ||
const number = 0; | ||
|
||
const isNegative = isNegativeNumber(number); | ||
|
||
expect(isNegative).to.be.false; | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
integrationTest/test/typescript-transpiling/test/CircleSpec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { expect } from 'chai'; | ||
import { getCircumference } from '../src/Circle'; | ||
|
||
describe('Circle', () => { | ||
it('should have a circumference of 2PI when the radius is 1', () => { | ||
const radius = 1; | ||
const expectedCircumference = 2 * Math.PI; | ||
const circumference = getCircumference(radius); | ||
expect(circumference).to.be.equal(expectedCircumference); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": [ | ||
"es5", | ||
"es2015.promise", | ||
"es2015.core" | ||
] | ||
}, | ||
"files": [ | ||
"src/*.ts", | ||
"test/*.ts" | ||
] | ||
} |
33 changes: 33 additions & 0 deletions
33
integrationTest/test/typescript-transpiling/verify/verify.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as chai from 'chai'; | ||
import * as fs from 'mz/fs'; | ||
import * as chaiAsPromised from 'chai-as-promised'; | ||
chai.use(chaiAsPromised); | ||
const expect = chai.expect; | ||
const expectFileExists = (path: string) => expect(fs.exists(path), `File ${path} does not exist`).to.eventually.eq(true); | ||
|
||
describe('Verify stryker has ran correctly', () => { | ||
|
||
describe('html reporter', () => { | ||
|
||
it('should report in html files', () => { | ||
return Promise.all([ | ||
expectFileExists('reports/mutation/html/Add.ts.html'), | ||
expectFileExists('reports/mutation/html/Circle.ts.html'), | ||
expectFileExists('reports/mutation/html/index.html') | ||
]); | ||
}); | ||
|
||
it('should copy over the resources', () => { | ||
return Promise.all([ | ||
expectFileExists('reports/mutation/html/stryker.css'), | ||
expectFileExists('reports/mutation/html/stryker.js'), | ||
expectFileExists('reports/mutation/html/stryker-80x80.png'), | ||
expectFileExists('reports/mutation/html/bootstrap/css/bootstrap.min.css'), | ||
expectFileExists('reports/mutation/html/bootstrap/css/bootstrap.min.css'), | ||
expectFileExists('reports/mutation/html/highlightjs/styles/default.css') | ||
]); | ||
}); | ||
}); | ||
|
||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib", | ||
"files": { | ||
"exclude": { | ||
".git": "", | ||
"**/*.js": { | ||
"when": "$(basename).ts" | ||
}, | ||
"**/*.d.ts": { | ||
"when": "$(basename).ts" | ||
}, | ||
"**/*.map": { | ||
"when": "$(basename)" | ||
} | ||
"typescript.tsdk": "../../node_modules/typescript/lib", | ||
"files.exclude": { | ||
".git": true, | ||
"**/*.js": { | ||
"when": "$(basename).ts" | ||
}, | ||
"**/*.d.ts": { | ||
"when": "$(basename).ts" | ||
}, | ||
"**/*.map": { | ||
"when": "$(basename)" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { default as Mutant } from './src/mutant/Mutant'; | ||
export { default as Mutator } from './src/mutant/Mutator'; | ||
export { default as MutatorFactory } from './src/mutant/MutatorFactory'; | ||
export { IdentifiedNode, Identified } from './src/mutant/IdentifiedNode'; | ||
export { default as MutatorFactory } from './src/mutant/MutatorFactory'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.