-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Allow array of regexp strings for testRegex #7209
Allow array of regexp strings for testRegex #7209
Conversation
The CI failure appears to be unrelated or random. |
Can you rebase? 🙂 Just doing an interactive one and removing the first commit should be enough, right? |
fb5b31d
to
c2c23f0
Compare
Rebased - I also had a type error in |
if (config.testRegex && filename.match(config.testRegex)) { | ||
if ( | ||
config.testRegex && | ||
config.testRegex.some(regex => filename.match(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.
I know you didn't introduce it, but can you use test
instead?
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.
To do this efficiently, it was necessary to change the internal type in ProjectConfig
to an array of RegExp
instead of string
(rather than parse the strings into RegExp
on every use here). This makes more sense anyway, but it touched a few things.
@@ -34,6 +34,6 @@ export function validationCondition(option: any, validOption: any): boolean { | |||
return getValues(validOption).some(e => validationConditionSingle(option, e)); | |||
} | |||
|
|||
export function MultipleValidOptions(...args: Array<any>) { |
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.
?
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.
Oops. Failed rebase.
.vscode/settings.json
Outdated
@@ -1,5 +1,7 @@ | |||
{ | |||
"editor.rulers": [80], | |||
"editor.rulers": [ |
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 the most annoying thing.... so when I fixed this, then saved, of course it incorrectly reformatted the fixed file itself!! I keel you vscode
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.
git checkout master .vscode/settings.json
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.
These are a couple of fantastic pull requests, thank you so much!
I'd like another set of eyes before merging, but this LGTM 🙂
I'll have one more look tomorrow morning |
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.
Looks good! I left 2 small things to address and we can ship it :)
|
||
it('when more than one testRegex is provided and filename is not a test file', () => { | ||
testShouldInstrument('source_file.js', defaultOptions, { | ||
testRegex: [/.*\_(test)\.(js)$/, /.*\.(test)\.(js)$/, /never/], | ||
}); |
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.
I see that we only test happy path in this test file. It would be great to add at least two smoke tests (1 for testRegex, 1 for testMatch) when the file should not be instrumented (e.g. add 4th expected
argument to testShouldInstrument
with default value of true
).
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.
There are already two describe
sections in this file, the 2nd -- "should return false" -- tests for scenarios that don't match, the unhappy path. I did add a test there already for testRegex
.
I do see that the description of the spec was incorrect, I have fixed that, as well as a couple other existing ones that were also incorrect. Maybe this was throwing you off - either way if there's still some additional coverage you'd like to see let me know.
I have also added a test of error condition to normalize.test.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.
Oh my, I totally missed second testShouldInstrument
. Should be renamed to testShouldNotInstrument
😛
a2f8e71
to
e25d89c
Compare
@@ -100,7 +101,10 @@ export default ({ | |||
testMatch: ['**/__tests__/**/*.js?(x)', '**/?(*.)+(spec|test).js?(x)'], | |||
testNamePattern: 'test signature', | |||
testPathIgnorePatterns: [NODE_MODULES_REGEXP], | |||
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.jsx?$', | |||
testRegex: MultipleValidOptions( |
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.
also, what do you think about naming this just multiple
for simplicity? I'm good with both, so pick whatever you like :)
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.
I don't feel strongly, but I guess I'd lean towards leaving it more verbose to provide clear context, since Mutliple
could potentially mean more than one thing.
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Resolves #7180
Depends on #7207
Creating dynamic configurations to include or exclude specific things is difficult because of inconsistency in how config allows specifying inclusions and exclusions.
testRegex
allows only a single regexptestMatch
allows an array of globstestPathIgnorePatterns
allows an array of regexpsSo there's no format (regex or glob) that can be used to build an array that works both for including and excluding.
This PR allows
testRegex
to accept an array of regex strings as well as a string, resolving this problem.Because this is the first configuration option that's overloaded with more than one valid type,
jest-validation
has also been enhanced with syntax that allows specifying more than one valid example in configuration.Test plan