-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add support for checker plugins (#2285)
Add support for Checker plugins. A checker plugin takes the place of the old transpiler plugin. When a checker plugin is configured, every mutant is checked before a test runner picks it up. This will allow typescript type checking to take place using the `@stryker-mutator/typescript-checker` plugin. Since checking a mutant can take a long time (~2 sec/mutant with the `@stryker-mutator/typescript-checker` on Stryker's core project), we use worker processes to run this in parallel. These processes are entirely managed by Stryker core, plugin creators don't need to worry about this. Add `--concurrency` (or `-c`) option which set the number of concurrent worker processes to be used by Stryker. A worker can be a checker process or a test runner process. The default is nr of CPU's available -1, with a minimum of 1 test runner process and 1 checker process (if a checker is configured). The algorithm used to determine the number of checkers is `ceil(--concurrency / 2)`. This allows room for `floor(--concurrency / 2)` test runners. Once the check process is done, all check processes are closed and more test runner processes are spun up to speed up the mutation testing process. BREAKING CHANGE: * `--maxConcurrentTestRunners` is now deprecated. Please use `--concurrency` instead.
- Loading branch information
Showing
80 changed files
with
250,259 additions
and
2,079 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,16 @@ | ||
{ | ||
"name": "jasmine-ts-node", | ||
"description": "A test for mocha using ts-node (no transpiler) using mocha package config", | ||
"scripts": { | ||
"test:unit": "jasmine", | ||
"test": "stryker run", | ||
"posttest": "mocha --no-package --require \"ts-node/register\" verify/verify.ts" | ||
}, | ||
"mocha": { | ||
"require": "ts-node/register/transpile-only", | ||
"spec": "test/**/*.ts" | ||
}, | ||
"devDependencies": { | ||
"@types/jasmine": "^3.5.11" | ||
} | ||
} |
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,61 @@ | ||
import { Player } from '../src/Player'; | ||
import { Song } from '../src/Song'; | ||
|
||
describe("Player", function () { | ||
var player; | ||
var song; | ||
|
||
beforeEach(function () { | ||
player = new Player(); | ||
song = new Song(); | ||
}); | ||
|
||
it("should be able to play a Song", function () { | ||
player.play(song); | ||
expect(player.currentlyPlayingSong).toEqual(song); | ||
|
||
//demonstrates use of custom matcher | ||
expect(player).toBePlaying(song); | ||
}); | ||
|
||
describe("when song has been paused", function () { | ||
beforeEach(function () { | ||
player.play(song); | ||
player.pause(); | ||
}); | ||
|
||
it("should indicate that the song is currently paused", function () { | ||
expect(player.isPlaying).toBeFalsy(); | ||
|
||
// demonstrates use of 'not' with a custom matcher | ||
expect(player).not.toBePlaying(song); | ||
}); | ||
|
||
it("should be possible to resume", function () { | ||
player.resume(); | ||
expect(player.isPlaying).toBeTruthy(); | ||
expect(player.currentlyPlayingSong).toEqual(song); | ||
}); | ||
}); | ||
|
||
// demonstrates use of spies to intercept and test method calls | ||
it("tells the current song if the user has made it a favorite", function () { | ||
spyOn(song, 'persistFavoriteStatus'); | ||
|
||
player.play(song); | ||
player.makeFavorite(); | ||
|
||
expect(song.persistFavoriteStatus).toHaveBeenCalledWith(true); | ||
}); | ||
|
||
//demonstrates use of expected exceptions | ||
describe("#resume", function () { | ||
it("should throw an exception if song is already playing", function () { | ||
player.play(song); | ||
|
||
expect(function () { | ||
player.resume(); | ||
}).toThrowError("song is already playing"); | ||
}); | ||
}); | ||
}); |
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 @@ | ||
import { concat } from '../src/concat'; | ||
|
||
describe(concat.name, () => { | ||
it('should concat a and b', () => { | ||
expect(concat('foo', 'bar')).toBe('foobar'); | ||
}) | ||
}); |
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,3 @@ | ||
require('ts-node').register({ | ||
transpileOnly: true | ||
}); |
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,5 @@ | ||
declare module jasmine { | ||
interface Matchers<T> { | ||
toBePlaying(song: import('../../src/Song').Song): boolean; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
e2e/test/jasmine-ts-node/spec/helpers/IsCurrentlyPlayingMatcher.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,20 @@ | ||
import { Player } from "../../src/Player"; | ||
import { Song } from "../../src/Song"; | ||
|
||
beforeEach(function () { | ||
jasmine.addMatchers({ | ||
toBePlaying: function () { | ||
return { | ||
compare: function (actual: Player, expected: Song) { | ||
var player = actual; | ||
|
||
return { | ||
pass: player.currentlyPlayingSong === expected && player.isPlaying | ||
} | ||
} | ||
}; | ||
} | ||
}); | ||
}); | ||
|
||
|
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 @@ | ||
{ | ||
"spec_dir": "spec", | ||
"spec_files": [ | ||
"**/*[sS]pec.[jt]s" | ||
], | ||
"helpers": [ | ||
"helpers/**/*.[jt]s" | ||
], | ||
"stopSpecOnExpectationFailure": false, | ||
"random": true | ||
} |
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,26 @@ | ||
import { Song } from "./Song"; | ||
|
||
export class Player { | ||
public currentlyPlayingSong: Song; | ||
public isPlaying: boolean; | ||
|
||
play(song: Song) { | ||
this.currentlyPlayingSong = song; | ||
this.isPlaying = true; | ||
} | ||
|
||
pause() { | ||
this.isPlaying = false; | ||
} | ||
|
||
resume() { | ||
if (this.isPlaying) { | ||
throw new Error('song is already playing'); | ||
} | ||
this.isPlaying = true; | ||
} | ||
|
||
makeFavorite() { | ||
this.currentlyPlayingSong.persistFavoriteStatus(true); | ||
} | ||
} |
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,5 @@ | ||
export class Song { | ||
persistFavoriteStatus(value: boolean) { | ||
throw new Error('not yet implemented'); | ||
} | ||
} |
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,3 @@ | ||
export function concat(a: string, b: string) { | ||
return a + b; // Will be a compile error when mutated | ||
} |
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 @@ | ||
{ | ||
"$schema": "../../node_modules/@stryker-mutator/core/schema/stryker-schema.json", | ||
"mutate": [ | ||
"{src,lib}/**/*.ts?(x)" | ||
], | ||
"checkers": [ | ||
"typescript" | ||
], | ||
"testRunner": "jasmine", | ||
"concurrency": 2, | ||
"coverageAnalysis": "perTest", | ||
"reporters": ["event-recorder", "clear-text"], | ||
"plugins": [ | ||
"@stryker-mutator/typescript-checker", | ||
"@stryker-mutator/jasmine-runner" | ||
] | ||
} |
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 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["ES2017"], | ||
"module": "CommonJS", | ||
"target": "ES2017", | ||
"types": ["jasmine"] | ||
}, | ||
"include": ["src", "spec"] | ||
} |
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 @@ | ||
import { expectMetrics } from '../../../helpers'; | ||
|
||
describe('Verify stryker has ran correctly', () => { | ||
|
||
it('should report correct score', async () => { | ||
await expectMetrics({ | ||
ignored: 0, | ||
killed: 12, | ||
mutationScore: 85.71, | ||
noCoverage: 2, | ||
survived: 0, | ||
timeout: 0, | ||
runtimeErrors: 0, | ||
compileErrors: 2 | ||
}); | ||
}); | ||
}); |
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
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,26 @@ | ||
const { zip, range, Subject, partition, ReplaySubject } = require('rxjs'); | ||
const { tap, shareReplay } = require('rxjs/operators'); | ||
|
||
const subject = new ReplaySubject(); | ||
|
||
subject.next(0); | ||
|
||
const n$ = subject.pipe(tap(n => console.log(`before replay ${n}`)), shareReplay(), tap(n => console.log(`after replay ${n}`))) | ||
|
||
|
||
const sub1 = n$.subscribe(console.log.bind(console, 'sub1')); | ||
|
||
subject.next(1); | ||
|
||
const sub2 = n$.subscribe(console.log.bind(console, 'sub2')) | ||
|
||
|
||
subject.next(2); | ||
|
||
sub1.unsubscribe(); | ||
sub2.unsubscribe(); | ||
|
||
subject.next(3); | ||
n$.subscribe(console.log.bind(console, 'sub3')); | ||
|
||
subject.next(4); |
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.