Skip to content

Commit

Permalink
fix(JestTestRunner): fix stryker error on skipping tests (#1168)
Browse files Browse the repository at this point in the history
Implement `TestStatus.Skipped` for pending jest results so Stryker does not fail on the first testrun when tests are marked as `skip`

Fixes #1152
  • Loading branch information
Sander Koenders authored and simondel committed Oct 3, 2018
1 parent e56621f commit 1f87ab1
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 122 deletions.
13 changes: 12 additions & 1 deletion packages/stryker-jest-runner/src/JestTestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,23 @@ export default class JestTestRunner implements TestRunner {
testResults.push({
failureMessages: testResult.failureMessages,
name: testResult.fullName,
status: (testResult.status === 'passed') ? TestStatus.Success : TestStatus.Failed,
status: this.determineTestResultStatus(testResult.status),
timeSpentMs: testResult.duration ? testResult.duration : 0
});
}
}

return testResults;
}

private determineTestResultStatus(status: string) {
switch (status) {
case 'passed':
return TestStatus.Success;
case 'pending':
return TestStatus.Skipped;
default:
return TestStatus.Failed;
}
}
}
278 changes: 157 additions & 121 deletions packages/stryker-jest-runner/test/helpers/testResultProducer.ts
Original file line number Diff line number Diff line change
@@ -1,122 +1,158 @@
export function createFailResult() {
return {
numFailedTests: 2,
numFailedTestSuites: 1,
numPassedTests: 0,
numPassedTestSuites: 0,
numPendingTests: 0,
numPendingTestSuites: 0,
numRuntimeErrorTestSuites: 0,
numTotalTests: 2,
numTotalTestSuites: 1,
startTime: 1513852010583,
success: false,
testResults: [
{
console: null,
coverage: undefined,
failureMessage: 'test failed - App.test.js',
numFailingTests: 2,
numPassingTests: 0,
numPendingTests: 0,
skipped: false,
sourceMaps: {},
testFilePath: 'App.test.js',
testResults: [
{
ancestorTitles: ['App'],
duration: 2,
failureMessages: [
'Fail message 1',
'Fail message 2'
],
fullName: 'App render renders without crashing',
numPassingAsserts: 0,
status: 'failed',
title: 'renders without crashing'
},
{
ancestorTitles: ['App'],
duration: 0,
failureMessages: [
'Fail message 3',
'Fail message 4'
],
fullName: 'App render renders without crashing',
numPassingAsserts: 0,
status: 'failed',
title: 'renders without crashing'
}
]
},
{
console: null,
coverage: undefined,
failureMessage: null,
numFailingTests: 0,
numPassingTests: 1,
numPendingTests: 0,
perfStats: [Object],
skipped: false,
snapshot: [Object],
sourceMaps: {},
testFilePath: 'App.test.js',
testResults: [
{
ancestorTitles: ['App'],
duration: 23,
failureMessages: [],
fullName: 'App renders without crashing',
numPassingAsserts: 0,
status: 'passed',
title: 'renders without crashing'
}
]
}
],
wasInterrupted: false
};
}
export const createFailResult = () => ({
numFailedTests: 2,
numFailedTestSuites: 1,
numPassedTests: 0,
numPassedTestSuites: 0,
numPendingTests: 0,
numPendingTestSuites: 0,
numRuntimeErrorTestSuites: 0,
numTotalTests: 2,
numTotalTestSuites: 1,
startTime: 1513852010583,
success: false,
testResults: [
{
console: null,
coverage: undefined,
failureMessage: 'test failed - App.test.js',
numFailingTests: 2,
numPassingTests: 0,
numPendingTests: 0,
skipped: false,
sourceMaps: {},
testFilePath: 'App.test.js',
testResults: [
{
ancestorTitles: ['App'],
duration: 2,
failureMessages: [
'Fail message 1',
'Fail message 2'
],
fullName: 'App render renders without crashing',
numPassingAsserts: 0,
status: 'failed',
title: 'renders without crashing'
},
{
ancestorTitles: ['App'],
duration: 0,
failureMessages: [
'Fail message 3',
'Fail message 4'
],
fullName: 'App render renders without crashing',
numPassingAsserts: 0,
status: 'failed',
title: 'renders without crashing'
}
]
},
{
console: null,
coverage: undefined,
failureMessage: null,
numFailingTests: 0,
numPassingTests: 1,
numPendingTests: 0,
perfStats: [Object],
skipped: false,
snapshot: [Object],
sourceMaps: {},
testFilePath: 'App.test.js',
testResults: [
{
ancestorTitles: ['App'],
duration: 23,
failureMessages: [],
fullName: 'App renders without crashing',
numPassingAsserts: 0,
status: 'passed',
title: 'renders without crashing'
}
]
}
],
wasInterrupted: false
});

