forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ignore custom Jest configuration file and warn if one is found
Currently with Jest we're experimenting with whether or not Angular CLI can meet user needs without exposing the underlying configuration file. See angular#25434 (comment) for more context. Jest was incorrectly picking up custom configurations, even though they exist outside Jest's root directory. This commit fixes that behavior so Jest does not see user configurations and does not apply them. Ideally we would throw an error if a Jest configuration is found to be more clear that it isn't doing what developers expect. However they may use a Jest config to run other projects in the same workspace outside of Angular CLI and we don't want to prevent that. A warning seems like the best trade off of notifying users that a custom config isn't supported while also not preventing unrelated Jest usage in the same workspace.
- Loading branch information
Showing
3 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
11 changes: 11 additions & 0 deletions
11
packages/angular_devkit/build_angular/src/builders/jest/jest.config.mjs
This file contains 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,11 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
// Empty config file, everything is specified via CLI options right now. | ||
// This file is used just so Jest doesn't accidentally inherit a custom user-specified Jest config. | ||
export default {}; |
This file contains 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 @@ | ||
import { writeFile } from '../../utils/fs'; | ||
import { applyJestBuilder } from '../../utils/jest'; | ||
import { ng } from '../../utils/process'; | ||
|
||
export default async function (): Promise<void> { | ||
await applyJestBuilder(); | ||
|
||
// Users may incorrectly write a Jest config believing it to be used by Angular. | ||
await writeFile( | ||
'jest.config.mjs', | ||
` | ||
export default { | ||
runner: 'does-not-exist', | ||
}; | ||
`.trim(), | ||
); | ||
|
||
// Should not fail from the above (broken) configuration. Shouldn't use it at all. | ||
const { stderr } = await ng('test'); | ||
|
||
// Should warn that a Jest configuration was found but not used. | ||
if (!stderr.includes('A custom Jest config was found')) { | ||
throw new Error(`No warning about custom Jest config:\nSTDERR:\n\n${stderr}`); | ||
} | ||
} |