Skip to content

Invalidate test cache when fixtures change #1102

@matejchalk

Description

@matejchalk

Each test target - unit-test, int-test, e2e-test - should be invalidated whenever the tested code changes, or the tests themselves change. Currently, the cache isn't being invalidated when fixtures change - i.e. files which aren't imported in code, but are read from file system with node:fs module (usually copied to a temporary test folder in beforeEach/beforeAll).

Because of this, we run the risk of merging broken tests, which will be hard to track down.

Steps to reproduce

  1. Run npx nx int-test plugin-eslint. Tests will pass and Nx will save cache.
  2. Change any file under packages/plugin-eslint/mocks/fixtures in a way that should break some test (e.g. delete nx-monorepo/nx.json).
  3. Re-run npx nx int-test plugin-eslint. Tests will pass instantly, Nx logs that cache was used.
  4. Run npx nx int-test plugin-eslint --skipNxCache. Observe that tests fail.

This is repeatable for any other type of test that relies on file system - i.e. some integration tests, most E2E tests.

Proposed solution

See discussion, mainly this comment

Acceptance criteria

  • Any change to files under {projectRoot} should invalidate test targets in Nx cache.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions