-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Command test runner): Add command test runner (#1047)
Add the command test runner. This test runner simply runs command from the bash/cmd prompt. It defaults to `npm test`. It will always report exactly _one_ test result (called `'All tests'`), as it cannot distinguish between the tests. It is implemented differently from other test runners, as we don't want to spawn this one in a separate process (it already uses `require('child_process').exec` to start a test run). Fixes #768
- Loading branch information
Showing
24 changed files
with
584 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as path from 'path'; | ||
import * as fs from 'mz/fs'; | ||
import { expect } from 'chai'; | ||
import { ScoreResult } from 'stryker-api/report'; | ||
|
||
export async function readScoreResult(eventResultDirectory = path.resolve('reports', 'mutation', 'events')) { | ||
const allReportFiles = await fs.readdir(eventResultDirectory); | ||
const scoreResultReportFile = allReportFiles.find(file => !!file.match(/.*onScoreCalculated.*/)); | ||
expect(scoreResultReportFile).ok; | ||
const scoreResultContent = await fs.readFile(path.resolve(eventResultDirectory, scoreResultReportFile || ''), 'utf8'); | ||
return JSON.parse(scoreResultContent) as ScoreResult; | ||
} |
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,15 @@ | ||
{ | ||
"name": "test-module", | ||
"version": "0.0.0", | ||
"private": true, | ||
"description": "A module to perform an integration test", | ||
"main": "index.js", | ||
"scripts": { | ||
"pretest": "rimraf \"reports\" \"stryker.log\"", | ||
"test": "stryker run stryker.conf.js", | ||
"mocha": "mocha", | ||
"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,26 @@ | ||
module.exports.add = function(num1, num2) { | ||
return num1 + num2; | ||
}; | ||
|
||
module.exports.addOne = function(number) { | ||
number++; | ||
return number; | ||
}; | ||
|
||
module.exports.negate = function(number) { | ||
return -number; | ||
}; | ||
|
||
module.exports.notCovered = function(number) { | ||
return number > 10; | ||
}; | ||
|
||
module.exports.isNegativeNumber = function(number) { | ||
var isNegative = false; | ||
if(number < 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,8 @@ | ||
module.exports.getCircumference = function(radius) { | ||
//Function to test multiple math mutations in a single function. | ||
return 2 * Math.PI * radius; | ||
}; | ||
|
||
module.exports.untestedFunction = function() { | ||
var i = 5 / 2 * 3; | ||
}; |
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,15 @@ | ||
module.exports = function (config) { | ||
config.set({ | ||
mutate: ['src/*.js'], | ||
testFramework: 'mocha', | ||
coverageAnalysis: 'off', | ||
reporter: ['clear-text', 'event-recorder'], | ||
mutator: 'javascript', | ||
maxConcurrentTestRunners: 2, | ||
commandRunner: { | ||
command: 'npm run mocha' | ||
}, | ||
symlinkNodeModules: false, | ||
fileLogLevel: 'info' | ||
}); | ||
}; |
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,55 @@ | ||
var expect = require('chai').expect; | ||
var addModule = require('../src/Add'); | ||
var add = addModule.add; | ||
var addOne = addModule.addOne; | ||
var isNegativeNumber = addModule.isNegativeNumber; | ||
var negate = addModule.negate; | ||
var notCovered = addModule.notCovered; | ||
|
||
console.log(process.env.path); | ||
|
||
describe('Add', function() { | ||
it('should be able to add two numbers', function() { | ||
var num1 = 2; | ||
var num2 = 5; | ||
var expected = num1 + num2; | ||
|
||
var actual = add(num1, num2); | ||
|
||
expect(actual).to.be.equal(expected); | ||
}); | ||
|
||
it('should be able 1 to a number', function() { | ||
var number = 2; | ||
var expected = 3; | ||
|
||
var actual = addOne(number); | ||
|
||
expect(actual).to.be.equal(expected); | ||
}); | ||
|
||
it('should be able negate a number', function() { | ||
var number = 2; | ||
var expected = -2; | ||
|
||
var actual = negate(number); | ||
|
||
expect(actual).to.be.equal(expected); | ||
}); | ||
|
||
it('should be able to recognize a negative number', function() { | ||
var number = -2; | ||
|
||
var isNegative = isNegativeNumber(number); | ||
|
||
expect(isNegative).to.be.true; | ||
}); | ||
|
||
it('should be able to recognize that 0 is not a negative number', function() { | ||
var number = 0; | ||
|
||
var isNegative = isNegativeNumber(number); | ||
|
||
expect(isNegative).to.be.false; | ||
}); | ||
}); |
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 @@ | ||
var expect = require('chai').expect; | ||
var circleModule = require('../src/Circle'); | ||
var getCircumference = circleModule.getCircumference; | ||
|
||
describe('Circle', function() { | ||
it('should have a circumference of 2PI when the radius is 1', function() { | ||
var radius = 1; | ||
var expectedCircumference = 2 * Math.PI; | ||
|
||
var 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,9 @@ | ||
{ | ||
"extends": "../../../tsconfig.json", | ||
"compilerOptions": { | ||
"declaration": false | ||
}, | ||
"files": [ | ||
"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,20 @@ | ||
import * as fs from 'mz/fs'; | ||
import { expect } from 'chai'; | ||
import * as path from 'path'; | ||
import { readScoreResult } from '../../../helpers'; | ||
|
||
describe('After running stryker with the command test runner', () => { | ||
it('should report 69% mutation score', async () => { | ||
const scoreResult = await readScoreResult(path.resolve('reports', 'mutation', 'events')); | ||
expect(scoreResult.killed).eq(16); | ||
expect(scoreResult.noCoverage).eq(0); | ||
expect(scoreResult.mutationScore).greaterThan(69).and.lessThan(70); | ||
}); | ||
|
||
it('should write to a log file', async () => { | ||
const strykerLog = await fs.readFile('./stryker.log', 'utf8'); | ||
expect(strykerLog).contains('INFO InitialTestExecutor Initial test run succeeded. Ran 1 test'); | ||
expect(strykerLog).matches(/Stryker Done in \d+/); | ||
expect(strykerLog).not.contains('ERROR'); | ||
}); | ||
}); |
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
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.