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

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

Open
1 of 4 tasks
stephane2024 opened this issue Jun 4, 2024 · 8 comments
Open
1 of 4 tasks

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

stephane2024 opened this issue Jun 4, 2024 · 8 comments

Comments

@stephane2024
Copy link

stephane2024 commented Jun 4, 2024

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/[email protected] 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

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

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
Copy link

having the same issues

@stephane2024 stephane2024 changed the title Default plugin tests fails because of handles NX19 Default plugin tests hangs because of handles in NX 19 Jun 4, 2024
@jonthomp
Copy link

We're having this issue after trying to upgrade from 18 to 19.5.1, have also tried 19.4.2.

macOS Sonoma
Node 21.7.0
NPM 10.5.0

Seems to impact all imports from @nx/devkit.

@jyannessa-mtx
Copy link

Also running into the same issue, which appears to be linked to flaky long running tests on CI. The stacktrace seems to always point to the first import of @nx/devkit or import { libraryGenerator } from '@nx/js';

Node   : 20.11.0
OS     : darwin-arm64
npm    : 10.2.4

nx                 : 19.5.2
@nx/js             : 19.5.2
@nx/jest           : 19.5.2
@nx/linter         : 19.5.2
@nx/eslint         : 19.5.2
@nx/workspace      : 19.5.2
@nx/angular        : 19.5.2
@nx/cypress        : 19.5.2
@nx/devkit         : 19.5.2
@nx/eslint-plugin  : 19.5.2
@nx/nest           : 19.5.2
@nx/node           : 19.5.2
@nx/plugin         : 19.5.2
@nx/storybook      : 19.5.2
@nrwl/tao          : 19.5.2
@nx/web            : 19.5.2
@nx/webpack        : 19.5.2
typescript         : 5.3.3
---------------------------------------
Community plugins:
@fortawesome/angular-fontawesome : 0.14.1
@ngneat/spectator                : 14.0.0
@storybook/angular               : 8.0.10
ng-mocks                         : 14.12.1
ngx-bootstrap                    : 12.0.0
---------------------------------------
Local workspace plugins:
         @mtx/nx-plugin

@AgentEnder
Copy link
Member

Hey, I agree this isn't great. There is something in our native code causing the open handle. While we get this figured out, you can add forceExit to your jest config. We'll be investigating this soon to try to figure out the root cause.

@blcoyote
Copy link

blcoyote commented Aug 14, 2024

Posting to say we're seeing the same issue with "@nx/devkit": "19.5.7",

` PASS workspace-plugin libs/workspace-plugin/src/executors/build/executor.spec.ts
● Console

console.log
  Executor ran for Build {}

  at runExecutor (src/executors/build/executor.ts:4:11)

Test Suites: 2 passed, 2 total
Tests: 13 passed, 13 total
Snapshots: 0 total
Time: 2.103 s
Ran all test suites.

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

● CustomGC

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

  at Runtime._loadModule (../../node_modules/jest-runtime/build/index.js:1018:29)
  at requireNative (../../node_modules/nx/src/native/native-bindings.js:159:16)
  at Object.<anonymous> (../../node_modules/nx/src/native/native-bindings.js:332:17)
  at Object.<anonymous> (../../node_modules/nx/src/native/index.js:91:21)
  at Object.<anonymous> (../../node_modules/nx/src/daemon/client/client.js:23:18)
  at Object.<anonymous> (../../node_modules/nx/src/project-graph/project-graph.js:12:18)
  at Object.<anonymous> (../../node_modules/nx/src/project-graph/file-utils.js:17:25)
  at Object.<anonymous> (../../node_modules/nx/src/utils/package-manager.js:24:22)
  at Object.<anonymous> (../../node_modules/nx/src/utils/package-json.js:16:27)
  at Object.<anonymous> (../../node_modules/nx/src/project-graph/plugins/loader.js:13:24)
  at Object.<anonymous> (../../node_modules/nx/src/project-graph/plugins/index.js:6:16)
  at Object.<anonymous> (../../node_modules/nx/src/devkit-exports.js:12:17)
  at Object.<anonymous> (../../node_modules/@nx/devkit/index.js:17:22)
  at Object.<anonymous> (src/generators/new-selfservice-lib/generator.spec.ts:1:1)

● TTYWRAP

  173 | async function generatReactLibrary(tree: Tree, options: NormalizedSchema) {
  174 |   console.log('Generating React style library');
> 175 |   await reactLibraryGenerator(tree, {
      |   ^
  176 |     name: options.name,
  177 |     directory: options.projectDirectory,
  178 |     tags: options.parsedTags,

  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 ensurePackage (../../node_modules/@nx/devkit/src/utils/package-json.js:280:16)
  at initGenerator (../../node_modules/@nx/js/src/generators/init/init.js:106:32)
  at async libraryGeneratorInternal (../../node_modules/@nx/react/src/generators/library/library.js:39:24)
  at async libraryGenerator (../../node_modules/@nx/react/src/generators/library/library.js:24:12)
  at async generatReactLibrary (src/generators/new-selfservice-lib/generator.ts:175:3)
  at async _default (src/generators/new-selfservice-lib/generator.ts:66:5)
  at async Object.<anonymous> (src/generators/new-selfservice-lib/generator.spec.ts:22:5)`

