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

jest <regexForTestFiles> CLI not picking up tests #5740

Closed
MadLittleMods opened this issue Mar 6, 2018 · 7 comments
Closed

jest <regexForTestFiles> CLI not picking up tests #5740

MadLittleMods opened this issue Mar 6, 2018 · 7 comments

Comments

@MadLittleMods
Copy link

MadLittleMods commented Mar 6, 2018

jest <regexForTestFiles> CLI not picking up tests.

Perhaps related to #5582

What is the current behavior?

Barebones demo repo: https://gitlab.com/MadLittleMods/jest-test-regex-issue-barebones-test-case1

Reproduction steps
  1. Install jest@22.4.2
  2. Save a file with some tests in some-test.js
  3. jest some-test.js
  4. Notice, No tests found
$ jest some-test.js
No tests found
In /jest-test-regex1
  3 files checked.
  testMatch: **/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x) - 0 matches
  testPathIgnorePatterns: /node_modules/ - 3 matches
Pattern: some-test.js - 0 matches

What is the expected behavior?

The jest <regexForTestFiles> CLI syntax should match files regardless of testMatch config.


This previously worked with jest@22.3.0 but I am unable to downgrade successfully and confirm because it always installs jest-cli@22.4.2. Any tips? Related #405, #3391

This installs jest@22.3.0 and jest-cli@22.3.0 but throws other errors

$ npm install jest@22.3.0 && cd ./node_modules/jest && rm -rf ./node_modules/jest-cli && npm install jest-cli@22.3.0 && cd ../../

$ npm test

TypeError: (0 , (_jestUtil || _load_jestUtil(...)).validateCLIOptions) is not a function
    at buildArgv (/jest-test-regex1/node_modules/jest/node_modules/jest-cli/build/cli/index.js:133:58)
    at Object.<anonymous> (/jest-test-regex1/node_modules/jest/node_modules/jest-cli/build/cli/index.js:41:20)
    at Generator.next (<anonymous>)
    at step (/jest-test-regex1/node_modules/jest/node_modules/jest-cli/build/cli/index.js:53:2732)
    at /jest-test-regex1/node_modules/jest/node_modules/jest-cli/build/cli/index.js:53:2962
    at new Promise (<anonymous>)
    at Object.<anonymous> (/jest-test-regex1/node_modules/jest/node_modules/jest-cli/build/cli/index.js:53:2643)
    at Object.run (/jest-test-regex1/node_modules/jest/node_modules/jest-cli/build/cli/index.js:53:48)
    at Object.<anonymous> (/jest-test-regex1/node_modules/jest/node_modules/jest-cli/bin/jest.js:16:27)
    at Module._compile (module.js:643:30)
@rickhanlonii
Copy link
Member

Hey @MadLittleMods, this is expected as the default matchers exclude your file and Jest will never run tests that are excluded through the config. See #5735 for a feature request to do this with an CLI argument and #5544, #5317, and #5527 for more info

@MadLittleMods
Copy link
Author

This comment explains it well,

For more context, we added support for this without an arg in #3882, and decided to roll back in #5544 and #5582, since we decided that Jest should never run tests that are excluded through the config

@rickhanlonii, #5735 (comment)

I was caught in the between rollout and rollback where this worked and all of the sudden didn't work in a minor release.

Thanks for the extra info 🙂

@angshuman-agarwal
Copy link

angshuman-agarwal commented Mar 17, 2018

Hi,
I have the same exception while running jest. How to resolve please ?
Versions installed -
"jest": "^22.3.0" "@types/jest": "^22.0.1", "ts-jest": "^21.2.1",

TypeError: (0 , (_jestUtil || _load_jestUtil(...)).validateCLIOptions) is not a function
at buildArgv (C:\Angshuman\adminclient_ts\node_modules\jest\node_modules\jest-cli\build\cli\index.js:133:58)
at Object. (C:\Angshuman\adminclient_ts\node_modules\jest\node_modules\jest-cli\build\cli\index.js:41:20)
at Generator.next ()
at step (C:\Angshuman\adminclient_ts\node_modules\jest\node_modules\jest-cli\build\cli\index.js:53:2732)
at C:\Angshuman\adminclient_ts\node_modules\jest\node_modules\jest-cli\build\cli\index.js:53:2962
at Promise ()
at Object. (C:\Angshuman\adminclient_ts\node_modules\jest\node_modules\jest-cli\build\cli\index.js:53:2643)
at Object.run (C:\Angshuman\adminclient_ts\node_modules\jest\node_modules\jest-cli\build\cli\index.js:53:48)
at Object. (C:\Angshuman\adminclient_ts\node_modules\jest\node_modules\jest-cli\bin\jest.js:16:27)
at Module._compile (module.js:569:30)

This is my package.json config for jest :

"jest": { "moduleFileExtensions": [ "ts", "tsx", "js" ], "transform": { "^.+\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/test-preprocessor.js" }, "testRegex": [ "/__tests__/.*\\.(ts|tsx|js)$" ] }

@MadLittleMods
Copy link
Author

@angshuman-agarwal What are your test files named? I suspect you need to update testRegex to match your test files as a path passed as a CLI argument is still subject to the matching/filtering from your config.

@asulaiman
Copy link

asulaiman commented May 22, 2018

@MadLittleMods i m getting the same error.

My directory structure:

root
-test
--spec-files
---*.js

Dev dependencies in my package:

"devDependencies": {
"babel-eslint": "6.1.2",
"babel-jest": "22.1.0",
"chai": "3.5.0",
"chai-as-promised": "5.3.0",
"eslint": "2.13.1",
"eslint-config-airbnb": "6.2.0",
"eslint-plugin-react": "4.3.0",
"jest": "22.1.4",
"jest-cli": "22.1.4",
"jest-runner-eslint": "0.4.0",
"nodemon": "1.12.1",
"nyc": "11.2.1",
"sinon": "2.4.1",
"snyk": "1.69.10",
"spec-xunit-file": "0.0.1-3",
"supertest": "1.2.0",
"supertest-as-promised": "3.2.0",
"xunit-file": "0.0.9"
}

jest.config.js:

module.exports = {
estPathIgnorePatterns: [
'<rootDir>/bower_components/',
'<rootDir>/node_modules/',
'<rootDir>/gulp-tasks/',
],
testMatch: ['<rootDir>/test/spec-files/*.js'],
globalSetup: '<rootDir>/test/setup.js',
};

Running:

./node_modules/.bin/jest --testPathPattern=test/spec-files/.*\\.js$

@MadLittleMods
Copy link
Author

@asulaiman Probably best to create your own issue. Check the regex testMatch when you run Jest to make sure it is what you expect.

@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 May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants