-
-
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
Keep ARGV only in CLI files #4012
Conversation
6b28cf2
to
90ab5f1
Compare
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.
it also greatly simplifies the argument flow of jest.
we don't need to pass testPathPattern
, testNamePattern
and testPattern
as a string throughout the flow.
and we don't need TestSelectionConfig
any more, since it was a derived data structure
@@ -97,7 +77,7 @@ exports[`Custom Reporters Integration default reporters enabled 2`] = ` | |||
Tests: 1 passed, 1 total | |||
Snapshots: 0 total | |||
Time: <<REPLACED>> | |||
Ran all test suites matching \\"add.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.
as discussed in #4006 this now prints the pattern instead of mix of pattern+raw input
@@ -4,7 +4,7 @@ exports[`Watch mode flows Runs Jest once by default and shows usage 1`] = ` | |||
Array [ | |||
" | |||
Watch Usage | |||
› Press o to only run tests related to changed files. | |||
› Press a to run all tests. |
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 not the actual behavior change, rather the test change because of different default mock value
@@ -228,5 +228,3 @@ exports[`Watch mode flows Results in pattern mode get truncated appropriately 2` | |||
[MOCK - cursorTo(12, 5)] | |||
[MOCK - cursorRestorePosition]" | |||
`; | |||
|
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 used a direct comparison here instead of snapshot
@@ -1,73 +0,0 @@ | |||
/** |
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 don't need this data structure any more, since all needed data can be taken from globalConfig
now
packages/jest-cli/src/run_jest.js
Outdated
updateArgv(argv, 'watchAll', {noSCM: true}); | ||
testSelectionConfig = getTestSelectionConfig(argv); | ||
data = await source.getTestPaths(testSelectionConfig); | ||
// updateArgv(argv, 'watchAll', {noSCM: 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.
this line seems to be noop now, but i wasn't 100% sure, i'll follow up.
(we might be missing a test case that tests this behavior)
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 sure that I understand why this is not needed anymore
* @flow | ||
*/ | ||
|
||
module.exports = (testPathPattern: string) => new RegExp(testPathPattern, 'i'); |
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.
since we serialize/deserialize patterns when we spawn workers, i chose to have a single function that can produce consistent result on both sides (probably should put it in a comment in this file)
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 like this one
packages/jest-cli/src/watch.js
Outdated
@@ -22,7 +21,8 @@ import isValidPath from './lib/is_valid_path'; | |||
import preRunMessage from './pre_run_message'; | |||
import createContext from './lib/create_context'; | |||
import runJest from './run_jest'; | |||
import updateArgv from './lib/update_argv'; | |||
// import updateArgv from './lib/update_argv'; |
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.
TODO: remove
packages/jest-config/src/index.js
Outdated
noStackTrace: options.noStackTrace, | ||
nonFlagArgs: options.nonFlagArgs, |
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.
the value of ARGV._
with a normal name
packages/jest-config/src/index.js
Outdated
logHeapUsage: options.logHeapUsage, | ||
mapCoverage: options.mapCoverage, | ||
maxWorkers: options.maxWorkers, | ||
noSCM: undefined, |
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 one is complicated, because we only know its value after we searched for tests (jest-changed-files
).
currently in Jest master we modify globalConfig
after we get the result and i think this is not a good pattern.
I think we should split runJest
function into two and run them sequentially:
const globalConfig = readConfig(...);
const {noSCM, tests} = findTests(globalConfig);
globalConfig.noSCM = noSCM;
globalConfig.somethingElse = ... // there's a few modifications that we're already doing in runJest
Object.freeze(globalConfig); // at this point config is immutable. no hacks
runJest(globalConfig);
newOptions.nonFlagArgs = argv._; | ||
newOptions.testPathPattern = buildTestPathPattern(argv); | ||
newOptions.json = argv.json; | ||
newOptions.lastCommit = argv.lastCommit; |
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 sure if it's the right way to do it. Adding these values to the switch block above leaves them undefined
I don't think I agree that this many new options have to be added to GlobalConfig. To keep this manageable, given that they all mostly belong to one or two features, I'd recommend grouping them in one or two objects within GlobalConfig instead. What do you think? |
@cpojer i don't think we should go this way honestly. if we do want to move to grouped configs, a can see it as globalConfig: {
testSelection: {testPathPattern: ..., testNamePattern: ..., ...},
runnerOptions: {onlyChanged: ..., bail: ..., maxWorkers: ...},
coverage: {threshold: ..., coverageIgnorePatterns: ...},
// ...
} but then you have to decide whether so basically my thoughts are - if we start grouping options together, there's no good convention or rule of how to group them and it will eventually become very confusing :( |
6ad5483
to
6e56c6e
Compare
Codecov Report
@@ Coverage Diff @@
## master #4012 +/- ##
==========================================
+ Coverage 60.31% 60.39% +0.07%
==========================================
Files 196 196
Lines 6761 6754 -7
Branches 6 6
==========================================
+ Hits 4078 4079 +1
+ Misses 2680 2672 -8
Partials 3 3
Continue to review full report at Codecov.
|
\\"path\\": false | ||
}, | ||
\\"options\\": { | ||
\\"Dmitrii Abramov\\": \\"Awesome\\" |
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.
lol
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.
probably needs to be updated too :D
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.
Spare that for another PR :p
globalConfig, | ||
mode, | ||
options, | ||
}: { |
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's not so many options here, so maybe we can switch to function arguments instead of destructuring? We could avoid duplicating the names in type def.
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.
it was just arguments before, but there's a lot of calls with either mode
or options
undefined, so it became
updateGlobalConfig(globalConfig, null, options)
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.
actually you're right, i don't see any reason to keep it two separate arguments. i'll just merge them into
updateGlobalConfig(globalConfig: GlobalConfig, options: Options);
packages/jest-cli/src/cli/index.js
Outdated
@@ -263,7 +263,6 @@ const _run = async ( | |||
|
|||
argv.watch || argv.watchAll |
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.
should be taken from globalConfig
now?
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 wow... i didn't notice this. This simplifies things even further. All of those functions don't need argv
any more. (and flow didn't catch that again) :)
packages/jest-cli/src/watch.js
Outdated
updateArgv(argv, argv.watch ? 'watch' : 'watchAll', { | ||
testNamePattern: argv.testNamePattern, | ||
testPathPattern: argv.testPathPattern || (argv._ || []).join('|'), | ||
}); |
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.
Because of lack of this update logic, globalConfig.onlyChanged
is not updated properly on the first run, resulting in tests being run, despite there's nothing changed in git.
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.
good catch! adding it back (although updating onlyChanged
implicitly seems like something we should fix in the future)
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.
Fix the bug with watch mode I mentioned in comments and I think this is good to go. Looks good to me for now.
I'd like it if we could keep "testSelection" as a globalConfig param. Just to double check, these args are not part of InitialOptions, therefore cannot be specified in a configuration file, right? I think that's the right way to go for these, there is never a time when hardcoding the test selection makes sense imho. |
@cpojer test selection config was completely derived data that duplicated
what global config already had. with this PR we mutate global config
directly, and there's no way to bring teat selection back :(
teat selection config was the reason why i couldn't implement "-all".
because both globalConfig and teatSelectionConfig had 'onlyChanged"
property, and i couldn't mutate both
…On Thu, Jul 13, 2017 at 2:57 AM Christoph Nakazawa ***@***.***> wrote:
I'd like it if we could keep "testSelection" as a globalConfig param.
Just to double check, these args are *not* part of InitialOptions,
therefore cannot be specified in a configuration file, right? I think
that's the right way to go for these, there is never a time when hardcoding
the test selection makes sense imho.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#4012 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AA5YZYCl48luPNOqmczBCNh-xqdZKvgcks5sNeoGgaJpZM4OU6l0>
.
|
Ok, you convinced me. No mutations, though, only copying! |
yeah. that's what i meant :)
…On Thu, Jul 13, 2017 at 7:27 AM Christoph Nakazawa ***@***.***> wrote:
Ok, you convinced me. No mutations, though, only copying!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#4012 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AA5YZe5IvtjbX9ONSC1lUcPQJRKqwGLJks5sNilOgaJpZM4OU6l0>
.
|
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.
Nice clean up, watch mode looks good to me... Just some really minor comments
@@ -22,10 +22,11 @@ jest.doMock( | |||
() => | |||
function() { | |||
const args = Array.from(arguments); | |||
const {onComplete} = args[0]; |
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.
Super nit: couldn't this be const [onComplete] = args
?
options?: Options, | ||
}): GlobalConfig => { | ||
// $FlowFixMe Object.assign | ||
const newConfig: GlobalConfig = Object.assign({}, globalConfig); |
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.
Nice, we are not mutating it any more!
packages/jest-cli/src/run_jest.js
Outdated
updateArgv(argv, 'watchAll', {noSCM: true}); | ||
testSelectionConfig = getTestSelectionConfig(argv); | ||
data = await source.getTestPaths(testSelectionConfig); | ||
// updateArgv(argv, 'watchAll', {noSCM: 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.
I'm not sure that I understand why this is not needed anymore
* @flow | ||
*/ | ||
|
||
module.exports = (testPathPattern: string) => new RegExp(testPathPattern, 'i'); |
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 like this one
6e56c6e
to
942dde3
Compare
ok. seems like i addressed them all! |
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. |
right now we're passing both ARGV and globalConfig all the way down to test runner. Also we mutate both of them as we pass it down (
globalConfig
is frozen, but we clone it instead of directly mutating).This PR separates ARGV from globalObject and makes it that ARGV is only used in CLI context (ARGV only represents the actual passed arguments to CLI now).
globalObject
is still mutable (frozen, but rewritten) and i believe Jest workflow suggests that it should be this way. For example, when we run--watch
mode, user's interactions changeglobalConfig
and then we re-run Jest with the new config.cc @rogeliog for watch stuff