nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
22.59k stars 2.25k forks source link

Default plugin tests hangs because of handles in NX 19 #26346

Open stephane2024 opened 4 weeks ago

stephane2024 commented 4 weeks ago

Current Behavior

Default tests for plugin should not fails

Expected Behavior

Should not fail or keep handles

GitHub Repo

https://github.com/stephane2024/ReproNX19

Steps to Reproduce

  1. create workspace npx create-nx-workspace@latest with
    • React
    • None (framework)
    • Integrated mono repo
    • webpack
    • None (E2E tests)
    • Emotion
    • No cloud

(install dependencies)

  1. create plugin npx nx add @nx/plugin npx nx g @nx/plugin:plugin plugin-a --directory libs/plugins/a npx nx generate @nx/plugin:generator generator-a --directory libs/plugins/a/src

  2. run test npm run test

Generate plugin works fine: npx nx generate @org/plugin-a:generator-a mylib --directory libs/ui/v1

Nx Report

PS C:\Work\Others\test-nx\MonoRepo> npx nx report

 NX   Report complete - copy this into the issue template

Node   : 20.12.2
OS     : win32-x64
yarn   : 1.22.22

nx                 : 19.1.1
@nx/js             : 19.1.1
@nx/jest           : 19.1.1
@nx/linter         : 19.1.1
@nx/eslint         : 19.1.1
@nx/workspace      : 19.1.1
@nx/devkit         : 19.1.1
@nx/eslint-plugin  : 19.1.1
@nx/plugin         : 19.1.1
@nx/react          : 19.1.1
@nrwl/tao          : 19.1.1
@nx/web            : 19.1.1
@nx/webpack        : 19.1.1
typescript         : 5.4.5
---------------------------------------
Registered Plugins:
@nx/webpack/plugin
@nx/eslint/plugin
@nx/jest/plugin
---------------------------------------
Local workspace plugins:
         @mono-repo/plugin-a

Failure Logs

PS C:\Work\Others\test-nx\MonoRepo> npm run test

> @mono-repo/source@0.0.0 test
> nx run plugin-a:test --detectOpenHandles

> nx run plugin-a:test --detectOpenHandles

> jest --detectOpenHandles

 PASS   plugin-a  src/generator.spec.ts
  generator-a generator
    √ should run successfully (656 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        3.723 s
Ran all test suites.

Jest has detected the following 2 open handles potentially keeping Jest from exiting:

  ●  CustomGC

      1 | import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
    > 2 | import { Tree, readProjectConfiguration } from '@nx/devkit';
        | ^
      3 |
      4 | import { generatorAGenerator } from './generator';
      5 | import { GeneratorAGeneratorSchema } from './schema';

      at Runtime._loadModule (../../../node_modules/jest-runtime/build/index.js:1018:29)
      at Object.<anonymous> (../../../node_modules/nx/src/native/native-bindings.js:66:29)
      at Object.<anonymous> (../../../node_modules/nx/src/native/index.js:75:21)
      at Object.<anonymous> (../../../node_modules/nx/src/tasks-runner/pseudo-terminal.js:4:18)
      at Object.<anonymous> (../../../node_modules/nx/src/command-line/run/run.js:13:27)
      at Object.<anonymous> (../../../node_modules/nx/src/devkit-exports.js:31:13)
      at Object.<anonymous> (../../../node_modules/@nx/devkit/index.js:17:22)
      at Object.<anonymous> (src/generator.spec.ts:2:1)

  ●  PIPEWRAP

      at node_modules/get-stdin/index.js (../../../node_modules/prettier/third-party.js:8690:7)
      at __require (../../../node_modules/prettier/third-party.js:6:50)
      at Object.<anonymous> (../../../node_modules/prettier/third-party.js:8976:13)
      at src/config/resolve-config.js (../../../node_modules/prettier/index.js:18407:22)
      at __require (../../../node_modules/prettier/index.js:1748:51)
      at src/common/get-file-info.js (../../../node_modules/prettier/index.js:18796:19)
      at __require (../../../node_modules/prettier/index.js:1748:51)
      at Object.<anonymous> (../../../node_modules/prettier/index.js:38172:19)
      at ../../../node_modules/@nx/devkit/src/generators/format-files.js:14:55
      at async formatFiles (../../../node_modules/@nx/devkit/src/generators/format-files.js:14:20)

——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— 

 NX   Successfully ran target test for project plugin-a (7s)

      With additional flags:
        --detectOpenHandles=true

Package Manager Version

NPM: 10.5.0 YARN: 1.22.22

Operating System

Additional Information

We are experiencing issues with the plugins tests after upgrading to NX 19. The tests fails on the CI with some warnings.

The repro repository I've sent is just empty workspace with a react application and a default plugin. When the tests are run with flag --detectOpenHandles, we can see 2 open handles that aren't released.

The plugin actually works and will generate files when called.

Same issue with NX 19.1.2

Thanks for your help 🙏

marekhuckmann commented 4 weeks ago

having the same issues