Skip to content

Commit

Permalink
Modify reporter to include test invocation count. Add Tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
palmerj3 committed Jun 20, 2018
1 parent fb1422e commit 226e60f
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ run_start
run_describe_start: ROOT_DESCRIBE_BLOCK
run_describe_start: describe
run_describe_start: child describe
Invocations: 1
test_start: my test
hook_start: beforeEach
hook_success: beforeEach
Expand Down Expand Up @@ -68,24 +69,29 @@ finish_describe_definition: 2nd describe
run_start
run_describe_start: ROOT_DESCRIBE_BLOCK
run_describe_start: describe
Invocations: 1
test_start: one
test_fn_start: one
test_fn_success: one
test_done: one
Invocations: 1
test_start: two
test_fn_start: two
test_fn_success: two
test_done: two
run_describe_start: 2nd level describe
Invocations: 1
test_start: 2nd level test
test_fn_start: 2nd level test
test_fn_success: 2nd level test
test_done: 2nd level test
run_describe_start: 3rd level describe
Invocations: 1
test_start: 3rd level test
test_fn_start: 3rd level test
test_fn_success: 3rd level test
test_done: 3rd level test
Invocations: 1
test_start: 3rd level test#2
test_fn_start: 3rd level test#2
test_fn_success: 3rd level test#2
Expand All @@ -98,6 +104,7 @@ hook_start: afterAll
hook_success: afterAll
run_describe_finish: describe
run_describe_start: 2nd describe
Invocations: 1
test_start: 2nd describe test
test_fn_start: 2nd describe test
test_fn_success: 2nd describe test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ finish_describe_definition: describe
run_start
run_describe_start: ROOT_DESCRIBE_BLOCK
run_describe_start: describe
Invocations: 1
test_start: one
hook_start: beforeEach
hook_success: beforeEach
Expand All @@ -18,6 +19,7 @@ test_fn_failure: one
hook_start: afterEach
hook_failure: afterEach
test_done: one
Invocations: 1
test_start: two
hook_start: beforeEach
hook_success: beforeEach
Expand All @@ -43,6 +45,7 @@ finish_describe_definition: describe
run_start
run_describe_start: ROOT_DESCRIBE_BLOCK
run_describe_start: describe
Invocations: 1
test_start: one
hook_start: beforeEach
hook_success: beforeEach
Expand All @@ -51,6 +54,7 @@ test_fn_success: one
hook_start: afterEach
hook_success: afterEach
test_done: one
Invocations: 1
test_start: two
hook_start: beforeEach
hook_success: beforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@ finish_describe_definition: 2nd describe
run_start
run_describe_start: ROOT_DESCRIBE_BLOCK
run_describe_start: describe
Invocations: 1
test_start: one
hook_start: beforeEach
hook_success: beforeEach
test_fn_start: one
test_fn_success: one
test_done: one
Invocations: 1
test_start: two
hook_start: beforeEach
hook_success: beforeEach
test_fn_start: two
test_fn_success: two
test_done: two
run_describe_start: 2nd level describe
Invocations: 1
test_start: 2nd level test
hook_start: beforeEach
hook_success: beforeEach
Expand All @@ -43,6 +46,7 @@ test_fn_start: 2nd level test
test_fn_success: 2nd level test
test_done: 2nd level test
run_describe_start: 3rd level describe
Invocations: 1
test_start: 3rd level test
hook_start: beforeEach
hook_success: beforeEach
Expand All @@ -51,6 +55,7 @@ hook_success: beforeEach
test_fn_start: 3rd level test
test_fn_success: 3rd level test
test_done: 3rd level test
Invocations: 1
test_start: 3rd level test#2
hook_start: beforeEach
hook_success: beforeEach
Expand All @@ -63,6 +68,7 @@ run_describe_finish: 3rd level describe
run_describe_finish: 2nd level describe
run_describe_finish: describe
run_describe_start: 2nd describe
Invocations: 1
test_start: 2nd describe test
hook_start: beforeEach
hook_failure: beforeEach
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-circus/src/event_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ const handler: EventHandler = (event, state): void => {
case 'test_start': {
state.currentlyRunningTest = event.test;
event.test.startedAt = Date.now();
event.test.invocations += 1;
console.log('Invocations:', event.test.invocations);
break;
}
case 'test_fn_failure': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export const runAndTransformResultsToJestFormat = async ({
duration: testResult.duration,
failureMessages: testResult.errors,
fullName: ancestorTitles.concat(title).join(' '),
invocations: testResult.invocations,
location: testResult.location,
numPassingAsserts: 0,
status,
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-circus/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const makeTest = (
duration: null,
errors: [],
fn,
invocations: 0,
mode: _mode,
name: convertDescriptorToString(name),
parent,
Expand Down Expand Up @@ -279,6 +280,7 @@ const makeTestResults = (describeBlock: DescribeBlock, config): TestResults => {
testResults.push({
duration: test.duration,
errors: test.errors.map(_formatError),
invocations: test.invocations,
location,
status,
testPath,
Expand Down
7 changes: 7 additions & 0 deletions packages/jest-cli/src/__tests__/cli/args.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ describe('check', () => {
);
});

it('raises an exception if testRetries is specified with no number', () => {
const argv: Argv = {testRetries: undefined};
expect(() => check(argv)).toThrow(
'The --testRetries option requires a positive integer to be specified.',
);
});

it('raises an exception if config is not a valid JSON string', () => {
const argv: Argv = {config: 'x:1'};
expect(() => check(argv)).toThrow(
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-cli/src/cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ export const check = (argv: Argv) => {
intRetries < 0
) {
throw new Error(
'The --testRetries option requires a positive integer to be specified.\n' +
'Example usage: jest --testRetries=3',
'The --testRetries option requires a positive integer to be specified.',
);
}

Expand Down
2 changes: 2 additions & 0 deletions types/Circus.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export type TestStatus = 'skip' | 'done';
export type TestResult = {|
duration: ?number,
errors: Array<FormattedError>,
invocations: ?number,
status: TestStatus,
location: ?{|column: number, line: number|},
testPath: Array<TestName | BlockName>,
Expand Down Expand Up @@ -194,6 +195,7 @@ export type TestEntry = {|
asyncError: Exception, // Used if the test failure contains no usable stack trace
errors: TestError,
fn: ?TestFn,
invocations: ?number, // number of times test was run (includes retries)
mode: TestMode,
name: TestName,
parent: DescribeBlock,
Expand Down

0 comments on commit 226e60f

Please sign in to comment.