Skip to content

Jest --findRelatedTests flag causes errors in precommit hook #245

@TrevorBurnham

Description

@TrevorBurnham

I ran into this issue when trying to contribute to @testing-library/jest-dom: testing-library/jest-dom#696 As of this writing, if you e.g. try to commit a change to that project's README.md, git will fail with this output:

husky > pre-commit (node v24.4.1)
✔ Preparing lint-staged...
⚠ Running tasks for staged files...
  ❯ node_modules/kcd-scripts/dist/config/lintstagedrc.js — 1 file
    ✔ README.md — 1 file
    ❯ *.+(js|jsx|json|yml|yaml|css|less|scss|ts|tsx|md|gql|graphql|mdx|vue) — 1 file
      ✔ kcd-scripts format
      ✔ kcd-scripts lint
      ✖ kcd-scripts test --findRelatedTests [FAILED]
↓ Skipped because of errors from tasks. [SKIPPED]
✔ Reverting to original state because of errors...
✔ Cleaning up temporary files...

✖ kcd-scripts test --findRelatedTests:
● Validation Warning:

  Unknown option "watchPlugins" with value ["/Users/trevor.burnham/code/jest-dom/node_modules/jest-watch-typeahead/build/file_name_plugin/plugin.js", "/Users/trevor.burnham/code/jest-dom/node_modules/jest-watch-typeahead/build/test_name_plugin/plugin.js"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

  Configuration Documentation:
  https://jestjs.io/docs/configuration

● Validation Warning:

  Unknown option "watchPlugins" with value ["/Users/trevor.burnham/code/jest-dom/node_modules/jest-watch-typeahead/build/file_name_plugin/plugin.js", "/Users/trevor.burnham/code/jest-dom/node_modules/jest-watch-typeahead/build/test_name_plugin/plugin.js"] was found.
  This is probably a typing mistake. Fixing it will remove this message.

  Configuration Documentation:
  https://jestjs.io/docs/configuration

No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0

It seems quite strange that a commit would be rejected because there are no related tests. The obvious fix would be to add the --passWithNoTests flag.

There's a deeper problem, though. At one point, I observed the same precommit hook failure as described above even when making changes to modules that do have tests. I suspect that this is because Jest's --findRelatedTests has known compatibility issues with roots (jestjs/jest#11527), which is a Jest configuration option that kcd-scripts uses.

For that reason, my recommendation would be to do away with the --findRelatedTests flag entirely. I've already submitted a PR to jest-dom to make that change there: testing-library/jest-dom#709

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions