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

nx/jest marks all projects as affected when updating dependencies (package-lock.json) #30271

Open
2 of 4 tasks
KingScouter opened this issue Mar 5, 2025 · 0 comments
Open
2 of 4 tasks

Comments

@KingScouter
Copy link

Current Behavior

We are working with a pretty big NX monorepo with multiple apps and libraries, pretty much all of them with Jest unit-tests. We also have some separate Typescript-packages which we publish regularly as NPM-packages on Github, which are then installed and integrated in our apps/libraries in the monorepo.
The monorepo has a single package.json file at the root where these packages are installed.
We are using GitHub Actions with NX affected to run tests on push / pull-request. The problem now is that if we update one of the published packages in the monorepo, NX marks all of the apps and libs as affected for the test-target, even if the tests aren't affected at all.

The test-target is configured the following:
In nx.json we have the following code for test:

{
  "targetDefaults": {
    "test": {
      "inputs": [
        "default",
        "^production",
        "{workspaceRoot}/jest.preset.js",
        "!{workspaceRoot}/package-lock.json",
        "!{workspaceRoot}/package.json",
        "!{workspaceRoot}/node_modules/**/*"
      ],
      "outputs": [
        "{workspaceRoot}/coverage/{projectRoot}",
        "{workspaceRoot}/test-artifacts/jest/{projectName}-jest-junit.xml"
      ],
      "options": {
        "jestConfig": "{projectRoot}/jest.config.ts",
        "passWithNoTests": true
      },
      "configurations": {
        "ci": {
          "ci": true,
          "codeCoverage": true
        }
      },
      "cache": true
    },
  },
  "plugins": [
    {
      "plugin": "@nx/jest/plugin",
      "options": {
        "targetName": "test"
      },
      "exclude": ["package-lock.json", "package.json", "{workspaceRoot}/package-lock.json", "{workspaceRoot}/package.json"]
    }
  ],
  "pluginsConfig": {
    "@nx/jest/plugin": {
      "projectsAffectedByDependencyUpdates": "auto"
    }
  }
}

If I then check which projects are affected using npx nx show projects --withTarget test --affected --head HEAD --base HEAD~1 --verbose, all projects are listed.

As described in the documentation (and as you can see above), I already tried to use projectsAffectedByDependencyUpdates to disable or at least improve the detection of affected projects, this however did nothing in the end.

Is there anything I'm missing here? Does the Jest-plugin even support this flag to disable dependency-updates? I could only find references to that in the @nx/js plugin.

Expected Behavior

Updates in dependencies are ignored when executing NX affected for tests with Jest.

GitHub Repo

No response

Steps to Reproduce

  1. Create a repo with multiple apps / libs
  2. Add target test with @nx/jest to all of them.
  3. Change the version of any dependency
  4. Run npx nx show projects --withTarget test --affected --head HEAD --base HEAD~1 --verbose and check the affected targets.

Nx Report

Node           : 20.11.0
OS             : win32-x64
Native Target  : x86_64-windows
npm            : 10.2.4

nx                 : 19.8.0
@nx/js             : 19.8.0
@nx/jest           : 19.8.0
@nx/linter         : 19.8.0
@nx/eslint         : 19.8.0
@nx/workspace      : 19.8.0
@nx/angular        : 19.8.0
@nx/cypress        : 19.8.0
@nx/devkit         : 19.8.0
@nx/eslint-plugin  : 20.0.12
@nx/express        : 19.8.0
@nx/nest           : 19.8.0
@nx/node           : 19.8.0
@nx/storybook      : 19.8.0
@nrwl/tao          : 19.8.0
@nx/web            : 19.8.0
@nx/webpack        : 19.8.0
typescript         : 5.5.4
---------------------------------------
Registered Plugins:
@nx/jest/plugin
---------------------------------------
Community plugins:
@jh-wm/plugin        : 0.0.43
@ngrx/effects        : 18.0.2
@ngrx/operators      : 18.0.1
@ngrx/store          : 18.0.2
@ngrx/store-devtools : 18.0.2
@storybook/angular   : 8.3.2
angular-eslint       : 18.4.2
ngx-bootstrap        : 18.0.2
---------------------------------------
Local workspace plugins:
         @ui/base-libs-nx-generators
---------------------------------------

Failure Logs

Package Manager Version

No response

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