Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug?]: Plug'n'Play causes Jest to detect open handles with some @types/ packages #3376

Closed
1 task done
WesCossick opened this issue Sep 2, 2021 · 3 comments
Closed
1 task done
Labels
bug Something isn't working external bug This issue highlights a bug in another project reproducible This issue can be successfully reproduced

Comments

@WesCossick
Copy link

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

@WesCossick WesCossick added the bug Something isn't working label Sep 2, 2021
@yarnbot

This comment has been minimized.

@yarnbot yarnbot added the reproducible This issue can be successfully reproduced label Sep 2, 2021
@Psidium
Copy link
Contributor

Psidium commented Sep 29, 2021

I'm having this warning with Jest too. In my case it says there are 6 open handles in a test dynamically import()ing the files being tested. I call await import() 6 times and I have 6 open handles.

Something like (Maybe won't reproduce, sometimes it does sometimes it doesn't).

const fs = require('fs');

await packageJsonAndInstall({
  scripts: {
    test: "jest --detectOpenHandles --forceExit 2>&1",
  },
  dependencies: {
    "@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 const helloWorld = () => Promise.resolve("Hello world!");`);
fs.writeFileSync('second-file.ts', `export const second = () => "aa";`);

fs.writeFileSync('hello-world.test.ts', `it("Works", async () => {
  const { helloWorld } = await import("./hello-world");
  const { second } = await import("./second-file");
  expect(second()).toBe("aa");
  expect(helloWorld()).resolves.toEqual("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');

@merceyz merceyz added the external bug This issue highlights a bug in another project label Nov 10, 2021
@merceyz
Copy link
Member

merceyz commented Nov 10, 2021

This was an issue in Jest which was tracked in jestjs/jest#11542 and fixed in jestjs/jest#12022

@merceyz merceyz closed this as completed Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working external bug This issue highlights a bug in another project reproducible This issue can be successfully reproduced
Projects
None yet
Development

No branches or pull requests

4 participants