-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jest-runner): handle test failures with circular objects (#10981)
- Loading branch information
Showing
4 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
e2e/__tests__/__snapshots__/circularInequality.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`handles circular inequality properly 1`] = ` | ||
FAIL __tests__/test-1.js | ||
● test | ||
expect(received).toEqual(expected) // deep equality | ||
- Expected - 1 | ||
+ Received + 3 | ||
- Object {} | ||
+ Object { | ||
+ "ref": [Circular], | ||
+ } | ||
3 | foo.ref = foo; | ||
4 | | ||
> 5 | expect(foo).toEqual({}); | ||
| ^ | ||
6 | }); | ||
at Object.toEqual (__tests__/test-1.js:5:15) | ||
FAIL __tests__/test-2.js | ||
● test | ||
expect(received).toEqual(expected) // deep equality | ||
- Expected - 1 | ||
+ Received + 3 | ||
- Object {} | ||
+ Object { | ||
+ "ref": [Circular], | ||
+ } | ||
3 | foo.ref = foo; | ||
4 | | ||
> 5 | expect(foo).toEqual({}); | ||
| ^ | ||
6 | }); | ||
at Object.toEqual (__tests__/test-2.js:5:15) | ||
`; | ||
|
||
exports[`handles circular inequality properly 2`] = ` | ||
Test Suites: 2 failed, 2 total | ||
Tests: 2 failed, 2 total | ||
Snapshots: 0 total | ||
Time: <<REPLACED>> | ||
Ran all test suites. | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {tmpdir} from 'os'; | ||
import * as path from 'path'; | ||
import {wrap} from 'jest-snapshot-serializer-raw'; | ||
import { | ||
cleanup, | ||
createEmptyPackage, | ||
extractSortedSummary, | ||
writeFiles, | ||
} from '../Utils'; | ||
import {runContinuous} from '../runJest'; | ||
|
||
const tempDir = path.resolve(tmpdir(), 'circular-inequality-test'); | ||
|
||
beforeEach(() => { | ||
createEmptyPackage(tempDir); | ||
}); | ||
|
||
afterEach(() => { | ||
cleanup(tempDir); | ||
}); | ||
|
||
test('handles circular inequality properly', async () => { | ||
const testFileContent = ` | ||
it('test', () => { | ||
const foo = {}; | ||
foo.ref = foo; | ||
expect(foo).toEqual({}); | ||
}); | ||
`; | ||
|
||
writeFiles(tempDir, { | ||
'__tests__/test-1.js': testFileContent, | ||
'__tests__/test-2.js': testFileContent, | ||
}); | ||
|
||
const {end, waitUntil} = runContinuous( | ||
tempDir, | ||
['--no-watchman', '--watch-all'], | ||
// timeout in case the `waitUntil` below doesn't fire | ||
{stripAnsi: true, timeout: 5000}, | ||
); | ||
|
||
await waitUntil(({stderr}) => stderr.includes('Ran all test suites.')); | ||
|
||
const {stderr} = await end(); | ||
|
||
const {summary, rest} = extractSortedSummary(stderr); | ||
expect(wrap(rest)).toMatchSnapshot(); | ||
expect(wrap(summary)).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters