-
Notifications
You must be signed in to change notification settings - Fork 306
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
Remove testRegex out of preset #131
Conversation
jest-preset.json
Outdated
@@ -8,7 +8,6 @@ | |||
"transform": { | |||
"^.+\\.(ts|js|html)$": "<rootDir>/node_modules/jest-preset-angular/preprocessor.js" | |||
}, | |||
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|js)$", | |||
"moduleFileExtensions": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, but Jest will not match *.ts
files by default. Why not changing it to testMatch
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, but if we add testMatch
, people who want to use testRegex
won't be able to run the tests. I think we should put testMatch
to the README inside installation setup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But testRegex
is already set and we write about it in README, so it will be the same situation. I'm not going to remove the default. One can always override it without any issues. Both cannot work with each other and Jest will warn you about it:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok then I'll adjust testRegex
to be testMatch
👍
jest-preset.json
Outdated
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|js)$", | ||
"testMatch": [ | ||
"(/__tests__/.*|\\.(test|spec))\\.(ts|js)$" | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you adjust the readme and changelog as well?
README.md
Outdated
@@ -45,7 +45,9 @@ import './jestGlobalMocks'; // browser mocks globally available for every test | |||
"transform": { | |||
"^.+\\.(ts|js|html)$": "<rootDir>/node_modules/jest-preset-angular/preprocessor.js" | |||
}, | |||
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|js)$", | |||
"testMatch": [ | |||
"(/__tests__/.*|\\.(test|spec))\\.(ts|js)$" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong. Here's the default one (where I just found a bug XD):
[
'**/__tests__/**/*.js?(x)',
'**/?(*.)(spec|test).js?(x)'
]
and we rather want to change it to:
[
'**/__tests__/**/*.+(ts|js)?(x)',
'**/?(*.)+(spec|test).+(ts|js)?(x)'
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh those 2 are default from Jest 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you make sure it works on current projects?
I think the regex is not good enough. Just try But I still can't ignore Updated: |
I think the second part should be
|
|
Updated in the latest commit 👍 |
README.md
Outdated
@@ -66,7 +69,7 @@ import './jestGlobalMocks'; // browser mocks globally available for every test | |||
* `<rootDir>` is a special syntax for root of your project (here by default it's project's root /) | |||
* we're using some `"globals"` to pass information about where our tsconfig.json file is that we'd like to be able to transform HTML files through ts-jest | |||
* `"transform"` – run every TS, JS, or HTML file through so called *preprocessor* (we'll get there); this lets Jest understand non-JS syntax | |||
* `"testRegex"` – we want to run Jest on files that matches this regex | |||
* `"testMatch"` – we want to run Jest on files that matches this regex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this glob
jest-preset.json
Outdated
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|js)$", | ||
"testMatch": [ | ||
"**/__tests__/**/*.(ts|js)?(x)", | ||
"**/+(*.)(spec|test).(ts|js)?(x)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should also add +
s before the (..|..)
groups, because that's a valid glob. What we use currently at Jest (and I filed a PR to fix it: jestjs/jest#5744) uses an extra feature from micromatch
library.
"**/__tests__/**/*.+(ts|js)?(x)",
"**/+(*.)+(spec|test).+(ts|js)?(x)"
Thanks for sticking with me! |
Thank you too. I learnt something new about glob as well |
Me too! |
Jest default set up testMatch to get all the test files to run. Removing testRegex out of the preset will bring flexibility to the users to set up their own testMatch/testRegex.