Skip to content

Commit afea019

Browse files
authored
Merge branch 'master' into wait-for-closed-resources-to-actually-close
2 parents 2ab6387 + 27bee72 commit afea019

File tree

6 files changed

+67
-6
lines changed

6 files changed

+67
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
- `[jest-runtime]` Detect reexports from CJS as named exports in ESM ([#10988](https://github.com/facebook/jest/pull/10988))
3737
- `[jest-runtime]` Support for async code transformations ([#11191](https://github.com/facebook/jest/pull/11191) & [#11220](https://github.com/facebook/jest/pull/11220))
3838
- `[jest-reporters]` Add static filepath property to all reporters ([#11015](https://github.com/facebook/jest/pull/11015))
39-
- `[jest-snapshot]` [**BREAKING**] Make prettier optional for inline snapshots - fall back to string replacement ([#7792](https://github.com/facebook/jest/pull/7792))
39+
- `[jest-snapshot]` [**BREAKING**] Make prettier optional for inline snapshots - fall back to string replacement ([#7792](https://github.com/facebook/jest/pull/7792) & [#11192](https://github.com/facebook/jest/pull/11192))
4040
- `[jest-snapshot]` [**BREAKING**] Run transforms over `snapshotResolver` ([#8751](https://github.com/facebook/jest/pull/8829))
4141
- `[jest-transform]` Pass config options defined in Jest's config to transformer's `process` and `getCacheKey` functions ([#10926](https://github.com/facebook/jest/pull/10926))
4242
- `[jest-transform]` Add support for transformers written in ESM ([#11163](https://github.com/facebook/jest/pull/11163))
@@ -70,6 +70,7 @@
7070
- `[jest-core]` Don't report PerformanceObserver as open handle ([#11123](https://github.com/facebook/jest/pull/11123))
7171
- `[jest-core]` Use `WeakRef` to hold timers when detecting open handles ([#11277](https://github.com/facebook/jest/pull/11277))
7272
- `[jest-core]` Correctly detect open handles that were created in test functions using `done` callbacks ([#11382](https://github.com/facebook/jest/pull/11382))
73+
- `[jest-core]` Do not collect `RANDOMBYTESREQUEST` as open handles ([#11278](https://github.com/facebook/jest/pull/11278))
7374
- `[jest-core]` Wait briefly for open handles to close before flagging them when using `--detectOpenHandles` ([#11429](https://github.com/facebook/jest/pull/11429))
7475
- `[jest-diff]` [**BREAKING**] Use only named exports ([#11371](https://github.com/facebook/jest/pull/11371))
7576
- `[jest-each]` [**BREAKING**] Ignore excess words in headings ([#8766](https://github.com/facebook/jest/pull/8766))

e2e/__tests__/detectOpenHandles.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ it('does not report promises', () => {
7171
expect(textAfterTest).toBe('');
7272
});
7373

74+
it('does not report crypto random data', () => {
75+
// The test here is basically that it exits cleanly without reporting anything (does not need `until`)
76+
const {stderr} = runJest('detect-open-handles', [
77+
'crypto',
78+
'--detectOpenHandles',
79+
]);
80+
const textAfterTest = getTextAfterTest(stderr);
81+
82+
expect(textAfterTest).toBe('');
83+
});
84+
7485
onNodeVersions('>=11.10.0', () => {
7586
it('does not report ELD histograms', () => {
7687
const {stderr} = runJest('detect-open-handles', [
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
const {randomFillSync} = require('crypto');
9+
10+
test('randomFillSync()', () => {
11+
const buf = Buffer.alloc(10);
12+
randomFillSync(buf);
13+
});

packages/jest-core/src/collectHandles.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ export default function collectHandles(): HandleCollectionResult {
6666
type === 'PROMISE' ||
6767
type === 'TIMERWRAP' ||
6868
type === 'ELDHISTOGRAM' ||
69-
type === 'PerformanceObserver'
69+
type === 'PerformanceObserver' ||
70+
type === 'RANDOMBYTESREQUEST'
7071
) {
7172
return;
7273
}

packages/jest-snapshot/src/InlineSnapshots.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,15 @@ export function saveInlineSnapshots(
4949
snapshots: Array<InlineSnapshot>,
5050
prettierPath: Config.Path,
5151
): void {
52-
const prettier = prettierPath
53-
? // @ts-expect-error requireOutside Babel transform
54-
(requireOutside(prettierPath) as Prettier)
55-
: undefined;
52+
let prettier: Prettier | null = null;
53+
if (prettierPath) {
54+
try {
55+
// @ts-expect-error requireOutside Babel transform
56+
prettier = requireOutside(prettierPath) as Prettier;
57+
} catch {
58+
// Continue even if prettier is not installed.
59+
}
60+
}
5661

5762
const snapshotsByFile = groupSnapshotsByFile(snapshots);
5863

packages/jest-snapshot/src/__tests__/InlineSnapshots.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,36 @@ expect(a).toMatchInlineSnapshot(\`[1, 2]\`);
7373
);
7474
});
7575

76+
test('saveInlineSnapshots() with bad prettier path leaves formatting outside of snapshots alone', () => {
77+
const filename = path.join(dir, 'my.test.js');
78+
fs.writeFileSync(
79+
filename,
80+
`
81+
const a = [1, 2];
82+
expect(a).toMatchInlineSnapshot(\`an out-of-date and also multi-line
83+
snapshot\`);
84+
expect(a).toMatchInlineSnapshot();
85+
expect(a).toMatchInlineSnapshot(\`[1, 2]\`);
86+
`.trim() + '\n',
87+
);
88+
89+
saveInlineSnapshots(
90+
[2, 4, 5].map(line => ({
91+
frame: {column: 11, file: filename, line} as Frame,
92+
snapshot: `[1, 2]`,
93+
})),
94+
'bad-prettier',
95+
);
96+
97+
expect(fs.readFileSync(filename, 'utf8')).toBe(
98+
`const a = [1, 2];
99+
expect(a).toMatchInlineSnapshot(\`[1, 2]\`);
100+
expect(a).toMatchInlineSnapshot(\`[1, 2]\`);
101+
expect(a).toMatchInlineSnapshot(\`[1, 2]\`);
102+
`,
103+
);
104+
});
105+
76106
test('saveInlineSnapshots() can handle typescript without prettier', () => {
77107
const filename = path.join(dir, 'my.test.ts');
78108
fs.writeFileSync(

0 commit comments

Comments
 (0)