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

Strict and explicit config resolution logic #4083

Closed
wants to merge 1 commit into from

Conversation

aaronabramov
Copy link
Contributor

This was one of the most confusing thing about MPR.
given an invalid path in a projects config property:

// package.json
projects: [
  'project1',
  'project2',
  'some_non_existing_thing',
]

current version of Jest would just either ignore this path completely and remove it from the project list, or, even worse, resolve back to the exact same package.json and try to run a project with all -test.js files from all the projects using the default configuration.

This PR:

  • guards agains having two projects resolve to the same config file
  • guards agains trying to specify a non-existing file or directory as a config
  • rewrites resolution logic and ads a bunch of tests

the only part that is lost is the ability to specify projects by a glob

projects: ['examples/*']

but i think this isn't a good use of globs and we don't even use it for our examples either. Anything that needs dynamic project list can use a .js based config and run glob explicitly.

If we still want to keep glob functionality, we should at least enforce that every glob resolves into at least one match.

@@ -61,7 +61,7 @@ export type DefaultOptions = {|
watchman: boolean,
|};

export type InitialOptions = {|
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this object is not supposed to be exact. It comes from the config file that can have anything in it. We guard against unrecognized options in jest-validate package.

snapshotSerializers?: Array<Path>,
testEnvironment?: string,
testFailureExitCode?: string | number,
testMatch?: Array<Glob>,
testNamePattern?: string,
testPathIgnorePatterns?: Array<string>,
testPathDirs?: Array<Path>,
Copy link
Contributor Author

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 deprecated or missing.
After properly typing this object, flow found that we use this property in the code but it was not present in this type

@codecov-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@e8ed43e). Click here to learn what that means.
The diff coverage is 42.1%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #4083   +/-   ##
=========================================
  Coverage          ?   60.65%           
=========================================
  Files             ?      197           
  Lines             ?     6781           
  Branches          ?        6           
=========================================
  Hits              ?     4113           
  Misses            ?     2665           
  Partials          ?        3
Impacted Files Coverage Δ
...st-config/src/read_config_file_and_set_root_dir.js 0% <0%> (ø)
packages/jest-config/src/normalize.js 79.12% <0%> (ø)
packages/jest-config/src/index.js 0% <0%> (ø)
packages/jest-config/src/constants.js 100% <100%> (ø)
packages/jest-config/src/resolve_config_path.js 95.65% <95.65%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e8ed43e...1cc00a2. Read the comment docs.

@cpojer
Copy link
Member

cpojer commented Jul 20, 2017

Please bring back the glob functionality, that should definitely be part of the feature and I don't want to break it. I'm ok with the added validation otherwise.

@@ -153,6 +153,29 @@ const _printVersionAndExit = outputStream => {
process.exit(0);
};

const _ensureProjectsDontUseTheSameConfig = (parsedConfigs, projects) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Dont" just really doesn't fit into code. How about:

  • ensureDifferentConfigFiles
  • ensureDiverseConfigFiles

or something similar?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensureNoDuplicateConfig?

@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants