-
-
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 configuration object in projects array #5176
Conversation
I'm not familiar with jest-cli/jest-config so let me know if I'm going about implementing it wrong! |
): { | ||
configPath: ?Path, | ||
globalConfig: GlobalConfig, | ||
hasDeprecationWarnings: boolean, | ||
projectConfig: ProjectConfig, | ||
} { | ||
let rawOptions; | ||
let configPath; | ||
let configPath = null; |
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.
Is there anywhere that requires a configPath
to be set other than readConfigFileAndSetRootDir
?
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 pretty cool, I like it a lot! We got a bug report previously that having only one project doesn’t work. Can we, as part of this PR, fix that too? By making it configurable with a custom object, it’s more likely people will end up with a single project while they are iterating on their setup and it would suck if that breaks because of a Jest bug. See #4117
packages/jest-config/src/index.js
Outdated
rawOptions.rootDir = parentConfigPath; | ||
} else { | ||
throw new Error( | ||
'jest: Cannot use configuration as an object without a file path', |
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 end this sentence with a full stop (.) ?
Also, please capitalize Jest.
Codecov Report
@@ Coverage Diff @@
## master #5176 +/- ##
=========================================
+ Coverage 60.54% 60.8% +0.25%
=========================================
Files 201 201
Lines 6707 6707
Branches 3 4 +1
=========================================
+ Hits 4061 4078 +17
+ Misses 2645 2628 -17
Partials 1 1
Continue to review full report at Codecov.
|
I did a bit of digging on that issue and got lost, do we want to treat: {
testMatch: ['...']
} The same as {
projects: [{
testMatch: ['...']
}]
} ? |
Yes, basically. I was thinking Jest should throw if there are ProjectConfig fields defined in the global config if there are one or more projects defined. In absence of a collision, it should just run whatever is specified in the projects settings. To sum up:
@SimenB any thoughts? |
I think we need to go through what's in Should we go through the docs as well and specify what we consider global config and what we consider project config? Not sure how to best say it without confusing people who don't care about the difference as they don't use |
Alright, as a start, let’s just make sure a single project specified in the projects settings keeps working then :) |
packages/jest-config/src/index.js
Outdated
// Whether it needs to look into `--config` arg passed to CLI. | ||
// It only used to read initial config. If the initial config contains | ||
// `project` property, we don't want to read `--config` value and rather | ||
// read individual configs for every project. | ||
skipArgvConfigOption?: boolean, | ||
parentConfigPath?: ?Path, |
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.
what does ?
on both sides mean? From my understanding name: ?type
allows null
, undefined
or a value, while name?: type
allows undefined
or a value.
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'm not very proficient with Flow. I just added the ?
on the LHS to satisfy the checker. Maybe I can remove the one left, but the property is optional so I think I'll get an error when it's not explicitly passed.
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.
Yeah, I think so 🙂
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.
Removing it worked.
packages/jest-config/src/index.js
Outdated
rawOptions = packageRootOrConfig; | ||
rawOptions.rootDir = parentConfigPath; | ||
} else { | ||
throw new Error( |
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 we have a test for this (mostly for coverage)?
@@ -166,10 +185,3 @@ const getConfigs = ( | |||
}), | |||
}; | |||
}; | |||
|
|||
module.exports = { |
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.
is this on purpose?
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.
Yes it is, you export
instead. Cool! 🙂
Yes I know, I still need to investigate a fix for the issue mentioned above |
expect(stdout).toEqual(''); | ||
}); | ||
|
||
test('allows a single project', () => { |
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 test passes. Is there another case that needs to be accounted for?
}); | ||
|
||
const {stdout, stderr} = runJest(DIR); | ||
expect(stderr).toContain('Test Suites: 2 passed, 2 total'); |
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 realize this probably follows the pattern of the other tests here, but could you use extractSummary
from utils
and use a snapshot? You get back both summary
and rest
from it with timestamps stripped
Also, just a quick status === 0
check would be nice
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.
Cool, will do.
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.
Code LGTM 🙂
Can you update the documentation as well?
https://github.com/facebook/jest/blob/97ee7c985bcafdc0ac203ba443a5fb791fbc3b5d/docs/Configuration.md#projects-array
Is the |
Seems like #4240 did not include docs. Feel free to add them 😀 |
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 great, thanks!
@azz This is really solid work, thanks so much for this PR. This is such a nice little tweak that’s going to make the multi project runner much more approachable. I’m hoping to see more PRs from you that meaningfully extend Jest with new features. |
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
Closes #5174
Test plan
Added an integration test. Happy to add more if you can think of edge cases.