Skip to content

Commit 817c9b8

Browse files
committed
ISSUE-13112: Refactor onTestCaseStart hook calling to more stable and transparent approach
- clean previous approach - add `test_started` event to Circus runner - fix tests for `test_started` event
1 parent 4f1cae7 commit 817c9b8

File tree

13 files changed

+44
-41
lines changed

13 files changed

+44
-41
lines changed

e2e/__tests__/__snapshots__/customReportersOnCircus.test.ts.snap

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,11 @@ exports[`Custom Reporters Integration on jest-circus push test case results for
1515
onTestFileResult testCaseResult 0: sample, status: todo, numExpectations: 0"
1616
`;
1717

18-
exports[`Custom Reporters Integration on jest-circus push test case results for skip tests 1`] = `
19-
"onTestCaseResult: sample, status: pending, numExpectations: 0
20-
onTestFileResult testCaseResult 0: sample, status: pending, numExpectations: 0"
21-
`;
22-
2318
exports[`Custom Reporters Integration on jest-circus push test case start 1`] = `
2419
"onTestCaseStart: test 1, mode: undefined, ancestorTitles: Custom Reporters
25-
onTestCaseResult: test 1, status: passed
26-
onTestCaseStart: test 2, mode: undefined, ancestorTitles: Custom Reporters
27-
onTestCaseResult: test 2, status: passed"
20+
onTestCaseStart: test 2, mode: undefined, ancestorTitles: Custom Reporters"
2821
`;
2922

30-
exports[`Custom Reporters Integration on jest-circus push test case start for todo tests 1`] = `
31-
"onTestCaseStart: sample, mode: todo, ancestorTitles: Custom Reporters
32-
onTestCaseResult: sample, status: todo"
33-
`;
23+
exports[`Custom Reporters Integration on jest-circus doesn't push test case start for skip tests 1`] = `""`;
3424

35-
exports[`Custom Reporters Integration on jest-circus push test case start for skip tests 1`] = `
36-
"onTestCaseStart: sample, mode: skip, ancestorTitles: Custom Reporters
37-
onTestCaseResult: sample, status: pending"
38-
`;
25+
exports[`Custom Reporters Integration on jest-circus doesn't push test case start for todo tests 1`] = `""`;

e2e/__tests__/customReportersOnCircus.test.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,6 @@ describe('Custom Reporters Integration on jest-circus', () => {
5555
expect(stdout).toMatchSnapshot();
5656
});
5757

58-
test('push test case results for skip tests', () => {
59-
const {stdout} = runJest('custom-reporters', [
60-
'--config',
61-
JSON.stringify({
62-
reporters: [
63-
'default',
64-
'<rootDir>/reporters/AssertionCountsReporter.js',
65-
],
66-
}),
67-
'skip.test.js',
68-
]);
69-
70-
expect(stdout).toMatchSnapshot();
71-
});
72-
7358
test('push test case start', () => {
7459
const {stdout} = runJest('custom-reporters', [
7560
'--config',
@@ -82,7 +67,7 @@ describe('Custom Reporters Integration on jest-circus', () => {
8267
expect(stdout).toMatchSnapshot();
8368
});
8469

85-
test('push test case start for todo tests', () => {
70+
test("doesn't push test case start for todo tests", () => {
8671
const {stdout} = runJest('custom-reporters', [
8772
'--config',
8873
JSON.stringify({
@@ -94,7 +79,7 @@ describe('Custom Reporters Integration on jest-circus', () => {
9479
expect(stdout).toMatchSnapshot();
9580
});
9681

97-
test('push test case start for skip tests', () => {
82+
test("doesn't push test case start for skip tests", () => {
9883
const {stdout} = runJest('custom-reporters', [
9984
'--config',
10085
JSON.stringify({

e2e/__tests__/testEnvironmentCircus.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ it('calls testEnvironment handleTestEvent', () => {
2323
"run_start",
2424
"run_describe_start",
2525
"test_start: test name here",
26+
"test_started: test name here",
2627
"hook_start",
2728
"hook_success: test name here",
2829
"hook_start",
@@ -31,6 +32,7 @@ it('calls testEnvironment handleTestEvent', () => {
3132
"test_fn_success: test name here",
3233
"test_done: test name here",
3334
"test_start: second test name here",
35+
"test_started: second test name here",
3436
"hook_start",
3537
"hook_success: second test name here",
3638
"hook_start",

e2e/__tests__/testEnvironmentCircusAsync.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ it('calls asynchronous handleTestEvent in testEnvironment', () => {
3636
"run_describe_start",
3737
"run_describe_start",
3838
"test_start: passing test",
39+
"test_started: passing test",
3940
"hook_start: beforeEach",
4041
"hook_success: beforeEach",
4142
"hook_start: beforeEach",
@@ -46,6 +47,7 @@ it('calls asynchronous handleTestEvent in testEnvironment', () => {
4647
"hook_failure: afterEach",
4748
"test_done: passing test",
4849
"test_start: failing test",
50+
"test_started: failing test",
4951
"hook_start: beforeEach",
5052
"hook_success: beforeEach",
5153
"hook_start: beforeEach",

e2e/custom-reporters/reporters/TestCaseStartReporter.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ class TestCaseStartReporter {
2121
`ancestorTitles: ${testCaseStartInfo.ancestorTitles.join('.')}`,
2222
);
2323
}
24-
onTestCaseResult(test, testCaseResult) {
25-
console.log(
26-
`onTestCaseResult: ${testCaseResult.title}, ` +
27-
`status: ${testCaseResult.status}`,
28-
);
29-
}
3024
}
3125

3226
module.exports = TestCaseStartReporter;

packages/jest-circus/src/__mocks__/testEventHandler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const testEventHandler: Circus.EventHandler = (event, state) => {
2020
break;
2121
}
2222
case 'test_start':
23+
case 'test_started':
2324
case 'test_retry':
2425
case 'test_done': {
2526
console.log(`${event.name}:`, event.test.name);

packages/jest-circus/src/__tests__/__snapshots__/afterAll.test.ts.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ hook_start: beforeAll
5454
hook_success: beforeAll
5555
run_describe_start: child describe
5656
test_start: my test
57+
test_started: my test
5758
hook_start: beforeEach
5859
> beforeEach
5960
hook_success: beforeEach
@@ -132,24 +133,29 @@ run_start
132133
run_describe_start: ROOT_DESCRIBE_BLOCK
133134
run_describe_start: describe
134135
test_start: one
136+
test_started: one
135137
test_fn_start: one
136138
test_fn_success: one
137139
test_done: one
138140
test_start: two
141+
test_started: two
139142
test_fn_start: two
140143
test_fn_success: two
141144
test_done: two
142145
run_describe_start: 2nd level describe
143146
test_start: 2nd level test
147+
test_started: 2nd level test
144148
test_fn_start: 2nd level test
145149
test_fn_success: 2nd level test
146150
test_done: 2nd level test
147151
run_describe_start: 3rd level describe
148152
test_start: 3rd level test
153+
test_started: 3rd level test
149154
test_fn_start: 3rd level test
150155
test_fn_success: 3rd level test
151156
test_done: 3rd level test
152157
test_start: 3rd level test#2
158+
test_started: 3rd level test#2
153159
test_fn_start: 3rd level test#2
154160
test_fn_success: 3rd level test#2
155161
test_done: 3rd level test#2
@@ -162,6 +168,7 @@ hook_success: afterAll
162168
run_describe_finish: describe
163169
run_describe_start: 2nd describe
164170
test_start: 2nd describe test
171+
test_started: 2nd describe test
165172
test_fn_start: 2nd describe test
166173
test_fn_success: 2nd describe test
167174
test_done: 2nd describe test

packages/jest-circus/src/__tests__/__snapshots__/baseTest.test.ts.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ run_start
1111
run_describe_start: ROOT_DESCRIBE_BLOCK
1212
run_describe_start: describe
1313
test_start: one
14+
test_started: one
1415
hook_start: beforeEach
1516
hook_success: beforeEach
1617
test_fn_start: one
@@ -19,6 +20,7 @@ hook_start: afterEach
1920
hook_failure: afterEach
2021
test_done: one
2122
test_start: two
23+
test_started: two
2224
hook_start: beforeEach
2325
hook_success: beforeEach
2426
test_fn_start: two
@@ -41,6 +43,7 @@ run_start
4143
run_describe_start: ROOT_DESCRIBE_BLOCK
4244
run_describe_start: describer
4345
test_start: One
46+
test_started: One
4447
test_fn_start: One
4548
test_fn_success: One
4649
test_done: One
@@ -62,6 +65,7 @@ run_start
6265
run_describe_start: ROOT_DESCRIBE_BLOCK
6366
run_describe_start: describe
6467
test_start: one
68+
test_started: one
6569
hook_start: beforeEach
6670
hook_success: beforeEach
6771
test_fn_start: one
@@ -70,6 +74,7 @@ hook_start: afterEach
7074
hook_success: afterEach
7175
test_done: one
7276
test_start: two
77+
test_started: two
7378
hook_start: beforeEach
7479
hook_success: beforeEach
7580
test_fn_start: two

packages/jest-circus/src/__tests__/__snapshots__/hooks.test.ts.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ hook_start: beforeAll
1717
> beforeAll 1
1818
hook_success: beforeAll
1919
test_start: test 1
20+
test_started: test 1
2021
test_fn_start: test 1
2122
> test 1
2223
test_fn_success: test 1
@@ -26,11 +27,13 @@ hook_start: beforeAll
2627
> beforeAll 2
2728
hook_success: beforeAll
2829
test_start: test 2
30+
test_started: test 2
2931
test_fn_start: test 2
3032
> test 2
3133
test_fn_success: test 2
3234
test_done: test 2
3335
test_start: test 3
36+
test_started: test 3
3437
test_fn_start: test 3
3538
> test 3
3639
test_fn_success: test 3
@@ -65,13 +68,15 @@ run_start
6568
run_describe_start: ROOT_DESCRIBE_BLOCK
6669
run_describe_start: describe
6770
test_start: one
71+
test_started: one
6872
hook_start: beforeEach
6973
> describe beforeEach
7074
hook_success: beforeEach
7175
test_fn_start: one
7276
test_fn_success: one
7377
test_done: one
7478
test_start: two
79+
test_started: two
7580
hook_start: beforeEach
7681
> describe beforeEach
7782
hook_success: beforeEach
@@ -80,6 +85,7 @@ test_fn_success: two
8085
test_done: two
8186
run_describe_start: 2nd level describe
8287
test_start: 2nd level test
88+
test_started: 2nd level test
8389
hook_start: beforeEach
8490
> describe beforeEach
8591
hook_success: beforeEach
@@ -91,6 +97,7 @@ test_fn_success: 2nd level test
9197
test_done: 2nd level test
9298
run_describe_start: 3rd level describe
9399
test_start: 3rd level test
100+
test_started: 3rd level test
94101
hook_start: beforeEach
95102
> describe beforeEach
96103
hook_success: beforeEach
@@ -101,6 +108,7 @@ test_fn_start: 3rd level test
101108
test_fn_success: 3rd level test
102109
test_done: 3rd level test
103110
test_start: 3rd level test#2
111+
test_started: 3rd level test#2
104112
hook_start: beforeEach
105113
> describe beforeEach
106114
hook_success: beforeEach
@@ -115,6 +123,7 @@ run_describe_finish: 2nd level describe
115123
run_describe_finish: describe
116124
run_describe_start: 2nd describe
117125
test_start: 2nd describe test
126+
test_started: 2nd describe test
118127
hook_start: beforeEach
119128
> 2nd describe beforeEach that throws
120129
hook_failure: beforeEach
@@ -140,6 +149,7 @@ run_describe_start: ROOT_DESCRIBE_BLOCK
140149
run_describe_start: describe 1
141150
run_describe_start: 2nd level describe
142151
test_start: test
152+
test_started: test
143153
hook_start: beforeEach
144154
before each 1
145155
hook_success: beforeEach

packages/jest-circus/src/__tests__/__snapshots__/randomizeTest.test.ts.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ run_start
1111
run_describe_start: ROOT_DESCRIBE_BLOCK
1212
run_describe_start: describe
1313
test_start: one
14+
test_started: one
1415
hook_start: beforeEach
1516
hook_success: beforeEach
1617
test_fn_start: one
@@ -19,6 +20,7 @@ hook_start: afterEach
1920
hook_failure: afterEach
2021
test_done: one
2122
test_start: two
23+
test_started: two
2224
hook_start: beforeEach
2325
hook_success: beforeEach
2426
test_fn_start: two
@@ -41,6 +43,7 @@ run_start
4143
run_describe_start: ROOT_DESCRIBE_BLOCK
4244
run_describe_start: describer
4345
test_start: One
46+
test_started: One
4447
test_fn_start: One
4548
test_fn_success: One
4649
test_done: One
@@ -62,6 +65,7 @@ run_start
6265
run_describe_start: ROOT_DESCRIBE_BLOCK
6366
run_describe_start: describe
6467
test_start: one
68+
test_started: one
6569
hook_start: beforeEach
6670
hook_success: beforeEach
6771
test_fn_start: one
@@ -70,6 +74,7 @@ hook_start: afterEach
7074
hook_success: afterEach
7175
test_done: one
7276
test_start: two
77+
test_started: two
7378
hook_start: beforeEach
7479
hook_success: beforeEach
7580
test_fn_start: two

0 commit comments

Comments
 (0)