Skip to content

Commit

Permalink
Merge branch 'main' into add-match-named-snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Jun 21, 2023
2 parents acb42b0 + 43b0ae8 commit f397e96
Show file tree
Hide file tree
Showing 35 changed files with 312 additions and 86 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Features

- `[jest-cli]` Include type definitions to generated config files ([#14078](https://github.com/facebook/jest/pull/14078))
- `[jest-core, jest-circus, jest-reporter, jest-runner]` Added support for reporting about start individual test cases using jest-circus ([#14174](https://github.com/jestjs/jest/pull/14174))
- `[jest-snapshot]` Support arrays as property matchers ([#14025](https://github.com/facebook/jest/pull/14025))
- `[jest-snapshot]` Add `toMatchNamedSnapshot` to bring snapshot support to concurrent mode ([#14045](https://github.com/facebook/jest/pull/14045))

Expand All @@ -15,6 +16,7 @@
- `[jest-mock]` Tweak typings to allow `jest.replaceProperty()` replace methods ([#14008](https://github.com/facebook/jest/pull/14008))
- `[jest-mock]` Improve user input validation and error messages of `spyOn` and `replaceProperty` methods ([#14087](https://github.com/facebook/jest/pull/14087))
- `[jest-runtime]` Bind `jest.isolateModulesAsync` to `this` ([#14083](https://github.com/facebook/jest/pull/14083))
- `[jest-runtime]` Forward `wrapperLength` to the `Script` constructor as `columnOffset` for accurate debugging ([#14148](https://github.com/facebook/jest/pull/14148))
- `[jest-snapshot]` Fix a potential bug when not using prettier and improve performance ([#14036](https://github.com/facebook/jest/pull/14036))
- `[@jest/transform]` Do not instrument `.json` modules ([#14048](https://github.com/facebook/jest/pull/14048))

Expand Down
6 changes: 3 additions & 3 deletions docs/SnapshotTesting.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ it('will fail every time', () => {

// Snapshot
exports[`will fail every time 1`] = `
Object {
{
"createdAt": 2018-05-19T23:36:09.816Z,
"id": 3,
"name": "LeBron James",
Expand All @@ -192,7 +192,7 @@ it('will check the matchers and pass', () => {

// Snapshot
exports[`will check the matchers and pass 1`] = `
Object {
{
"createdAt": Any<Date>,
"id": Any<Number>,
"name": "LeBron James",
Expand All @@ -217,7 +217,7 @@ it('will check the values and pass', () => {

// Snapshot
exports[`will check the values and pass 1`] = `
Object {
{
"createdAt": Any<Date>,
"name": 'Bond... James Bond',
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ exports[`Custom Reporters Integration on jest-circus push test case results for
"onTestCaseResult: sample, status: todo, numExpectations: 0
onTestFileResult testCaseResult 0: sample, status: todo, numExpectations: 0"
`;

exports[`Custom Reporters Integration on jest-circus push test case start 1`] = `
"onTestCaseStart: test 1, mode: undefined, ancestorTitles: Custom Reporters
onTestCaseStart: test 2, mode: undefined, ancestorTitles: Custom Reporters"
`;

exports[`Custom Reporters Integration on jest-circus doesn't push test case start for skip tests 1`] = `""`;

exports[`Custom Reporters Integration on jest-circus doesn't push test case start for todo tests 1`] = `""`;
4 changes: 2 additions & 2 deletions e2e/__tests__/__snapshots__/globals.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ exports[`cannot have describe with no implementation 1`] = `
Missing second argument. It must be a callback function.
> 1 | describe('describe, no implementation');
| ^
| ^
at Object.<anonymous> (__tests__/onlyConstructs.test.js:1:10)"
at Object.<anonymous> (__tests__/onlyConstructs.test.js:1:40)"
`;
exports[`cannot have describe with no implementation 2`] = `
Expand Down
36 changes: 36 additions & 0 deletions e2e/__tests__/customReportersOnCircus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,40 @@ describe('Custom Reporters Integration on jest-circus', () => {

expect(stdout).toMatchSnapshot();
});

test('push test case start', () => {
const {stdout} = runJest('custom-reporters', [
'--config',
JSON.stringify({
reporters: ['default', '<rootDir>/reporters/TestCaseStartReporter.js'],
}),
'just2Tests.test.js',
]);

expect(stdout).toMatchSnapshot();
});

test("doesn't push test case start for todo tests", () => {
const {stdout} = runJest('custom-reporters', [
'--config',
JSON.stringify({
reporters: ['default', '<rootDir>/reporters/TestCaseStartReporter.js'],
}),
'todo.test.js',
]);

expect(stdout).toMatchSnapshot();
});

test("doesn't push test case start for skip tests", () => {
const {stdout} = runJest('custom-reporters', [
'--config',
JSON.stringify({
reporters: ['default', '<rootDir>/reporters/TestCaseStartReporter.js'],
}),
'skip.test.js',
]);

expect(stdout).toMatchSnapshot();
});
});
2 changes: 2 additions & 0 deletions e2e/__tests__/testEnvironmentCircus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ it('calls testEnvironment handleTestEvent', () => {
"run_start",
"run_describe_start",
"test_start: test name here",
"test_started: test name here",
"hook_start",
"hook_success: test name here",
"hook_start",
Expand All @@ -31,6 +32,7 @@ it('calls testEnvironment handleTestEvent', () => {
"test_fn_success: test name here",
"test_done: test name here",
"test_start: second test name here",
"test_started: second test name here",
"hook_start",
"hook_success: second test name here",
"hook_start",
Expand Down
2 changes: 2 additions & 0 deletions e2e/__tests__/testEnvironmentCircusAsync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ it('calls asynchronous handleTestEvent in testEnvironment', () => {
"run_describe_start",
"run_describe_start",
"test_start: passing test",
"test_started: passing test",
"hook_start: beforeEach",
"hook_success: beforeEach",
"hook_start: beforeEach",
Expand All @@ -46,6 +47,7 @@ it('calls asynchronous handleTestEvent in testEnvironment', () => {
"hook_failure: afterEach",
"test_done: passing test",
"test_start: failing test",
"test_started: failing test",
"hook_start: beforeEach",
"hook_success: beforeEach",
"hook_start: beforeEach",
Expand Down
19 changes: 19 additions & 0 deletions e2e/custom-reporters/__tests__/just2Tests.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

'use strict';

describe('Custom Reporters', () => {
it('test 1', () => {
expect(true).toBeTruthy();
});

it('test 2', () => {
expect(true).toBeTruthy();
});
});
13 changes: 13 additions & 0 deletions e2e/custom-reporters/__tests__/skip.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

'use strict';

describe('Custom Reporters', () => {
it.skip('sample', () => {});
});
26 changes: 26 additions & 0 deletions e2e/custom-reporters/reporters/TestCaseStartReporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

/**
* @class
* @implements {import('@jest/reporters').Reporter}
*/
class TestCaseStartReporter {
onTestCaseStart(test, testCaseStartInfo) {
const mode =
testCaseStartInfo.mode != null ? testCaseStartInfo.mode : 'undefined';
console.log(
`onTestCaseStart: ${testCaseStartInfo.title}, ` +
`mode: ${mode}, ` +
`ancestorTitles: ${testCaseStartInfo.ancestorTitles.join('.')}`,
);
}
}

module.exports = TestCaseStartReporter;
1 change: 1 addition & 0 deletions packages/jest-circus/src/__mocks__/testEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const testEventHandler: Circus.EventHandler = (event, state) => {
break;
}
case 'test_start':
case 'test_started':
case 'test_retry':
case 'test_done': {
console.log(`${event.name}:`, event.test.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ hook_start: beforeAll
hook_success: beforeAll
run_describe_start: child describe
test_start: my test
test_started: my test
hook_start: beforeEach
> beforeEach
hook_success: beforeEach
Expand Down Expand Up @@ -132,24 +133,29 @@ run_start
run_describe_start: ROOT_DESCRIBE_BLOCK
run_describe_start: describe
test_start: one
test_started: one
test_fn_start: one
test_fn_success: one
test_done: one
test_start: two
test_started: two
test_fn_start: two
test_fn_success: two
test_done: two
run_describe_start: 2nd level describe
test_start: 2nd level test
test_started: 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
test_start: 3rd level test
test_started: 3rd level test
test_fn_start: 3rd level test
test_fn_success: 3rd level test
test_done: 3rd level test
test_start: 3rd level test#2
test_started: 3rd level test#2
test_fn_start: 3rd level test#2
test_fn_success: 3rd level test#2
test_done: 3rd level test#2
Expand All @@ -162,6 +168,7 @@ hook_success: afterAll
run_describe_finish: describe
run_describe_start: 2nd describe
test_start: 2nd describe test
test_started: 2nd describe test
test_fn_start: 2nd describe test
test_fn_success: 2nd describe test
test_done: 2nd describe test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ run_start
run_describe_start: ROOT_DESCRIBE_BLOCK
run_describe_start: describe
test_start: one
test_started: one
hook_start: beforeEach
hook_success: beforeEach
test_fn_start: one
Expand All @@ -19,6 +20,7 @@ hook_start: afterEach
hook_failure: afterEach
test_done: one
test_start: two
test_started: two
hook_start: beforeEach
hook_success: beforeEach
test_fn_start: two
Expand All @@ -41,6 +43,7 @@ run_start
run_describe_start: ROOT_DESCRIBE_BLOCK
run_describe_start: describer
test_start: One
test_started: One
test_fn_start: One
test_fn_success: One
test_done: One
Expand All @@ -62,6 +65,7 @@ run_start
run_describe_start: ROOT_DESCRIBE_BLOCK
run_describe_start: describe
test_start: one
test_started: one
hook_start: beforeEach
hook_success: beforeEach
test_fn_start: one
Expand All @@ -70,6 +74,7 @@ hook_start: afterEach
hook_success: afterEach
test_done: one
test_start: two
test_started: two
hook_start: beforeEach
hook_success: beforeEach
test_fn_start: two
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ hook_start: beforeAll
> beforeAll 1
hook_success: beforeAll
test_start: test 1
test_started: test 1
test_fn_start: test 1
> test 1
test_fn_success: test 1
Expand All @@ -26,11 +27,13 @@ hook_start: beforeAll
> beforeAll 2
hook_success: beforeAll
test_start: test 2
test_started: test 2
test_fn_start: test 2
> test 2
test_fn_success: test 2
test_done: test 2
test_start: test 3
test_started: test 3
test_fn_start: test 3
> test 3
test_fn_success: test 3
Expand Down Expand Up @@ -65,13 +68,15 @@ run_start
run_describe_start: ROOT_DESCRIBE_BLOCK
run_describe_start: describe
test_start: one
test_started: one
hook_start: beforeEach
> describe beforeEach
hook_success: beforeEach
test_fn_start: one
test_fn_success: one
test_done: one
test_start: two
test_started: two
hook_start: beforeEach
> describe beforeEach
hook_success: beforeEach
Expand All @@ -80,6 +85,7 @@ test_fn_success: two
test_done: two
run_describe_start: 2nd level describe
test_start: 2nd level test
test_started: 2nd level test
hook_start: beforeEach
> describe beforeEach
hook_success: beforeEach
Expand All @@ -91,6 +97,7 @@ test_fn_success: 2nd level test
test_done: 2nd level test
run_describe_start: 3rd level describe
test_start: 3rd level test
test_started: 3rd level test
hook_start: beforeEach
> describe beforeEach
hook_success: beforeEach
Expand All @@ -101,6 +108,7 @@ test_fn_start: 3rd level test
test_fn_success: 3rd level test
test_done: 3rd level test
test_start: 3rd level test#2
test_started: 3rd level test#2
hook_start: beforeEach
> describe beforeEach
hook_success: beforeEach
Expand All @@ -115,6 +123,7 @@ run_describe_finish: 2nd level describe
run_describe_finish: describe
run_describe_start: 2nd describe
test_start: 2nd describe test
test_started: 2nd describe test
hook_start: beforeEach
> 2nd describe beforeEach that throws
hook_failure: beforeEach
Expand All @@ -140,6 +149,7 @@ run_describe_start: ROOT_DESCRIBE_BLOCK
run_describe_start: describe 1
run_describe_start: 2nd level describe
test_start: test
test_started: test
hook_start: beforeEach
before each 1
hook_success: beforeEach
Expand Down
Loading

0 comments on commit f397e96

Please sign in to comment.