export function createSuccessResult() {
return {
numFailedTests: 0,
numFailedTestSuites: 0,
numPassedTests: 1,
numPassedTestSuites: 1,
numPendingTests: 0,
numPendingTestSuites: 0,
numRuntimeErrorTestSuites: 0,
numTotalTests: 1,
numTotalTestSuites: 1,
startTime: 1513857548132,
success: true,
testResults: [
{
console: null,
coverage: undefined,
failureMessage: null,
numFailingTests: 0,
numPassingTests: 1,
numPendingTests: 0,
perfStats: [Object],
skipped: false,
snapshot: [Object],
sourceMaps: {},
testFilePath: 'App.test.js',
testResults: [
{
ancestorTitles: ['App'],
duration: 23,
failureMessages: [],
fullName: 'App renders without crashing',
numPassingAsserts: 0,
status: 'passed',
title: 'renders without crashing'
}
]
}
],
wasInterrupted: false
};
}
export const createSuccessResult = () => ({
numFailedTests: 0,
numFailedTestSuites: 0,
numPassedTests: 1,
numPassedTestSuites: 1,
numPendingTests: 0,
numPendingTestSuites: 0,
numRuntimeErrorTestSuites: 0,
numTotalTests: 1,
numTotalTestSuites: 1,
startTime: 1513857548132,
success: true,
testResults: [
{
console: null,
coverage: undefined,
failureMessage: null,
numFailingTests: 0,
numPassingTests: 1,
numPendingTests: 0,
perfStats: [Object],
skipped: false,
snapshot: [Object],
sourceMaps: {},
testFilePath: 'App.test.js',
testResults: [
{
ancestorTitles: ['App'],
duration: 23,
failureMessages: [],
fullName: 'App renders without crashing',
numPassingAsserts: 0,
status: 'passed',
title: 'renders without crashing'
}
]
}
],
wasInterrupted: false
});

export const createPendingResult = () => ({
numFailedTests: 0,
numFailedTestSuites: 0,
numPassedTests: 1,
numPassedTestSuites: 1,
numPendingTests: 0,
numPendingTestSuites: 0,
numRuntimeErrorTestSuites: 0,
numTotalTests: 1,
numTotalTestSuites: 1,
startTime: 1513857548132,
success: true,
testResults: [
{
console: null,
coverage: undefined,
failureMessage: null,
numFailingTests: 0,
numPassingTests: 1,
numPendingTests: 0,
perfStats: [Object],
skipped: false,
snapshot: [Object],
sourceMaps: {},
testResults: [
{
ancestorTitles: ['App'],
duration: 0,
failureMessages: [],
fullName: 'App renders without crashing',
numPassingAsserts: 0,
status: 'pending',
title: 'renders without crashing'
}
]
}
],
wasInterrupted: false
});
19 changes: 19 additions & 0 deletions packages/stryker-jest-runner/test/unit/JestTestRunnerSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,25 @@ describe('JestTestRunner', () => {
});
});

it('should call the jestTestRunner run method and return a skipped runResult', async () => {
runJestStub.resolves({ results: fakeResults.createPendingResult() });

const result = await jestTestRunner.run();

expect(result).to.deep.equal({
errorMessages: [],
status: RunStatus.Complete,
tests: [
{
failureMessages: [],
name: 'App renders without crashing',
status: TestStatus.Skipped,
timeSpentMs: 0
}
]
});
});

it('should call the jestTestRunner run method and return a negative runResult', async () => {
runJestStub.resolves({ results: fakeResults.createFailResult() });

Expand Down

0 comments on commit 1f87ab1

Please sign in to comment.