-
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
- Loading branch information
1 parent
b164569
commit 3c9f996
Showing
18 changed files
with
132 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
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
Oops, something went wrong.