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

NX20 and @nx/jest/plugin: implicit 'test' target disappeared #29057

Open
1 of 4 tasks
stefanlivens opened this issue Nov 25, 2024 · 0 comments
Open
1 of 4 tasks

NX20 and @nx/jest/plugin: implicit 'test' target disappeared #29057

stefanlivens opened this issue Nov 25, 2024 · 0 comments

Comments

@stefanlivens
Copy link

Current Behavior

When migrating to NX20 in a mono-repo, the implicit 'test'-target from @nx/jest/plugin has disappeared.

Situation:
Full NX mono-repo, with components in /packages/ and supporting stuff like storybook in /libs/. Complete setup with jest, separate jest.configs in the /libs/ and /packages/, and a target setup in the root nx.json like this:

"plugins": [{
      "plugin": "@nx/jest/plugin",
      "exclude": ["libs/**/*"],
      "options": {
        "targetName": "test"
      }
 }]

A jest.config.ts like

import { getJestProjects } from '@nx/jest';

export default {
  projects: getJestProjects(),
...
};

When migrating to NX20, and after running the provided migration, this becomes:

import { getJestProjectsAsync } from '@nx/jest';

export default async () => ({
  projects: await getJestProjectsAsync(),
  ...
});

And this makes the test target disappear, meaning we get this error:
NX Cannot find configuration for task component-library:test

Upon investigating the NX -source code, we found this (plugin.ts)

if (jestConfigContent.includes('getJestProjectsAsync()')) {
  // The `getJestProjectsAsync` function uses the project graph, which leads to a
  // circular dependency. We can skip this since it's no intended to be used for
  // an Nx project.
  return {};
}

This confuses me:

  • so if jestProjectAsync is present, do not add the implicit target ? But this is what the documentation says me to do, no?
  • "not intended to be used for an nx project"?

I kinda get the circular dependency reference, but then how should we use this @nx/jest plugin?

Expected Behavior

I did not expect the 'test' target to disappear.
So it would be nice to have some kind of a warning/error from the @nx/jest/plugin.

GitHub Repo

No response

Steps to Reproduce

Nx Report

Node           : 20.17.0
OS             : darwin-x64
Native Target  : x86_64-macos
npm            : 10.8.2

nx (global)        : 19.5.2
nx                 : 20.1.3
@nx/js             : 20.1.3
@nx/jest           : 20.1.3
@nx/eslint         : 20.1.3
@nx/workspace      : 20.1.3
@nx/devkit         : 20.1.3
@nx/eslint-plugin  : 20.1.3
@nx/plugin         : 20.1.3
@nx/web            : 20.1.3
typescript         : 5.4.5
---------------------------------------
Registered Plugins:
@nx/jest/plugin
@nx/eslint/plugin

Failure Logs

Package Manager Version

npm

Operating System

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

Additional Information

No response

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

1 participant