@csk-trackunit
Copy link

Having the same issue, and it seems related to readProjectConfiguration.

Jest has detected the following 1 open handle potentially keeping Jest from exiting:

  ●  CustomGC

    > 1 | import { Tree, readProjectConfiguration } from "@nx/devkit";
        | ^
      2 | import { createTreeWithEmptyWorkspace } from "@nx/devkit/testing";
      3 | import nxLibGenerator, { NxLibSchema } from "./generator";
      4 |

      at Runtime._loadModule (../../../node_modules/.store/jest-runtime-npm-29.7.0-120fa64128/node_modules/jest-runtime/build/index.js:1018:29)
      at requireNative (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/native/native-bindings.js:159:16)
      at Object.<anonymous> (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/native/native-bindings.js:332:17)
      at Object.<anonymous> (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/native/index.js:91:21)
      at Object.<anonymous> (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/daemon/client/client.js:23:18)
      at Object.<anonymous> (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/project-graph/project-graph.js:12:18)
      at Object.<anonymous> (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/project-graph/file-utils.js:17:25)
      at Object.<anonymous> (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/utils/package-manager.js:24:22)
      at Object.<anonymous> (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/utils/package-json.js:16:27)
      at Object.<anonymous> (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/project-graph/plugins/loader.js:13:24)
      at Object.<anonymous> (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/project-graph/plugins/index.js:6:16)
      at Object.<anonymous> (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/devkit-exports.js:12:17)
      at Object.<anonymous> (../../../node_modules/.store/@nx-devkit-virtual-d6924ab5c7/node_modules/@nx/devkit/index.js:17:22)
      at Object.<anonymous> (src/generators/nx-lib/generator.spec.ts:1:1)

After removing the readProjectConfiguration import from our test, the open handle is detected in the generator and not directly in the test.

Jest has detected the following 1 open handle potentially keeping Jest from exiting:

  ●  CustomGC

    > 1 | import {
        | ^
      2 |   formatFiles,
      3 |   generateFiles,
      4 |   getWorkspaceLayout,

      at Runtime._loadModule (../../../node_modules/.store/jest-runtime-npm-29.7.0-120fa64128/node_modules/jest-runtime/build/index.js:1018:29)
      at requireNative (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/native/native-bindings.js:159:16)
      at Object.<anonymous> (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/native/native-bindings.js:332:17)
      at Object.<anonymous> (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/native/index.js:91:21)
      at Object.<anonymous> (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/daemon/client/client.js:23:18)
      at Object.<anonymous> (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/project-graph/project-graph.js:12:18)
      at Object.<anonymous> (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/project-graph/file-utils.js:17:25)
      at Object.<anonymous> (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/utils/package-manager.js:24:22)
      at Object.<anonymous> (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/utils/package-json.js:16:27)
      at Object.<anonymous> (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/project-graph/plugins/loader.js:13:24)
      at Object.<anonymous> (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/project-graph/plugins/index.js:6:16)
      at Object.<anonymous> (../../../node_modules/.store/nx-virtual-34e0a58c63/node_modules/nx/src/devkit-exports.js:12:17)
      at Object.<anonymous> (../../../node_modules/.store/@nx-devkit-virtual-d6924ab5c7/node_modules/@nx/devkit/index.js:17:22)
      at Object.<anonymous> (src/generators/nx-lib/generator.ts:1:1)
      at Object.<anonymous> (src/generators/nx-lib/generator.spec.ts:3:1)

@alexandr2110pro
Copy link

Hey there! Any plans to solve this?

Same thing on MacOS and Nx v19.7.1

Node           : 20.17.0
OS             : darwin-arm64
Native Target  : aarch64-macos
pnpm           : 9.7.1

nx                 : 19.6.1
@nx/js             : 19.6.1
@nx/jest           : 19.6.1
@nx/linter         : 19.6.1
@nx/eslint         : 19.6.1
@nx/workspace      : 19.6.1
@nx/devkit         : 19.6.1
@nx/eslint-plugin  : 19.6.1
@nx/plugin         : 19.6.1
@nx/rollup         : 19.6.1
@nrwl/tao          : 19.6.1
typescript         : 5.5.4
---------------------------------------
Registered Plugins:
@nx/rollup/plugin
@nx/eslint/plugin
@nx/jest/plugin
---------------------------------------
Local workspace plugins:
	 @easybread/recommended

@santoshyadavdev
Copy link
Contributor

santoshyadavdev commented Nov 4, 2024

We have the same issue with Nx 20.0.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants