Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(reporting): report test name when a hook fails (#2757)
Report the test name when a `beforeEach` or `afterEach` hook fails.
- Loading branch information
Showing
4 changed files
with
85 additions
and
3 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
62 changes: 62 additions & 0 deletions
62
packages/mocha-runner/test/integration/regession.it.spec.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,62 @@ | ||
import { FailedTestResult, TestStatus } from '@stryker-mutator/api/test-runner'; | ||
import { assertions, factory, testInjector } from '@stryker-mutator/test-helpers'; | ||
import { expect } from 'chai'; | ||
|
||
import { createMochaTestRunnerFactory } from '../../src'; | ||
import { MochaRunnerWithStrykerOptions } from '../../src/mocha-runner-with-stryker-options'; | ||
import { resolveTestResource } from '../helpers/resolve-test-resource'; | ||
|
||
describe('regression integration tests', () => { | ||
let options: MochaRunnerWithStrykerOptions; | ||
|
||
beforeEach(() => { | ||
options = testInjector.options as MochaRunnerWithStrykerOptions; | ||
options.mochaOptions = { 'no-config': true }; | ||
}); | ||
|
||
describe('issue #2720', () => { | ||
beforeEach(async () => { | ||
process.chdir(resolveTestResource('regression', 'issue-2720')); | ||
}); | ||
|
||
it('should have report correct failing test when "beforeEach" fails', async () => { | ||
// Arrange | ||
options.mochaOptions.spec = ['failing-before-each']; | ||
const sut = testInjector.injector.injectFunction(createMochaTestRunnerFactory('__stryker2__')); | ||
await sut.init(); | ||
|
||
// Act | ||
const result = await sut.dryRun(factory.dryRunOptions({})); | ||
|
||
// Assert | ||
assertions.expectCompleted(result); | ||
const expected: Partial<FailedTestResult> = { | ||
name: 'suite should fail in beforeEach', | ||
id: 'suite should fail in beforeEach', | ||
status: TestStatus.Failed, | ||
}; | ||
expect(result.tests).lengthOf(1); | ||
expect(result.tests[0]).deep.contains(expected); | ||
}); | ||
|
||
it('should have report correct failing test when "afterEach" fails', async () => { | ||
// Arrange | ||
options.mochaOptions.spec = ['failing-after-each']; | ||
const sut = testInjector.injector.injectFunction(createMochaTestRunnerFactory('__stryker2__')); | ||
await sut.init(); | ||
|
||
// Act | ||
const result = await sut.dryRun(factory.dryRunOptions({})); | ||
|
||
// Assert | ||
assertions.expectCompleted(result); | ||
const expected: Partial<FailedTestResult> = { | ||
name: 'suite2 should fail in afterEach', | ||
id: 'suite2 should fail in afterEach', | ||
status: TestStatus.Failed, | ||
}; | ||
expect(result.tests).lengthOf(2); | ||
expect(result.tests[1]).deep.contains(expected); | ||
}); | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
packages/mocha-runner/testResources/regression/issue-2720/failing-after-each.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,10 @@ | ||
describe('suite2', () => { | ||
|
||
afterEach(() => { | ||
throw new Error(); | ||
}); | ||
|
||
it('should fail in afterEach', () => { | ||
// idle | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
packages/mocha-runner/testResources/regression/issue-2720/failing-before-each.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,10 @@ | ||
describe('suite', () => { | ||
|
||
beforeEach(() => { | ||
throw new Error(); | ||
}); | ||
|
||
it('should fail in beforeEach', () => { | ||
// idle | ||
}); | ||
}); |