Skip to content

Commit

Permalink
Merge branch 'master' into wait-for-closed-resources-to-actually-close
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed May 20, 2021
2 parents 2ab6387 + 27bee72 commit afea019
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -36,7 +36,7 @@
- `[jest-runtime]` Detect reexports from CJS as named exports in ESM ([#10988](https://github.com/facebook/jest/pull/10988))
- `[jest-runtime]` Support for async code transformations ([#11191](https://github.com/facebook/jest/pull/11191) & [#11220](https://github.com/facebook/jest/pull/11220))
- `[jest-reporters]` Add static filepath property to all reporters ([#11015](https://github.com/facebook/jest/pull/11015))
- `[jest-snapshot]` [**BREAKING**] Make prettier optional for inline snapshots - fall back to string replacement ([#7792](https://github.com/facebook/jest/pull/7792))
- `[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))
- `[jest-snapshot]` [**BREAKING**] Run transforms over `snapshotResolver` ([#8751](https://github.com/facebook/jest/pull/8829))
- `[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))
- `[jest-transform]` Add support for transformers written in ESM ([#11163](https://github.com/facebook/jest/pull/11163))
Expand Down Expand Up @@ -70,6 +70,7 @@
- `[jest-core]` Don't report PerformanceObserver as open handle ([#11123](https://github.com/facebook/jest/pull/11123))
- `[jest-core]` Use `WeakRef` to hold timers when detecting open handles ([#11277](https://github.com/facebook/jest/pull/11277))
- `[jest-core]` Correctly detect open handles that were created in test functions using `done` callbacks ([#11382](https://github.com/facebook/jest/pull/11382))
- `[jest-core]` Do not collect `RANDOMBYTESREQUEST` as open handles ([#11278](https://github.com/facebook/jest/pull/11278))
- `[jest-core]` Wait briefly for open handles to close before flagging them when using `--detectOpenHandles` ([#11429](https://github.com/facebook/jest/pull/11429))
- `[jest-diff]` [**BREAKING**] Use only named exports ([#11371](https://github.com/facebook/jest/pull/11371))
- `[jest-each]` [**BREAKING**] Ignore excess words in headings ([#8766](https://github.com/facebook/jest/pull/8766))
Expand Down
11 changes: 11 additions & 0 deletions e2e/__tests__/detectOpenHandles.ts
Expand Up @@ -71,6 +71,17 @@ it('does not report promises', () => {
expect(textAfterTest).toBe('');
});

it('does not report crypto random data', () => {
// The test here is basically that it exits cleanly without reporting anything (does not need `until`)
const {stderr} = runJest('detect-open-handles', [
'crypto',
'--detectOpenHandles',
]);
const textAfterTest = getTextAfterTest(stderr);

expect(textAfterTest).toBe('');
});

onNodeVersions('>=11.10.0', () => {
it('does not report ELD histograms', () => {
const {stderr} = runJest('detect-open-handles', [
Expand Down
13 changes: 13 additions & 0 deletions e2e/detect-open-handles/__tests__/crypto.js
@@ -0,0 +1,13 @@
/**
* 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.
*/

const {randomFillSync} = require('crypto');

test('randomFillSync()', () => {
const buf = Buffer.alloc(10);
randomFillSync(buf);
});
3 changes: 2 additions & 1 deletion packages/jest-core/src/collectHandles.ts
Expand Up @@ -66,7 +66,8 @@ export default function collectHandles(): HandleCollectionResult {
type === 'PROMISE' ||
type === 'TIMERWRAP' ||
type === 'ELDHISTOGRAM' ||
type === 'PerformanceObserver'
type === 'PerformanceObserver' ||
type === 'RANDOMBYTESREQUEST'
) {
return;
}
Expand Down
13 changes: 9 additions & 4 deletions packages/jest-snapshot/src/InlineSnapshots.ts
Expand Up @@ -49,10 +49,15 @@ export function saveInlineSnapshots(
snapshots: Array<InlineSnapshot>,
prettierPath: Config.Path,
): void {
const prettier = prettierPath
? // @ts-expect-error requireOutside Babel transform
(requireOutside(prettierPath) as Prettier)
: undefined;
let prettier: Prettier | null = null;
if (prettierPath) {
try {
// @ts-expect-error requireOutside Babel transform
prettier = requireOutside(prettierPath) as Prettier;
} catch {
// Continue even if prettier is not installed.
}
}

const snapshotsByFile = groupSnapshotsByFile(snapshots);

Expand Down
30 changes: 30 additions & 0 deletions packages/jest-snapshot/src/__tests__/InlineSnapshots.test.ts
Expand Up @@ -73,6 +73,36 @@ expect(a).toMatchInlineSnapshot(\`[1, 2]\`);
);
});

test('saveInlineSnapshots() with bad prettier path leaves formatting outside of snapshots alone', () => {
const filename = path.join(dir, 'my.test.js');
fs.writeFileSync(
filename,
`
const a = [1, 2];
expect(a).toMatchInlineSnapshot(\`an out-of-date and also multi-line
snapshot\`);
expect(a).toMatchInlineSnapshot();
expect(a).toMatchInlineSnapshot(\`[1, 2]\`);
`.trim() + '\n',
);

saveInlineSnapshots(
[2, 4, 5].map(line => ({
frame: {column: 11, file: filename, line} as Frame,
snapshot: `[1, 2]`,
})),
'bad-prettier',
);

expect(fs.readFileSync(filename, 'utf8')).toBe(
`const a = [1, 2];
expect(a).toMatchInlineSnapshot(\`[1, 2]\`);
expect(a).toMatchInlineSnapshot(\`[1, 2]\`);
expect(a).toMatchInlineSnapshot(\`[1, 2]\`);
`,
);
});

test('saveInlineSnapshots() can handle typescript without prettier', () => {
const filename = path.join(dir, 'my.test.ts');
fs.writeFileSync(
Expand Down

0 comments on commit afea019

Please sign in to comment.