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

Remove testRegex out of preset #131

Merged
merged 8 commits into from
Mar 7, 2018
Merged

Remove testRegex out of preset #131

merged 8 commits into from
Mar 7, 2018

Conversation

ahnpnl
Copy link
Collaborator

@ahnpnl ahnpnl commented Mar 7, 2018

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.

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": [
Copy link
Owner

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?

Copy link
Collaborator Author

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.

Copy link
Owner

@thymikee thymikee Mar 7, 2018

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:

https://github.com/facebook/jest/blob/f1c422f58ab05010ccbfd42902248946e5924860/packages/jest-config/src/normalize.js#L582-L587

Copy link
Collaborator Author

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)$"
],
Copy link
Owner

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)$"
Copy link
Owner

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)' 
]

Copy link
Collaborator Author

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 👍

Copy link
Owner

@thymikee thymikee left a 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?

@ahnpnl
Copy link
Collaborator Author

ahnpnl commented Mar 7, 2018

I think the regex is not good enough. Just try yarn pack and install it into example app. It doesn't exclude src/test.ts .
I'd prefer this one
"testMatch": [ "**/__tests__/**/*.(ts|js)?(x)", "**/?(*.)(spec|test).(ts|js)?(x)" ]

But I still can't ignore src/test.ts yet

Updated:
This one seems to work well:
[ "**/__tests__/**/*.(ts|js)?(x)", "**/?*.(spec|test).(ts|js)?(x)" ]

@thymikee
Copy link
Owner

thymikee commented Mar 7, 2018

I think the second part should be

"**/+(*.)(spec|test).(ts|js)?(x)"

@ahnpnl
Copy link
Collaborator Author

ahnpnl commented Mar 7, 2018

  • Tested with new project generated with CLI: OK
  • Tested with example inside the repo: still fails with src/test.ts
    Updated: I think it's good now. My mistake didn't generate the new package for example

@ahnpnl
Copy link
Collaborator Author

ahnpnl commented Mar 7, 2018

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
Copy link
Owner

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)"
Copy link
Owner

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)"

@thymikee thymikee merged commit d7ffd1b into thymikee:master Mar 7, 2018
@thymikee
Copy link
Owner

thymikee commented Mar 7, 2018

Thanks for sticking with me!

@ahnpnl
Copy link
Collaborator Author

ahnpnl commented Mar 7, 2018

Thank you too. I learnt something new about glob as well

@thymikee
Copy link
Owner

thymikee commented Mar 7, 2018

Me too!

@ahnpnl ahnpnl deleted the fix/remove-testregex branch March 7, 2018 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants