-
-
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(worker): handle circular messages
- Loading branch information
Showing
11 changed files
with
304 additions
and
12 deletions.
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
97 changes: 97 additions & 0 deletions
97
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,97 @@ | ||
// 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 | }); | ||
7 | | ||
8 | it('test 2', () => { | ||
at Object.toEqual (__tests__/test-1.js:5:15) | ||
● test 2 | ||
expect(received).toEqual(expected) // deep equality | ||
- Expected - 1 | ||
+ Received + 3 | ||
- Object {} | ||
+ Object { | ||
+ "ref": [Circular], | ||
+ } | ||
10 | foo.ref = foo; | ||
11 | | ||
> 12 | expect(foo).toEqual({}); | ||
| ^ | ||
13 | }); | ||
at Object.toEqual (__tests__/test-1.js:12: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 | }); | ||
7 | | ||
8 | it('test 2', () => { | ||
at Object.toEqual (__tests__/test-2.js:5:15) | ||
● test 2 | ||
expect(received).toEqual(expected) // deep equality | ||
- Expected - 1 | ||
+ Received + 3 | ||
- Object {} | ||
+ Object { | ||
+ "ref": [Circular], | ||
+ } | ||
10 | foo.ref = foo; | ||
11 | | ||
> 12 | expect(foo).toEqual({}); | ||
| ^ | ||
13 | }); | ||
at Object.toEqual (__tests__/test-2.js:12:15) | ||
`; | ||
|
||
exports[`handles circular inequality properly 2`] = ` | ||
Test Suites: 2 failed, 2 total | ||
Tests: 4 failed, 4 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,67 @@ | ||
/** | ||
* 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({}); | ||
}); | ||
it('test 2', () => { | ||
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}) => { | ||
return 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
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
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
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
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
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
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,34 @@ | ||
/** | ||
* 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 {parse as parseMessage, stringify} from 'telejson'; | ||
|
||
const customMessageStarter = 'jest string - '; | ||
|
||
export function serialize(data: unknown): unknown { | ||
if (data != null && typeof data === 'object') { | ||
// we only use stringify for the circular objects, not other features | ||
return `${customMessageStarter}${stringify(data, { | ||
allowClass: false, | ||
allowDate: false, | ||
allowFunction: false, | ||
allowRegExp: false, | ||
allowSymbol: false, | ||
allowUndefined: false, | ||
})}`; | ||
} | ||
|
||
return data; | ||
} | ||
|
||
export function parse(data: unknown): unknown { | ||
if (typeof data === 'string' && data.startsWith(customMessageStarter)) { | ||
return parseMessage(data.slice(customMessageStarter.length)); | ||
} | ||
|
||
return data; | ||
} |
Oops, something went wrong.