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

--findRelatedTests does not seem to be combatible with roots #11527

Closed
nicojs opened this issue Jun 4, 2021 · 2 comments
Closed

--findRelatedTests does not seem to be combatible with roots #11527

nicojs opened this issue Jun 4, 2021 · 2 comments

Comments

@nicojs
Copy link
Contributor

nicojs commented Jun 4, 2021

🐛 Bug Report

Using --findRelatedTest doesn't seem to be compatible with specifying roots.

To Reproduce

Steps to reproduce the behavior:

  1. Make sure your tests are located in a different directory than your main code:
    ├── package-lock.json
    ├── package.json
    ├── src
    │   └── example.js
    └── test
        └── example.test.js
    
  2. Configure roots to point to your test dir
    {
        "jest": {
          "roots": ["test"]
        }
    }
  3. Run npx jest --findRelatedTests src/example.js and see the following:
    No tests found, exiting with code 1
    Run with `--passWithNoTests` to exit with code 0
    No files found in ~/github/jest-find-related-tests-roots.
    Make sure Jest's configuration does not exclude this directory.
    To set up Jest, make sure a package.json file exists.
    Jest Documentation: https://jestjs.io/docs/configuration
    Pattern: src/example.js - 0 matches
    

Expected behavior

 PASS  test/example.test.js
  ✓ should provide 42 (2 ms)

Link to repl or repo (highly encouraged)

See https://github.com/nicojs/jest-find-related-tests-roots for an example.

envinfo


  System:
    OS: Linux 5.4 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
  Binaries:
    Node: 14.16.1 - /usr/bin/node
    Yarn: 1.22.10 - /usr/bin/yarn
    npm: 6.14.12 - /usr/bin/npm
  npmPackages:
    jest: ^27.0.4 => 27.0.4
@nicojs
Copy link
Contributor Author

nicojs commented Jun 11, 2021

After reading the docs on roots, I think this works as designed. I've implemented a fix in Stryker (add the directory of the file under test to "roots" before each run).

Note: While rootDir is mostly used as a token to be re-used in other configuration options, roots is used by the internals of Jest to locate test files and source files. This applies also when searching for manual mocks for modules from node_modules (__mocks__ will need to live in one of the roots).

@nicojs nicojs closed this as completed Jun 11, 2021
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant