Skip to content

Commit

Permalink
fix: flaky test count (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
devpow112 authored Jan 11, 2024
1 parent d4c8e21 commit aa10496
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 13 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"test:all": "run-s test:unit test:integration",
"test:unit": "mocha test/unit/**/*.test.js",
"test:integration": "run-s test:integration:mocha test:integration:playwright",
"test:integration:mocha": "mocha --config test/integration/configs/mocha.cjs",
"test:integration:playwright": "playwright test --config test/integration/configs/playwright.js",
"test:integration:mocha": "mocha --config test/integration/configs/mocha.cjs || exit 0",
"test:integration:playwright": "playwright test --config test/integration/configs/playwright.js || exit 0",
"test:coverage": "c8 npm run test:all"
},
"engines": {
Expand Down
8 changes: 6 additions & 2 deletions src/reporters/mocha.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class TestReportingMochaReporter extends Spec {

values.started = values.started ?? (new Date()).toISOString();
values.location = values.location ?? makeLocation(test.file);
values.retries = values.retries === undefined ? 0 : values.retries + 1;
values.retries = values.retries ?? 0;
values.totalDuration = values.totalDuration ?? 0;

this._tests.set(name, values);
Expand All @@ -100,9 +100,9 @@ class TestReportingMochaReporter extends Spec {
const values = this._tests.get(name);

values.totalDuration += test.duration;
values.retries += 1;

this._tests.set(name, values);
this._testsFlaky.add(name);
}

_onTestEnd(test) {
Expand All @@ -114,6 +114,10 @@ class TestReportingMochaReporter extends Spec {
values.totalDuration += values.duration;

this._tests.set(name, values);

if (values.status === 'passed' && values.retries !== 0) {
this._testsFlaky.add(name);
}
}

_onRunEnd(stats) {
Expand Down
8 changes: 4 additions & 4 deletions src/reporters/playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ export default class Reporter {

if (values.status === 'passed') {
countPassed++;

if (values.retries !== 0) {
countFlaky++;
}
} else if (values.status === 'failed') {
countFailed++;
} else if (values.status === 'skipped') {
countSkipped++;
}

if (values.retries !== 0) {
countFlaky++;
}

return { ...values };
});

Expand Down
8 changes: 5 additions & 3 deletions test/integration/mocha-1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const delay = () => {
describe('reporter tests 1', () => {
let count = 0;

it('test', () => {});
it('test', () => { });

it.skip('skipped test', () => {});
it.skip('skipped test', () => { });

it('flaky test', async() => {
it('flaky test that succeeds eventually', async() => {
if (count < 2) {
await delay();

Expand All @@ -18,4 +18,6 @@ describe('reporter tests 1', () => {
throw new Error('flaky test failure');
}
});

it('failed test', () => { throw new Error('fail'); });
});
6 changes: 4 additions & 2 deletions test/integration/mocha-2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const delay = () => {
describe('reporter tests 2', () => {
let count = 0;

it('test', () => {});
it('test', () => { });

it.skip('skipped test', () => {});
it.skip('skipped test', () => { });

it('flaky test', async() => {
if (count < 2) {
Expand All @@ -18,4 +18,6 @@ describe('reporter tests 2', () => {
throw new Error('flaky test failure');
}
});

it('failed test', () => { throw new Error('fail'); });
});
2 changes: 2 additions & 0 deletions test/integration/playwright-1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ test.describe('reporter tests 1', () => {
throw new Error('flaky test failure');
}
});

test('failed test', () => { throw new Error('fail'); });
});
2 changes: 2 additions & 0 deletions test/integration/playwright-2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ test.describe('reporter tests 2', () => {
throw new Error('flaky test failure');
}
});

test('failed test', () => { throw new Error('fail'); });
});

0 comments on commit aa10496

Please sign in to comment.