-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(testing): handle existing jest preset file correctly (#23437)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #20449
- Loading branch information
1 parent
937019b
commit 217a349
Showing
17 changed files
with
130 additions
and
72 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { nxPreset } from './preset/jest-preset'; | ||
|
||
export { nxPreset }; | ||
|
||
export default nxPreset; |
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
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
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
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
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
6 changes: 3 additions & 3 deletions
6
packages/jest/src/generators/configuration/lib/update-jestconfig.ts
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
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
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,49 @@ | ||
import { readJson, type Tree } from '@nx/devkit'; | ||
|
||
export const jestConfigExtensions = [ | ||
'js', | ||
'ts', | ||
'mjs', | ||
'cjs', | ||
'mts', | ||
'cts', | ||
] as const; | ||
export type JestConfigExtension = typeof jestConfigExtensions[number]; | ||
|
||
export const jestPresetExtensions = ['js', 'cjs', 'mjs'] as const; | ||
export type JestPresetExtension = typeof jestPresetExtensions[number]; | ||
|
||
export function getPresetExt(tree: Tree): JestPresetExtension { | ||
const ext = jestPresetExtensions.find((ext) => | ||
tree.exists(`jest.preset.${ext}`) | ||
); | ||
|
||
if (ext) { | ||
return ext; | ||
} | ||
|
||
const rootPkgJson = readJson(tree, 'package.json'); | ||
if (rootPkgJson.type && rootPkgJson.type === 'module') { | ||
// use cjs if package.json type is module | ||
return 'cjs'; | ||
} | ||
|
||
// default to js | ||
return 'js'; | ||
} | ||
|
||
export function findRootJestConfig(tree: Tree): string | null { | ||
const ext = jestConfigExtensions.find((ext) => | ||
tree.exists(`jest.config.${ext}`) | ||
); | ||
|
||
return ext ? `jest.config.${ext}` : null; | ||
} | ||
|
||
export function findRootJestPreset(tree: Tree): string | null { | ||
const ext = jestPresetExtensions.find((ext) => | ||
tree.exists(`jest.preset.${ext}`) | ||
); | ||
|
||
return ext ? `jest.preset.${ext}` : null; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
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
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
2 changes: 1 addition & 1 deletion
2
packages/node/src/generators/e2e-project/files/server/common/jest.config.ts__tmpl__
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
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