diff --git a/examples/example-app-monorepo/jest-esm-isolated.config.mjs b/examples/example-app-monorepo/jest-esm-isolated.config.mjs index dacac5dd8c..ae95fa6c5f 100644 --- a/examples/example-app-monorepo/jest-esm-isolated.config.mjs +++ b/examples/example-app-monorepo/jest-esm-isolated.config.mjs @@ -5,7 +5,7 @@ globalThis.ngJest = { /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ const jestConfig = { - globalSetup: 'jest-preset-angular/global-setup', + globalSetup: 'jest-preset-angular/global-setup.mjs', projects: ['/apps/app1/jest-esm-isolated.config.mjs', '/libs/user/jest-esm-isolated.config.mjs'], }; diff --git a/examples/example-app-monorepo/jest-esm.config.mjs b/examples/example-app-monorepo/jest-esm.config.mjs index 313224f936..c0f44d23e0 100644 --- a/examples/example-app-monorepo/jest-esm.config.mjs +++ b/examples/example-app-monorepo/jest-esm.config.mjs @@ -5,7 +5,7 @@ globalThis.ngJest = { /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ const jestConfig = { - globalSetup: 'jest-preset-angular/global-setup', + globalSetup: 'jest-preset-angular/global-setup.mjs', projects: ['/apps/app1/jest-esm.config.mjs', '/libs/user/jest-esm.config.mjs'], }; diff --git a/examples/example-app-v12/jest-esm.config.mjs b/examples/example-app-v12/jest-esm.config.mjs index e5fbc86bda..6811e85138 100644 --- a/examples/example-app-v12/jest-esm.config.mjs +++ b/examples/example-app-v12/jest-esm.config.mjs @@ -14,7 +14,7 @@ const jestConfig = { tsconfig: '/tsconfig-esm.spec.json', }, }, - globalSetup: 'jest-preset-angular/global-setup', + globalSetup: 'jest-preset-angular/global-setup.mjs', setupFilesAfterEnv: ['/setup-jest-esm.ts'], } diff --git a/examples/example-app-v13/jest-esm.config.mjs b/examples/example-app-v13/jest-esm.config.mjs index 9c654c3611..161e15301f 100644 --- a/examples/example-app-v13/jest-esm.config.mjs +++ b/examples/example-app-v13/jest-esm.config.mjs @@ -14,7 +14,7 @@ const jestConfig = { tsconfig: '/tsconfig-esm.spec.json', }, }, - globalSetup: 'jest-preset-angular/global-setup', + globalSetup: 'jest-preset-angular/global-setup.mjs', moduleNameMapper: { tslib: 'tslib/tslib.es6.js', rxjs: '/node_modules/rxjs/dist/bundles/rxjs.umd.js', diff --git a/examples/example-app-v14/jest-esm.config.mjs b/examples/example-app-v14/jest-esm.config.mjs index 9c654c3611..161e15301f 100644 --- a/examples/example-app-v14/jest-esm.config.mjs +++ b/examples/example-app-v14/jest-esm.config.mjs @@ -14,7 +14,7 @@ const jestConfig = { tsconfig: '/tsconfig-esm.spec.json', }, }, - globalSetup: 'jest-preset-angular/global-setup', + globalSetup: 'jest-preset-angular/global-setup.mjs', moduleNameMapper: { tslib: 'tslib/tslib.es6.js', rxjs: '/node_modules/rxjs/dist/bundles/rxjs.umd.js', diff --git a/examples/example-app-yarn-workspace/packages/angular-app/jest-esm.config.mjs b/examples/example-app-yarn-workspace/packages/angular-app/jest-esm.config.mjs index 98442e606a..0393c066ca 100644 --- a/examples/example-app-yarn-workspace/packages/angular-app/jest-esm.config.mjs +++ b/examples/example-app-yarn-workspace/packages/angular-app/jest-esm.config.mjs @@ -14,7 +14,7 @@ const jestConfig = { tsconfig: '/tsconfig-esm.spec.json', }, }, - globalSetup: 'jest-preset-angular/global-setup', + globalSetup: 'jest-preset-angular/global-setup.mjs', moduleNameMapper: { tslib: 'tslib/tslib.es6.js', rxjs: '/../../node_modules/rxjs/dist/bundles/rxjs.umd.js', diff --git a/examples/example-app-yarn-workspace/packages/user/jest-esm.config.mjs b/examples/example-app-yarn-workspace/packages/user/jest-esm.config.mjs index 98442e606a..0393c066ca 100644 --- a/examples/example-app-yarn-workspace/packages/user/jest-esm.config.mjs +++ b/examples/example-app-yarn-workspace/packages/user/jest-esm.config.mjs @@ -14,7 +14,7 @@ const jestConfig = { tsconfig: '/tsconfig-esm.spec.json', }, }, - globalSetup: 'jest-preset-angular/global-setup', + globalSetup: 'jest-preset-angular/global-setup.mjs', moduleNameMapper: { tslib: 'tslib/tslib.es6.js', rxjs: '/../../node_modules/rxjs/dist/bundles/rxjs.umd.js', diff --git a/global-setup.js b/global-setup.js index e34577ea79..aa32b5bc70 100644 --- a/global-setup.js +++ b/global-setup.js @@ -1 +1 @@ -module.exports = require('./build/config/global-setup'); +module.exports = require('./build/config/global-setup').globalSetup; diff --git a/global-setup.mjs b/global-setup.mjs new file mode 100644 index 0000000000..6564ceaa39 --- /dev/null +++ b/global-setup.mjs @@ -0,0 +1,3 @@ +import { globalSetup } from './build/config/global-setup.js'; + +export default globalSetup; diff --git a/scripts/test-examples.js b/scripts/test-examples.js index 41b39a406f..0d21156f6f 100755 --- a/scripts/test-examples.js +++ b/scripts/test-examples.js @@ -35,13 +35,20 @@ const executeTest = (projectPath) => { logger.log('installing bundled version of jest-preset-angular'); logger.log(); - ['build', 'presets', 'global-setup.js', 'jest-preset.js', 'package.json', 'setup-jest.js', 'setup-jest.mjs'].forEach( - (asset) => { - const assetToReplace = join(projectPath, 'node_modules', 'jest-preset-angular', asset); - const assetToCopy = join(rootDir, asset); - copySync(assetToCopy, assetToReplace, {}); - } - ); + [ + 'build', + 'presets', + 'global-setup.js', + 'global-setup.mjs', + 'jest-preset.js', + 'package.json', + 'setup-jest.js', + 'setup-jest.mjs', + ].forEach((asset) => { + const assetToReplace = join(projectPath, 'node_modules', 'jest-preset-angular', asset); + const assetToCopy = join(rootDir, asset); + copySync(assetToCopy, assetToReplace, {}); + }); // then we can run the tests const cmdLine = ['yarn', 'test']; diff --git a/src/config/global-setup.spec.ts b/src/config/global-setup.spec.ts index 9c54f24b32..fdfa72fd38 100644 --- a/src/config/global-setup.spec.ts +++ b/src/config/global-setup.spec.ts @@ -1,4 +1,4 @@ -import globalSetup from './global-setup'; +import { globalSetup } from './global-setup'; jest.mock('../utils/ngcc-jest-processor', () => { return { diff --git a/src/config/global-setup.ts b/src/config/global-setup.ts index 08a38d28cb..f6b084ef32 100644 --- a/src/config/global-setup.ts +++ b/src/config/global-setup.ts @@ -1,11 +1,9 @@ import { runNgccJestProcessor } from '../utils/ngcc-jest-processor'; -const globalSetup = async () => { +export const globalSetup = async () => { const ngJestConfig = globalThis.ngJest; const tsconfig = ngJestConfig?.tsconfig; if (!ngJestConfig?.skipNgcc) { runNgccJestProcessor(tsconfig); } }; - -export default globalSetup;