Skip to content

Commit 226e60f

Browse files
committed
Modify reporter to include test invocation count. Add Tests.
1 parent fb1422e commit 226e60f

File tree

9 files changed

+32
-2
lines changed

9 files changed

+32
-2
lines changed

packages/jest-circus/src/__tests__/__snapshots__/after_all.test.js.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ run_start
1414
run_describe_start: ROOT_DESCRIBE_BLOCK
1515
run_describe_start: describe
1616
run_describe_start: child describe
17+
Invocations: 1
1718
test_start: my test
1819
hook_start: beforeEach
1920
hook_success: beforeEach
@@ -68,24 +69,29 @@ finish_describe_definition: 2nd describe
6869
run_start
6970
run_describe_start: ROOT_DESCRIBE_BLOCK
7071
run_describe_start: describe
72+
Invocations: 1
7173
test_start: one
7274
test_fn_start: one
7375
test_fn_success: one
7476
test_done: one
77+
Invocations: 1
7578
test_start: two
7679
test_fn_start: two
7780
test_fn_success: two
7881
test_done: two
7982
run_describe_start: 2nd level describe
83+
Invocations: 1
8084
test_start: 2nd level test
8185
test_fn_start: 2nd level test
8286
test_fn_success: 2nd level test
8387
test_done: 2nd level test
8488
run_describe_start: 3rd level describe
89+
Invocations: 1
8590
test_start: 3rd level test
8691
test_fn_start: 3rd level test
8792
test_fn_success: 3rd level test
8893
test_done: 3rd level test
94+
Invocations: 1
8995
test_start: 3rd level test#2
9096
test_fn_start: 3rd level test#2
9197
test_fn_success: 3rd level test#2
@@ -98,6 +104,7 @@ hook_start: afterAll
98104
hook_success: afterAll
99105
run_describe_finish: describe
100106
run_describe_start: 2nd describe
107+
Invocations: 1
101108
test_start: 2nd describe test
102109
test_fn_start: 2nd describe test
103110
test_fn_success: 2nd describe test

packages/jest-circus/src/__tests__/__snapshots__/base_test.test.js.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ finish_describe_definition: describe
1010
run_start
1111
run_describe_start: ROOT_DESCRIBE_BLOCK
1212
run_describe_start: describe
13+
Invocations: 1
1314
test_start: one
1415
hook_start: beforeEach
1516
hook_success: beforeEach
@@ -18,6 +19,7 @@ test_fn_failure: one
1819
hook_start: afterEach
1920
hook_failure: afterEach
2021
test_done: one
22+
Invocations: 1
2123
test_start: two
2224
hook_start: beforeEach
2325
hook_success: beforeEach
@@ -43,6 +45,7 @@ finish_describe_definition: describe
4345
run_start
4446
run_describe_start: ROOT_DESCRIBE_BLOCK
4547
run_describe_start: describe
48+
Invocations: 1
4649
test_start: one
4750
hook_start: beforeEach
4851
hook_success: beforeEach
@@ -51,6 +54,7 @@ test_fn_success: one
5154
hook_start: afterEach
5255
hook_success: afterEach
5356
test_done: one
57+
Invocations: 1
5458
test_start: two
5559
hook_start: beforeEach
5660
hook_success: beforeEach

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,22 @@ finish_describe_definition: 2nd describe
2121
run_start
2222
run_describe_start: ROOT_DESCRIBE_BLOCK
2323
run_describe_start: describe
24+
Invocations: 1
2425
test_start: one
2526
hook_start: beforeEach
2627
hook_success: beforeEach
2728
test_fn_start: one
2829
test_fn_success: one
2930
test_done: one
31+
Invocations: 1
3032
test_start: two
3133
hook_start: beforeEach
3234
hook_success: beforeEach
3335
test_fn_start: two
3436
test_fn_success: two
3537
test_done: two
3638
run_describe_start: 2nd level describe
39+
Invocations: 1
3740
test_start: 2nd level test
3841
hook_start: beforeEach
3942
hook_success: beforeEach
@@ -43,6 +46,7 @@ test_fn_start: 2nd level test
4346
test_fn_success: 2nd level test
4447
test_done: 2nd level test
4548
run_describe_start: 3rd level describe
49+
Invocations: 1
4650
test_start: 3rd level test
4751
hook_start: beforeEach
4852
hook_success: beforeEach
@@ -51,6 +55,7 @@ hook_success: beforeEach
5155
test_fn_start: 3rd level test
5256
test_fn_success: 3rd level test
5357
test_done: 3rd level test
58+
Invocations: 1
5459
test_start: 3rd level test#2
5560
hook_start: beforeEach
5661
hook_success: beforeEach
@@ -63,6 +68,7 @@ run_describe_finish: 3rd level describe
6368
run_describe_finish: 2nd level describe
6469
run_describe_finish: describe
6570
run_describe_start: 2nd describe
71+
Invocations: 1
6672
test_start: 2nd describe test
6773
hook_start: beforeEach
6874
hook_failure: beforeEach

