-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
feat: warn when there are multiple configs #11922
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
Merged
SimenB
merged 41 commits into
jestjs:main
from
jankaifer:jankaifer/warn-multiple-configs-found
Oct 6, 2021
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
b85b26b
chore: throw when there are multiple configs
jankaifer 4dff740
fix: allowed package.json without 'jest' as valid config
jankaifer 227f7d4
test: unit test for multiple configs error in resolver
jankaifer a678d28
Apply suggestions from code review
jankaifer 0f81fe4
test: fixed integration test
jankaifer b6ff8b8
tests: fixed config issues in old tests
jankaifer 27fdaff
feat: multiple jest.config.ext files are not allowed
jankaifer 0d15a1f
test: added e2e test for --config override
jankaifer eccf953
fix: more explicit expression
jankaifer 3d71585
fix: added more real-life package.json example
jankaifer 4cca511
Merge branch 'jankaifer/warn-multiple-configs-found' of github.com:Ja…
jankaifer 752b1f9
test: added snapshot tests for multiple errors
jankaifer 02b8ef2
test: moved snapshots from unit tests to e2e tests
jankaifer cd7c9c9
test: fixed rootDir replacements in snapshots
jankaifer 9e13ff2
Apply suggestions from code review
jankaifer f30ab95
added missing import
jankaifer b931029
Change from CR
jankaifer f9c515e
improved error message
jankaifer 3b1c5b8
added test for --config error surpresion
jankaifer 02338fd
added more real life package.json
jankaifer 2ce0401
added more assertions for multiple config errors
jankaifer ac00510
improved formatting of error message
jankaifer 82d3e44
fixed sample jest configs in e2e tests
jankaifer db8c90c
wip: changed from error to warning
jankaifer ab05377
fixed unit tests for warning
jankaifer df0f3a5
updated snapshots
jankaifer 1f17acc
Update CHANGELOG.md
SimenB 2d6efff
Update packages/jest-config/src/resolveConfigPath.ts
jankaifer 3682947
Merge branch 'main' into jankaifer/warn-multiple-configs-found
SimenB 7727e74
add slash import
SimenB 9926edf
no flat in node 10
SimenB 91655ce
rename tests
SimenB d60356f
slash path in e2e test as well
SimenB 6a52634
skip duplicate warning
SimenB 3505a2c
add copyright header
SimenB 80e52de
make warning yellow
SimenB 8abb1c1
specify key in pkg.json
SimenB 746f353
use wrap
SimenB cae826c
removed hardcoded filename
jankaifer 1de582b
made skipMultipleConfigWarning optional
jankaifer b57cbf5
Update packages/jest-config/src/resolveConfigPath.ts
SimenB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`multiple configs will warn 1`] = ` | ||
● Multiple configurations found: | ||
* <rootDir>/e2e/multiple-configs/jest.config.js | ||
* <rootDir>/e2e/multiple-configs/jest.config.json | ||
* \`jest\` key in <rootDir>/e2e/multiple-configs/package.json | ||
|
||
Implicit config resolution does not allow multiple configuration files. | ||
Either remove unused config files or select one explicitly with \`--config\`. | ||
|
||
Configuration Documentation: | ||
https://jestjs.io/docs/configuration.html | ||
|
||
PASS Config from js file __tests__/test.js | ||
✓ dummy test | ||
`; | ||
|
||
exports[`multiple configs will warn 2`] = ` | ||
Test Suites: 1 passed, 1 total | ||
Tests: 1 passed, 1 total | ||
Snapshots: 0 total | ||
Time: <<REPLACED>> | ||
Ran all test suites. | ||
`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {getConfig} from '../runJest'; | ||
|
||
test('reads config from cjs file', () => { | ||
const {configs} = getConfig( | ||
'config-override', | ||
['--config', 'different-config.json'], | ||
{ | ||
skipPkgJsonCheck: true, | ||
}, | ||
); | ||
|
||
expect(configs).toHaveLength(1); | ||
expect(configs[0].displayName).toEqual({ | ||
color: 'white', | ||
name: 'Config from different-config.json file', | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import * as path from 'path'; | ||
import {wrap} from 'jest-snapshot-serializer-raw'; | ||
import slash = require('slash'); | ||
import {extractSummary} from '../Utils'; | ||
import runJest from '../runJest'; | ||
|
||
const MULTIPLE_CONFIGS_WARNING_TEXT = 'Multiple configurations found'; | ||
|
||
test('multiple configs will warn', () => { | ||
const rootDir = slash(path.resolve(__dirname, '../..')); | ||
const {exitCode, stderr} = runJest('multiple-configs', [], { | ||
skipPkgJsonCheck: true, | ||
}); | ||
|
||
expect(exitCode).toBe(0); | ||
expect(stderr).toContain(MULTIPLE_CONFIGS_WARNING_TEXT); | ||
|
||
const cleanStdErr = stderr.replace(new RegExp(rootDir, 'g'), '<rootDir>'); | ||
const {rest, summary} = extractSummary(cleanStdErr); | ||
|
||
expect(wrap(rest)).toMatchSnapshot(); | ||
expect(wrap(summary)).toMatchSnapshot(); | ||
}); | ||
|
||
test('multiple configs warning can be suppressed by using --config', () => { | ||
const {exitCode, stderr} = runJest( | ||
'multiple-configs', | ||
['--config', 'jest.config.json'], | ||
{ | ||
skipPkgJsonCheck: true, | ||
}, | ||
); | ||
|
||
expect(exitCode).toBe(0); | ||
SimenB marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(stderr).not.toContain(MULTIPLE_CONFIGS_WARNING_TEXT); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
test('dummy test', () => { | ||
expect(1).toBe(1); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"displayName": "Config from different-config.json file" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"displayName": "Config from json file" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "config-override" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"jest": {} | ||
SimenB marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"name": "cjs-config" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"jest": {} | ||
"name": "mjs-config" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
test('dummy test', () => { | ||
expect(1).toBe(1); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
module.exports = { | ||
displayName: 'Config from js file', | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"displayName": "Config from json file" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"jest": { | ||
"displayName": "Config from package.json file" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.