-
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.
fix(core): exit process on error (#2378)
Exit with non-zero exit code when an error occurs. * Update typed-inject to v3 in order to dispose of the `rootInjector` * Rename some e2e tests to better reflect what they're testing. * Add an e2e test for a failing dry run. Fixes #2315
- Loading branch information
Showing
50 changed files
with
226 additions
and
88 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,3 @@ | ||
{ | ||
"spec": ["test/unit/*.js"] | ||
} |
File renamed without changes.
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": "exit-prematurely-dry-run-fails", | ||
"version": "0.0.0", | ||
"private": true, | ||
"description": "A module to perform an integration test", | ||
"main": "index.js", | ||
"scripts": { | ||
"pretest": "rimraf reports .stryker-tmp stryker.log", | ||
"test": "stryker run || node -p \"require('fs').appendFileSync('stryker.log', 'Exited with an error exit code')\"", | ||
"posttest": "mocha --no-config --require ../../tasks/ts-node-register.js 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,6 @@ | ||
module.exports.add = function(num1, num2) { | ||
return num1 + num2; | ||
}; | ||
|
||
|
||
|
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 @@ | ||
{ | ||
"$schema": "../../node_modules/@stryker-mutator/core/schema/stryker-schema.json", | ||
"testRunner": "mocha", | ||
"concurrency": 2, | ||
"coverageAnalysis": "off", | ||
"fileLogLevel": "info", | ||
"reporters": ["clear-text", "html", "event-recorder"], | ||
"plugins": [ | ||
"@stryker-mutator/mocha-runner" | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
e2e/test/exit-prematurely-dry-run-fails/test/unit/add.spec.ts.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,13 @@ | ||
const { add } = require('../../src/add'); | ||
const { expect } = require('chai'); | ||
|
||
describe('add', () => { | ||
|
||
it('2 + 3 = 5', () => { | ||
expect(add(2, 3)).to.be.equal(5); | ||
}); | ||
|
||
it('1 + 1 = 3... ? (this is the test that should fail)', () => { | ||
expect(add(1, 1)).to.be.equal(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,28 @@ | ||
import { promises as fs } from 'fs'; | ||
import { expect } from 'chai'; | ||
import { it } from 'mocha'; | ||
|
||
describe('Verify stryker has handled dry run failure correctly', () => { | ||
|
||
let strykerLog: string; | ||
|
||
before(async () => { | ||
strykerLog = await fs.readFile('./stryker.log', 'utf8'); | ||
}); | ||
|
||
it('should about failed tests in initial test run', async () => { | ||
expect(strykerLog).contains('There were failed tests in the initial test run'); | ||
}); | ||
|
||
it('should log exactly which test failed and why', async () => { | ||
expect(strykerLog) | ||
.contains('add 1 + 1 = 3... ? (this is the test that should fail)') | ||
.contains('expected 2 to equal 3'); | ||
}); | ||
|
||
it('should have exited with a non-zero exit code', async () => { | ||
// This line is added in package.json script if the process exited in an error. | ||
expect(strykerLog) | ||
.contains('Exited with an error exit code'); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
e2e/test/exit-prematurely/package.json → ...rematurely-no-tests-executed/package.json
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
File renamed without changes.
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 @@ | ||
// Idle |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
e2e/test/jasmine-jasmine/package.json → e2e/test/jasmine-javascript/package.json
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
e2e/test/mocha-mocha/package.json → e2e/test/mocha-javascript/package.json
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
|
@@ -44,6 +44,6 @@ | |
}, | ||
"devDependencies": { | ||
"@types/node": "^14.0.1", | ||
"typed-inject": "~2.2.1" | ||
"typed-inject": "~3.0.0" | ||
} | ||
} |
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
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,15 @@ | ||
import { Injector, Scope } from 'typed-inject'; | ||
import { commonTokens } from '@stryker-mutator/api/plugin'; | ||
import { LoggerFactoryMethod, Logger } from '@stryker-mutator/api/logging'; | ||
import { getLogger } from 'log4js'; | ||
|
||
export function provideLogger(injector: Injector): LoggerProvider { | ||
return injector.provideValue(commonTokens.getLogger, getLogger).provideFactory(commonTokens.logger, loggerFactory, Scope.Transient); | ||
} | ||
export type LoggerProvider = Injector<{ [commonTokens.getLogger]: LoggerFactoryMethod; [commonTokens.logger]: Logger }>; | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
function loggerFactory(getLogger: LoggerFactoryMethod, target: Function | undefined) { | ||
return getLogger(target ? target.name : 'UNKNOWN'); | ||
} | ||
loggerFactory.inject = [commonTokens.getLogger, commonTokens.target] as const; |
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.