packages/jest-circus/src/event_handler.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ const handler: EventHandler = (event, state): void => {
114114
case 'test_start': {
115115
state.currentlyRunningTest = event.test;
116116
event.test.startedAt = Date.now();
117+
event.test.invocations += 1;
118+
console.log('Invocations:', event.test.invocations);
117119
break;
118120
}
119121
case 'test_fn_failure': {

packages/jest-circus/src/legacy_code_todo_rewrite/jest_adapter_init.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export const runAndTransformResultsToJestFormat = async ({
137137
duration: testResult.duration,
138138
failureMessages: testResult.errors,
139139
fullName: ancestorTitles.concat(title).join(' '),
140+
invocations: testResult.invocations,
140141
location: testResult.location,
141142
numPassingAsserts: 0,
142143
status,

packages/jest-circus/src/utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export const makeTest = (
8080
duration: null,
8181
errors: [],
8282
fn,
83+
invocations: 0,
8384
mode: _mode,
8485
name: convertDescriptorToString(name),
8586
parent,
@@ -279,6 +280,7 @@ const makeTestResults = (describeBlock: DescribeBlock, config): TestResults => {
279280
testResults.push({
280281
duration: test.duration,
281282
errors: test.errors.map(_formatError),
283+
invocations: test.invocations,
282284
location,
283285
status,
284286
testPath,

packages/jest-cli/src/__tests__/cli/args.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ describe('check', () => {
5252
);
5353
});
5454

55+
it('raises an exception if testRetries is specified with no number', () => {
56+
const argv: Argv = {testRetries: undefined};
57+
expect(() => check(argv)).toThrow(
58+
'The --testRetries option requires a positive integer to be specified.',
59+
);
60+
});
61+
5562
it('raises an exception if config is not a valid JSON string', () => {
5663
const argv: Argv = {config: 'x:1'};
5764
expect(() => check(argv)).toThrow(

packages/jest-cli/src/cli/args.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ export const check = (argv: Argv) => {
5757
intRetries < 0
5858
) {
5959
throw new Error(
60-
'The --testRetries option requires a positive integer to be specified.\n' +
61-
'Example usage: jest --testRetries=3',
60+
'The --testRetries option requires a positive integer to be specified.',
6261
);
6362
}
6463

types/Circus.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export type TestStatus = 'skip' | 'done';
145145
export type TestResult = {|
146146
duration: ?number,
147147
errors: Array<FormattedError>,
148+
invocations: ?number,
148149
status: TestStatus,
149150
location: ?{|column: number, line: number|},
150151
testPath: Array<TestName | BlockName>,
@@ -194,6 +195,7 @@ export type TestEntry = {|
194195
asyncError: Exception, // Used if the test failure contains no usable stack trace
195196
errors: TestError,
196197
fn: ?TestFn,
198+
invocations: ?number, // number of times test was run (includes retries)
197199
mode: TestMode,
198200
name: TestName,
199201
parent: DescribeBlock,

0 commit comments

Comments
 (0)