Skip to content

Commit 8a23412

Browse files
committed
[test] Assertion counting
1 parent f92975b commit 8a23412

File tree

4 files changed

+34
-19
lines changed

4 files changed

+34
-19
lines changed

gulpfile.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ const test = async (
621621
'coverage.json',
622622
JSON.stringify({
623623
...(countAsserts
624-
? JSON.parse(await promises.readFile('./tmp/assertion-summary.json'))
624+
? JSON.parse(await promises.readFile('./tmp/counts.json'))
625625
: {}),
626626
...JSON.parse(await promises.readFile('./tmp/coverage-summary.json'))
627627
.total,
@@ -784,4 +784,4 @@ export const prePublishPackage = series(
784784
testE2e,
785785
);
786786

787-
export const publishPackage = series(prePublishPackage, npmPublish);
787+
export const publishPackage = series(prePublishPackage, npmPublish);

test/jest/environment.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import {writeFileSync} from 'fs';
12
import {TestEnvironment} from 'jest-environment-jsdom';
23
import {TextDecoder, TextEncoder} from 'util';
34
import {BroadcastChannel} from 'worker_threads';
45

5-
export default class extends TestEnvironment {
6-
static assertionCalls = 0;
6+
export default class TinyBaseEnvironment extends TestEnvironment {
7+
static tests = 0;
8+
static assertions = 0;
9+
710
async setup() {
811
Object.assign(this.global, {
912
TextDecoder,
@@ -18,4 +21,16 @@ export default class extends TestEnvironment {
1821
});
1922
await super.setup();
2023
}
24+
25+
async teardown() {
26+
writeFileSync(
27+
'./tmp/counts.json',
28+
JSON.stringify({
29+
tests: TinyBaseEnvironment.tests,
30+
assertions: TinyBaseEnvironment.assertions,
31+
}),
32+
'utf-8',
33+
);
34+
await super.teardown();
35+
}
2136
}

test/jest/reporter.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
import env from './environment.js';
2-
import {writeFileSync} from 'fs';
1+
import {readFileSync} from 'fs';
32

43
export default class {
5-
onRunComplete(_contexts, results) {
6-
writeFileSync(
7-
'./tmp/assertion-summary.json',
8-
JSON.stringify({
9-
tests: results.numTotalTests,
10-
assertions: env.assertionCalls,
11-
}),
12-
'utf-8',
13-
);
4+
onRunComplete() {
5+
const counts = JSON.parse(readFileSync('./tmp/counts.json', 'utf-8'));
146
// eslint-disable-next-line no-console
15-
console.log('Assertions:', env.assertionCalls, '\n');
7+
console.log(
8+
'Tests:',
9+
counts.tests,
10+
'\nAssertions:',
11+
counts.assertions,
12+
'\n',
13+
);
1614
}
1715
}

test/jest/setup.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
jest.retryTimes(10);
22

3-
afterEach(
4-
() => (global.env.assertionCalls += expect.getState().assertionCalls),
5-
);
3+
afterEach(() => {
4+
const {assertionCalls} = expect.getState();
5+
global.env.tests += 1;
6+
global.env.assertions += assertionCalls;
7+
});

0 commit comments

Comments
 (0)