Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mocha-runner: Add support for test's fileName #3504

Merged
merged 5 commits into from
Jun 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/test/reporters-e2e/verify/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('Verify stryker has ran correctly', () => {
});
});
});
const createTestsRegex = () => /All tests\s*✓ Add should be able to add two numbers \(killed 2\)/;
const createTestsRegex = () => /All tests\s*AddSpec\.js\s*\s*✓ Add should be able to add two numbers \(killed 2\)/;
const createNoCoverageMutantRegex = () => /#6\.\s*\[NoCoverage\]/;
const createSurvivedMutantRegex = () => /#20\.\s*\[Survived\]/;
const createClearTextTableSummaryRowRegex = () => /All files\s*\|\s*64\.00\s*\|\s*16\s*\|\s*0\s*\|\s*1\s*\|\s*8\s*\|\s*0\s*\|/;
1 change: 1 addition & 0 deletions packages/mocha-runner/src/stryker-mocha-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class StrykerMochaReporter {
name: title,
status: TestStatus.Success,
timeSpentMs: this.timer.elapsedMs(),
fileName: test.file,
};
this.tests.push(result);
this.passedCount++;
Expand Down
24 changes: 14 additions & 10 deletions packages/mocha-runner/test/integration/sample-project.it.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ describe('Running a sample project', () => {
});

afterEach(async () => {
if (sut) {
await sut.dispose();
}
await sandbox.dispose();
});

Expand All @@ -40,9 +43,6 @@ describe('Running a sample project', () => {
await sut.init();
});

afterEach(async () => {
await sut.dispose();
});
it('should report completed tests', async () => {
const runResult = await sut.dryRun(factory.dryRunOptions());
assertions.expectCompleted(runResult);
Expand All @@ -51,6 +51,17 @@ describe('Running a sample project', () => {
runResult.tests.forEach((t) => expect(t.timeSpentMs).to.be.greaterThan(-1).and.to.be.lessThan(1000));
});

it('should report test files', async () => {
const specFileName = resolveTestFile('MyMathSpec.js');
const runResult = await sut.dryRun(factory.dryRunOptions());
assertions.expectCompleted(runResult);
expect(runResult.tests[0].fileName).eq(specFileName);
expect(runResult.tests[1].fileName).eq(specFileName);
expect(runResult.tests[2].fileName).eq(specFileName);
expect(runResult.tests[3].fileName).eq(specFileName);
expect(runResult.tests[4].fileName).eq(specFileName);
});

it('should be able to run 2 times in a row', async () => {
await sut.dryRun(factory.dryRunOptions());
const runResult = await sut.dryRun(factory.dryRunOptions());
Expand All @@ -66,9 +77,6 @@ describe('Running a sample project', () => {
sut = createSut();
return sut.init();
});
afterEach(async () => {
await sut.dispose();
});

it('should only report the first failure (bail)', async () => {
const runResult = await sut.dryRun(factory.dryRunOptions());
Expand All @@ -90,10 +98,6 @@ describe('Running a sample project', () => {
sut = createSut();
return sut.init();
});

afterEach(async () => {
await sut.dispose();
});
it('should report no completed tests', async () => {
const runResult = await sut.dryRun(factory.dryRunOptions());
assertions.expectCompleted(runResult);
Expand Down