diff --git a/packages/stryker-mocha-runner/package.json b/packages/stryker-mocha-runner/package.json index eb19c63411..90d1b54036 100644 --- a/packages/stryker-mocha-runner/package.json +++ b/packages/stryker-mocha-runner/package.json @@ -31,7 +31,7 @@ "log4js": "^0.6.37" }, "peerDependencies": { - "stryker-api": "^0.1.0", + "stryker-api": "^0.1.2", "mocha": "^2.3.3" }, "devDependencies": { @@ -52,7 +52,7 @@ "mocha-sinon": "^1.1.4", "sinon": "^1.17.2", "sinon-chai": "^2.8.0", - "stryker-api": "0.1.0", + "stryker-api": "0.1.2", "typescript": "^1.8.10", "typings": "^1.3.1" } diff --git a/packages/stryker-mocha-runner/src/MochaTestRunner.ts b/packages/stryker-mocha-runner/src/MochaTestRunner.ts index 76d3579fdc..9ee6ba5499 100644 --- a/packages/stryker-mocha-runner/src/MochaTestRunner.ts +++ b/packages/stryker-mocha-runner/src/MochaTestRunner.ts @@ -1,4 +1,5 @@ import {TestRunner, TestResult, RunResult, RunnerOptions, CoverageCollection} from 'stryker-api/test_runner'; +import {InputFile} from 'stryker-api/core'; import * as path from 'path'; import * as log4js from 'log4js'; // import * as Mocha from 'mocha'; @@ -7,14 +8,14 @@ import StrykerMochaReporter from './StrykerMochaReporter'; const log = log4js.getLogger('MochaTestRunner'); export default class MochaTestRunner implements TestRunner { - private files: string[]; + private files: InputFile[]; constructor(runnerOptions: RunnerOptions) { - this.files = runnerOptions.files.map(f => path.resolve(f.path)); + this.files = runnerOptions.files; } private purgeFiles() { - this.files.forEach(f => delete require.cache[f]); + this.files.forEach(f => delete require.cache[f.path]); } run(): Promise { @@ -22,7 +23,7 @@ export default class MochaTestRunner implements TestRunner { try { this.purgeFiles(); let mocha = new Mocha({ reporter: StrykerMochaReporter }); - this.files.forEach(f => mocha.addFile(f)); + this.files.filter(file => file.included).forEach(f => mocha.addFile(f.path)); try { let runner: any = mocha.run((failures: number) => { let result: RunResult = runner.runResult; @@ -36,7 +37,7 @@ export default class MochaTestRunner implements TestRunner { } } catch (error) { log.error(error); - fail(); + fail(error); } }); diff --git a/packages/stryker-mocha-runner/test/integration/MochaTestRunnerSpec.ts b/packages/stryker-mocha-runner/test/integration/MochaTestRunnerSpec.ts index 674a87e43a..5fc1655de2 100644 --- a/packages/stryker-mocha-runner/test/integration/MochaTestRunnerSpec.ts +++ b/packages/stryker-mocha-runner/test/integration/MochaTestRunnerSpec.ts @@ -2,10 +2,11 @@ import * as chai from 'chai'; import MochaTestRunner from '../../src/MochaTestRunner'; import {TestResult, RunnerOptions, RunResult} from 'stryker-api/test_runner'; import * as chaiAsPromised from 'chai-as-promised'; +import * as path from 'path'; chai.use(chaiAsPromised); let expect = chai.expect; -describe.only('MochaTestRunner', function() { +describe('MochaTestRunner', function () { var sut: MochaTestRunner; this.timeout(10000); @@ -15,7 +16,9 @@ describe.only('MochaTestRunner', function() { before(() => { testRunnerOptions = { - files: [{ path: 'testResources/sampleProject/src/MyMath.js', shouldMutate: true }, { path: 'testResources/sampleProject/test/MyMathSpec.js', shouldMutate: false }], + files: [ + file('./testResources/sampleProject/src/MyMath.js'), + file('./testResources/sampleProject/test/MyMathSpec.js')], coverageEnabled: false, strykerOptions: {}, port: 1234 @@ -39,12 +42,33 @@ describe.only('MochaTestRunner', function() { }); it('should be able to run 2 times in a row', () => { - return expect(sut.run().then( () => sut.run())).to.eventually.satisfy((testResult: RunResult) => { + return expect(sut.run().then(() => sut.run())).to.eventually.satisfy((testResult: RunResult) => { expect(testResult.succeeded).to.be.eq(5); return true; }); }); }); + + describe('with an error in an unincluded input file', () => { + before(() => { + let options = { + files: [ + file('testResources/sampleProject/src/MyMath.js'), + file('testResources/sampleProject/src/Error.js', false, false), + file('testResources/sampleProject/test/MyMathSpec.js')], + coverageEnabled: false, + strykerOptions: {}, + port: 1234 + }; + sut = new MochaTestRunner(options); + }); + + it('should report completed tests without errors', () => expect(sut.run()).to.eventually.satisfy((testResult: RunResult) => { + expect(testResult.result).to.be.eq(TestResult.Complete, 'Test result did not match'); + return true; + })); + }); }); + let file = (filePath: string, mutated: boolean = true, included: boolean = true) => ({ path: path.resolve(filePath), mutated, included }); }); \ No newline at end of file diff --git a/packages/stryker-mocha-runner/testResources/sampleProject/src/Error.js b/packages/stryker-mocha-runner/testResources/sampleProject/src/Error.js new file mode 100644 index 0000000000..2c5f9bed23 --- /dev/null +++ b/packages/stryker-mocha-runner/testResources/sampleProject/src/Error.js @@ -0,0 +1,2 @@ + +someGlobalObjectWhichDoesNotExist.someFunctionWhichDoesNotExist('1', 2); \ No newline at end of file