-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Self-service
- I'd be willing to implement a fix
Describe the bug
If Plug'n'Play is used, for both Yarn 2 and Yarn 3, Jest will detect open handles inside .pnp.cjs
for the @types/express
and @types/supertest
packages. Here's the message from Jest:
Jest has detected the following 5 open handles potentially keeping Jest from exiting:
● ZLIB
12326 | });
12327 | } else {
> 12328 | const decompressedData = external_zlib_default().inflateRawSync(data);
| ^
12329 | this.fileSources.set(index, decompressedData);
12330 | return decompressedData;
12331 | }
at ZipFS.getFileSource (.pnp.cjs:12328:60)
at ZipFS.readFileBuffer (.pnp.cjs:12648:17)
at ZipFS.readFileSync (.pnp.cjs:12634:23)
Other @types/
packages may be affected, though I wasn't able to find any. Most @types/
packages do not appear to be affected by this bug.
To reproduce
Below is the closest I could come to creating a reproduction using the Sherlock Playground. Tests took minutes, not seconds, to run, if they even finished running at all. The editor often froze, sometimes it wouldn't allow me to type, many times the test would fail with no output or indication why, results would differ even without changing the code, I occasionally received errors about React, and finally I started receiving "502: Bad Gateway" errors. It was at this point that I gave up.
Instead, I highly recommend taking a look at the GitHub repository I created to reproduce the error using various versions of Yarn with and without Plug'n'Play enabled: https://github.com/WesCossick/reproduce-zlib-open-handle.
const fs = require('fs');
await packageJsonAndInstall({
scripts: {
test: "jest --detectOpenHandles --forceExit 2>&1",
},
dependencies: {
"@types/express": "^4.17.13",
"@types/jest": "^27.0.1",
jest: "^27.1.0",
"ts-jest": "^27.0.5",
typescript: "~4.2.0",
},
});
fs.writeFileSync('tsconfig.json', `{
"include": ["*"],
"compilerOptions": {
"esModuleInterop": true,
"module": "CommonJS",
"moduleResolution": "Node",
"strict": true,
"target": "ES2019"
}
}`);
fs.writeFileSync('jest.config.js', `module.exports = {
preset: "ts-jest",
testEnvironment: "node",
testFailureExitCode: 0,
};`);
fs.writeFileSync('hello-world.ts', `export default () => "Hello world!";`);
fs.writeFileSync('hello-world.test.ts', `import helloWorld from "./hello-world";
it("Works", () => {
expect(helloWorld()).toBe("Hello world!");
});`);
await yarn('run', 'test'); // Often the first run doesn't detect open handles
const output = await yarn('run', 'test');
console.log(output);
await expect(output).toContain('1 passed, 1 total');
await expect(output).not.toContain('potentially keeping Jest from exiting');
Environment
System:
OS: macOS 11.5.2
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Binaries:
Node: 14.17.0 - /private/var/folders/nf/rf7d163x7p3g_jkyzmzx6mv40000gn/T/xfs-9b2da1a6/node
Yarn: 3.0.1 - /private/var/folders/nf/rf7d163x7p3g_jkyzmzx6mv40000gn/T/xfs-9b2da1a6/yarn
npm: 7.20.3 - /usr/local/bin/npm
Additional context
No response