diff --git a/e2e/ast-transformers/hoisting/jest-isolated.config.js b/e2e/ast-transformers/hoisting/jest-isolated.config.js index 307dd460ab..a0bd8876cd 100644 --- a/e2e/ast-transformers/hoisting/jest-isolated.config.js +++ b/e2e/ast-transformers/hoisting/jest-isolated.config.js @@ -2,9 +2,13 @@ const baseCfg = require('./jest.config'); module.exports = { ...baseCfg, - globals: { - 'ts-jest': { - isolatedModules: true, - }, + transform: { + ...baseCfg.transform, + '^.+\\.(ts|js|html)$': [ + '/../../../build/index.js', + { + isolatedModules: true, + }, + ], }, }; diff --git a/e2e/ast-transformers/ng-jit-transformers/jest-isolated.config.js b/e2e/ast-transformers/ng-jit-transformers/jest-isolated.config.js index 1ab56b5bf2..775f310b1a 100644 --- a/e2e/ast-transformers/ng-jit-transformers/jest-isolated.config.js +++ b/e2e/ast-transformers/ng-jit-transformers/jest-isolated.config.js @@ -2,10 +2,14 @@ const baseCfg = require('./jest.config'); module.exports = { ...baseCfg, - globals: { - 'ts-jest': { - ...baseCfg.globals['ts-jest'], - isolatedModules: true, - }, + transform: { + ...baseCfg.transform, + '^.+\\.(ts|js|mjs|html)$': [ + '/../../../build/index.js', + { + ...require('./ts-jest.config'), + isolatedModules: true, + }, + ], }, }; diff --git a/e2e/ast-transformers/ng-jit-transformers/jest.config.js b/e2e/ast-transformers/ng-jit-transformers/jest.config.js index 4fb8643027..9ed43311f8 100644 --- a/e2e/ast-transformers/ng-jit-transformers/jest.config.js +++ b/e2e/ast-transformers/ng-jit-transformers/jest.config.js @@ -1,14 +1,9 @@ module.exports = { - globals: { - 'ts-jest': { - stringifyContentPathRegex: '\\.html$', - }, - }, resolver: '/../../../build/resolvers/ng-jest-resolver', setupFilesAfterEnv: ['/../../../setup-jest.js'], testEnvironment: 'jsdom', transform: { - '^.+\\.(ts|js|mjs|html)$': '/../../../build/index.js', + '^.+\\.(ts|js|mjs|html)$': ['/../../../build/index.js', require('./ts-jest.config')], }, transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'], }; diff --git a/e2e/ast-transformers/ng-jit-transformers/ts-jest.config.js b/e2e/ast-transformers/ng-jit-transformers/ts-jest.config.js new file mode 100644 index 0000000000..98304ffbee --- /dev/null +++ b/e2e/ast-transformers/ng-jit-transformers/ts-jest.config.js @@ -0,0 +1,3 @@ +module.exports = { + stringifyContentPathRegex: '\\.html$', +}; diff --git a/e2e/async/jest-isolated.config.js b/e2e/async/jest-isolated.config.js index 1ab56b5bf2..547d113416 100644 --- a/e2e/async/jest-isolated.config.js +++ b/e2e/async/jest-isolated.config.js @@ -2,10 +2,14 @@ const baseCfg = require('./jest.config'); module.exports = { ...baseCfg, - globals: { - 'ts-jest': { - ...baseCfg.globals['ts-jest'], - isolatedModules: true, - }, + transform: { + ...baseCfg.transform, + '^.+\\.(ts|mjs|js|html)$': [ + '/../../build/index.js', + { + ...require('./ts-jest.config'), + isolatedModules: true, + }, + ], }, }; diff --git a/e2e/async/jest.config.js b/e2e/async/jest.config.js index 0880455d20..4497f6c2f0 100644 --- a/e2e/async/jest.config.js +++ b/e2e/async/jest.config.js @@ -1,17 +1,9 @@ module.exports = { - globals: { - 'ts-jest': { - tsconfig: { - /** Angular doesn't work with ES2017+ - * see https://github.com/angular/components/issues/21632#issuecomment-764975917 - */ - target: 'ES2016', - }, - }, - }, resolver: '/../../build/resolvers/ng-jest-resolver', testEnvironment: 'jsdom', setupFilesAfterEnv: ['/../../setup-jest.js'], - transform: { '^.+\\.(ts|mjs|js|html)$': '/../../build/index.js' }, + transform: { + '^.+\\.(ts|mjs|js|html)$': ['/../../build/index.js', require('./ts-jest.config')], + }, transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'], }; diff --git a/e2e/async/ts-jest.config.js b/e2e/async/ts-jest.config.js new file mode 100644 index 0000000000..efd38f9218 --- /dev/null +++ b/e2e/async/ts-jest.config.js @@ -0,0 +1,8 @@ +module.exports = { + tsconfig: { + /** Angular doesn't work with ES2017+ + * see https://github.com/angular/components/issues/21632#issuecomment-764975917 + */ + target: 'ES2016', + }, +}; diff --git a/e2e/babel-support/jest-isolated.config.js b/e2e/babel-support/jest-isolated.config.js index 1ab56b5bf2..631a734947 100644 --- a/e2e/babel-support/jest-isolated.config.js +++ b/e2e/babel-support/jest-isolated.config.js @@ -1,11 +1,11 @@ -const baseCfg = require('./jest.config'); - module.exports = { - ...baseCfg, - globals: { - 'ts-jest': { - ...baseCfg.globals['ts-jest'], - isolatedModules: true, - }, + transform: { + '^.+\\.(ts|js|html)$': [ + '/../../build/index.js', + { + ...require('./ts-jest.config'), + isolatedModules: true, + }, + ], }, }; diff --git a/e2e/babel-support/jest.config.js b/e2e/babel-support/jest.config.js index e6573f5087..c4772e30a8 100644 --- a/e2e/babel-support/jest.config.js +++ b/e2e/babel-support/jest.config.js @@ -1,10 +1,5 @@ module.exports = { - globals: { - 'ts-jest': { - babelConfig: true, - }, - }, transform: { - '^.+\\.(ts|js|html)$': '/../../build/index.js', + '^.+\\.(ts|js|html)$': ['/../../build/index.js', require('./ts-jest.config')], }, }; diff --git a/e2e/babel-support/ts-jest.config.js b/e2e/babel-support/ts-jest.config.js new file mode 100644 index 0000000000..be485235a4 --- /dev/null +++ b/e2e/babel-support/ts-jest.config.js @@ -0,0 +1,3 @@ +module.exports = { + babelConfig: true, +}; diff --git a/e2e/custom-typings/jest-isolated.config.js b/e2e/custom-typings/jest-isolated.config.js index 307dd460ab..27fb845f1e 100644 --- a/e2e/custom-typings/jest-isolated.config.js +++ b/e2e/custom-typings/jest-isolated.config.js @@ -2,9 +2,12 @@ const baseCfg = require('./jest.config'); module.exports = { ...baseCfg, - globals: { - 'ts-jest': { - isolatedModules: true, - }, + transform: { + '^.+\\.(ts|js|html)$': [ + '/../../build/index.js', + { + isolatedModules: true, + }, + ], }, }; diff --git a/e2e/full-ivy-lib/jest-isolated.config.js b/e2e/full-ivy-lib/jest-isolated.config.js index 307dd460ab..e7f0bbf6b5 100644 --- a/e2e/full-ivy-lib/jest-isolated.config.js +++ b/e2e/full-ivy-lib/jest-isolated.config.js @@ -2,9 +2,13 @@ const baseCfg = require('./jest.config'); module.exports = { ...baseCfg, - globals: { - 'ts-jest': { - isolatedModules: true, - }, + transform: { + ...baseCfg.transform, + '^.+\\.(ts|js|mjs|html)$': [ + '/../../build/index.js', + { + isolatedModules: true, + }, + ], }, }; diff --git a/e2e/jest-globals/jest-isolated.config.js b/e2e/jest-globals/jest-isolated.config.js index 307dd460ab..ebb43c08ba 100644 --- a/e2e/jest-globals/jest-isolated.config.js +++ b/e2e/jest-globals/jest-isolated.config.js @@ -2,9 +2,13 @@ const baseCfg = require('./jest.config'); module.exports = { ...baseCfg, - globals: { - 'ts-jest': { - isolatedModules: true, - }, + transform: { + ...baseCfg.transform, + '^.+\\.(ts|js|html)$': [ + '/../../build/index.js', + { + isolatedModules: true, + }, + ], }, }; diff --git a/e2e/ng-deep-import/jest-isolated.config.js b/e2e/ng-deep-import/jest-isolated.config.js index 307dd460ab..e7f0bbf6b5 100644 --- a/e2e/ng-deep-import/jest-isolated.config.js +++ b/e2e/ng-deep-import/jest-isolated.config.js @@ -2,9 +2,13 @@ const baseCfg = require('./jest.config'); module.exports = { ...baseCfg, - globals: { - 'ts-jest': { - isolatedModules: true, - }, + transform: { + ...baseCfg.transform, + '^.+\\.(ts|js|mjs|html)$': [ + '/../../build/index.js', + { + isolatedModules: true, + }, + ], }, }; diff --git a/e2e/partial-ivy-lib/jest-isolated.config.js b/e2e/partial-ivy-lib/jest-isolated.config.js index 307dd460ab..e7f0bbf6b5 100644 --- a/e2e/partial-ivy-lib/jest-isolated.config.js +++ b/e2e/partial-ivy-lib/jest-isolated.config.js @@ -2,9 +2,13 @@ const baseCfg = require('./jest.config'); module.exports = { ...baseCfg, - globals: { - 'ts-jest': { - isolatedModules: true, - }, + transform: { + ...baseCfg.transform, + '^.+\\.(ts|js|mjs|html)$': [ + '/../../build/index.js', + { + isolatedModules: true, + }, + ], }, }; diff --git a/e2e/path-mapping/jest-isolated.config.js b/e2e/path-mapping/jest-isolated.config.js index 307dd460ab..ebb43c08ba 100644 --- a/e2e/path-mapping/jest-isolated.config.js +++ b/e2e/path-mapping/jest-isolated.config.js @@ -2,9 +2,13 @@ const baseCfg = require('./jest.config'); module.exports = { ...baseCfg, - globals: { - 'ts-jest': { - isolatedModules: true, - }, + transform: { + ...baseCfg.transform, + '^.+\\.(ts|js|html)$': [ + '/../../build/index.js', + { + isolatedModules: true, + }, + ], }, }; diff --git a/e2e/process-js-packages/jest-esm.config.mjs b/e2e/process-js-packages/jest-esm.config.mjs index 1168bdaddf..5ae7f347dc 100644 --- a/e2e/process-js-packages/jest-esm.config.mjs +++ b/e2e/process-js-packages/jest-esm.config.mjs @@ -1,14 +1,11 @@ export default { - extensionsToTreatAsEsm: ['.ts'], - globals: { - 'ts-jest': { - tsconfig: 'tsconfig-esm.spec.json', + extensionsToTreatAsEsm: [".ts"], + transform: { + "^.+\\.(ts|js)$": ["/../../build/index.js", { + tsconfig: "tsconfig-esm.spec.json", useESM: true, isolatedModules: true, - }, - }, - transform: { - '^.+\\.(ts|js)$': '/../../build/index.js', + }], }, moduleNameMapper: { '@googlemaps/markerclusterer': '@googlemaps/markerclusterer/dist/index.esm.js', diff --git a/e2e/process-js-packages/jest.config.js b/e2e/process-js-packages/jest.config.js index 24d7ce695e..ddc164c6ba 100644 --- a/e2e/process-js-packages/jest.config.js +++ b/e2e/process-js-packages/jest.config.js @@ -1,15 +1,17 @@ module.exports = { globals: { - 'ts-jest': { - tsconfig: 'tsconfig.spec.json', - isolatedModules: true, - }, ngJest: { processWithEsbuild: ['**/node_modules/lodash-es/*.js'], }, }, transform: { - '^.+\\.(ts|js|mjs)$': '/../../build/index.js', + '^.+\\.(ts|js|mjs)$': [ + '/../../build/index.js', + { + tsconfig: 'tsconfig.spec.json', + isolatedModules: true, + }, + ], }, transformIgnorePatterns: ['node_modules/(?!lodash-es)'], }; diff --git a/e2e/snapshot-serializers/jest-isolated.config.js b/e2e/snapshot-serializers/jest-isolated.config.js index 1ab56b5bf2..be1f7f3192 100644 --- a/e2e/snapshot-serializers/jest-isolated.config.js +++ b/e2e/snapshot-serializers/jest-isolated.config.js @@ -2,10 +2,13 @@ const baseCfg = require('./jest.config'); module.exports = { ...baseCfg, - globals: { - 'ts-jest': { - ...baseCfg.globals['ts-jest'], - isolatedModules: true, - }, + transform: { + '^.+\\.(ts|js|mjs|html)$': [ + '/../../build/index.js', + { + ...require('./ts-jest.config'), + isolatedModules: true, + }, + ], }, }; diff --git a/e2e/snapshot-serializers/jest.config.js b/e2e/snapshot-serializers/jest.config.js index 5912820ef6..934ced9eea 100644 --- a/e2e/snapshot-serializers/jest.config.js +++ b/e2e/snapshot-serializers/jest.config.js @@ -1,9 +1,4 @@ module.exports = { - globals: { - 'ts-jest': { - stringifyContentPathRegex: '\\.html$', - }, - }, resolver: '/../../build/resolvers/ng-jest-resolver', setupFilesAfterEnv: ['/../../setup-jest.js'], snapshotSerializers: [ @@ -13,7 +8,7 @@ module.exports = { ], testEnvironment: 'jsdom', transform: { - '^.+\\.(ts|js|mjs|html)$': '/../../build/index.js', + '^.+\\.(ts|js|mjs|html)$': ['/../../build/index.js', require('./ts-jest.config')], }, transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'], }; diff --git a/e2e/snapshot-serializers/ts-jest.config.js b/e2e/snapshot-serializers/ts-jest.config.js new file mode 100644 index 0000000000..98304ffbee --- /dev/null +++ b/e2e/snapshot-serializers/ts-jest.config.js @@ -0,0 +1,3 @@ +module.exports = { + stringifyContentPathRegex: '\\.html$', +}; diff --git a/examples/example-app-monorepo/apps/app1/jest-esm-isolated.config.mjs b/examples/example-app-monorepo/apps/app1/jest-esm-isolated.config.mjs index c6da7e4787..c0696cc27b 100644 --- a/examples/example-app-monorepo/apps/app1/jest-esm-isolated.config.mjs +++ b/examples/example-app-monorepo/apps/app1/jest-esm-isolated.config.mjs @@ -1,15 +1,18 @@ import jestCfg from './jest-esm.config.mjs'; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ const jestIsolatedCfg = { ...jestCfg, - globals: { - 'ts-jest': { - tsconfig: '/tsconfig-esm.spec.json', - stringifyContentPathRegex: '\\.(html|svg)$', - isolatedModules: true, - useESM: true, - }, + transform: { + '^.+\\.(ts|js|html|svg)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig-esm.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', + isolatedModules: true, + useESM: true, + }, + ], }, }; diff --git a/examples/example-app-monorepo/apps/app1/jest-esm.config.mjs b/examples/example-app-monorepo/apps/app1/jest-esm.config.mjs index ee72dffb61..329720d8f5 100644 --- a/examples/example-app-monorepo/apps/app1/jest-esm.config.mjs +++ b/examples/example-app-monorepo/apps/app1/jest-esm.config.mjs @@ -1,20 +1,24 @@ import ngPreset from 'jest-preset-angular/presets/index.js'; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ const jestConfig = { ...ngPreset.defaultsESM, displayName: 'app1', - globals: { - 'ts-jest': { - ...ngPreset.defaultsESM.globals["ts-jest"], - tsconfig: '/tsconfig-esm.spec.json', - }, - }, moduleNameMapper: { tslib: 'tslib/tslib.es6.js', rxjs: '/../../node_modules/rxjs/dist/bundles/rxjs.umd.js', }, setupFilesAfterEnv: ['/setup-jest-esm.ts'], -} + transform: { + '^.+\\.(ts|js|html|svg)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig-esm.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', + useESM: true, + }, + ], + }, +}; export default jestConfig; diff --git a/examples/example-app-monorepo/apps/app1/jest-isolated.config.js b/examples/example-app-monorepo/apps/app1/jest-isolated.config.js index a77e374423..e0eb05ff6d 100644 --- a/examples/example-app-monorepo/apps/app1/jest-isolated.config.js +++ b/examples/example-app-monorepo/apps/app1/jest-isolated.config.js @@ -1,13 +1,16 @@ const jestCfg = require('./jest.config'); +const { defaultTransformerOptions } = require('jest-preset-angular/presets'); -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ module.exports = { ...jestCfg, - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - stringifyContentPathRegex: '\\.(html|svg)$', - isolatedModules: true, - }, + transform: { + '^.+\\.(ts|js|mjs|html|svg)$': [ + 'jest-preset-angular', + { + ...defaultTransformerOptions, + isolatedModules: true, + }, + ], }, }; diff --git a/examples/example-app-monorepo/apps/app1/jest.config.js b/examples/example-app-monorepo/apps/app1/jest.config.js index b8082f8790..c770fafbd9 100644 --- a/examples/example-app-monorepo/apps/app1/jest.config.js +++ b/examples/example-app-monorepo/apps/app1/jest.config.js @@ -1,4 +1,4 @@ -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ module.exports = { displayName: 'app1', preset: 'jest-preset-angular', diff --git a/examples/example-app-monorepo/jest-esm-isolated.config.mjs b/examples/example-app-monorepo/jest-esm-isolated.config.mjs index ae95fa6c5f..7b66b0774a 100644 --- a/examples/example-app-monorepo/jest-esm-isolated.config.mjs +++ b/examples/example-app-monorepo/jest-esm-isolated.config.mjs @@ -3,7 +3,7 @@ globalThis.ngJest = { tsconfig: 'tsconfig-esm.spec.json', }; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ const jestConfig = { 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 c0f44d23e0..0744b44cea 100644 --- a/examples/example-app-monorepo/jest-esm.config.mjs +++ b/examples/example-app-monorepo/jest-esm.config.mjs @@ -3,7 +3,7 @@ globalThis.ngJest = { tsconfig: 'tsconfig-esm.spec.json', }; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ const jestConfig = { 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-monorepo/jest-isolated.config.js b/examples/example-app-monorepo/jest-isolated.config.js index 7567e6d26f..2e6e0cb8c5 100644 --- a/examples/example-app-monorepo/jest-isolated.config.js +++ b/examples/example-app-monorepo/jest-isolated.config.js @@ -4,7 +4,7 @@ globalThis.ngJest = { tsconfig: 'tsconfig.spec.json', }; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ module.exports = { globalSetup: 'jest-preset-angular/global-setup', projects: ['/apps/app1/jest-isolated.config.js', '/libs/user/jest-isolated.config.js'], diff --git a/examples/example-app-monorepo/jest.config.js b/examples/example-app-monorepo/jest.config.js index 538d61f6f8..13ca94531c 100644 --- a/examples/example-app-monorepo/jest.config.js +++ b/examples/example-app-monorepo/jest.config.js @@ -4,7 +4,7 @@ globalThis.ngJest = { tsconfig: 'tsconfig.spec.json', }; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ module.exports = { globalSetup: 'jest-preset-angular/global-setup', projects: ['/apps/app1', '/libs/user'], diff --git a/examples/example-app-monorepo/libs/user/jest-esm-isolated.config.mjs b/examples/example-app-monorepo/libs/user/jest-esm-isolated.config.mjs index c6da7e4787..c0696cc27b 100644 --- a/examples/example-app-monorepo/libs/user/jest-esm-isolated.config.mjs +++ b/examples/example-app-monorepo/libs/user/jest-esm-isolated.config.mjs @@ -1,15 +1,18 @@ import jestCfg from './jest-esm.config.mjs'; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ const jestIsolatedCfg = { ...jestCfg, - globals: { - 'ts-jest': { - tsconfig: '/tsconfig-esm.spec.json', - stringifyContentPathRegex: '\\.(html|svg)$', - isolatedModules: true, - useESM: true, - }, + transform: { + '^.+\\.(ts|js|html|svg)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig-esm.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', + isolatedModules: true, + useESM: true, + }, + ], }, }; diff --git a/examples/example-app-monorepo/libs/user/jest-esm.config.mjs b/examples/example-app-monorepo/libs/user/jest-esm.config.mjs index 1256e3eb4b..f8f9fe3c20 100644 --- a/examples/example-app-monorepo/libs/user/jest-esm.config.mjs +++ b/examples/example-app-monorepo/libs/user/jest-esm.config.mjs @@ -1,20 +1,24 @@ import ngPreset from 'jest-preset-angular/presets/index.js'; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ const jestConfig = { ...ngPreset.defaultsESM, displayName: 'user-lib', - globals: { - 'ts-jest': { - ...ngPreset.defaultsESM.globals["ts-jest"], - tsconfig: '/tsconfig-esm.spec.json', - }, - }, moduleNameMapper: { tslib: 'tslib/tslib.es6.js', rxjs: '/../../node_modules/rxjs/dist/bundles/rxjs.umd.js', }, setupFilesAfterEnv: ['/setup-jest-esm.ts'], -} + transform: { + '^.+\\.(ts|js|html|svg)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig-esm.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', + useESM: true, + }, + ], + }, +}; export default jestConfig; diff --git a/examples/example-app-monorepo/libs/user/jest-isolated.config.js b/examples/example-app-monorepo/libs/user/jest-isolated.config.js index a77e374423..e0eb05ff6d 100644 --- a/examples/example-app-monorepo/libs/user/jest-isolated.config.js +++ b/examples/example-app-monorepo/libs/user/jest-isolated.config.js @@ -1,13 +1,16 @@ const jestCfg = require('./jest.config'); +const { defaultTransformerOptions } = require('jest-preset-angular/presets'); -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ module.exports = { ...jestCfg, - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - stringifyContentPathRegex: '\\.(html|svg)$', - isolatedModules: true, - }, + transform: { + '^.+\\.(ts|js|mjs|html|svg)$': [ + 'jest-preset-angular', + { + ...defaultTransformerOptions, + isolatedModules: true, + }, + ], }, }; diff --git a/examples/example-app-monorepo/libs/user/jest.config.js b/examples/example-app-monorepo/libs/user/jest.config.js index d6c35da2ac..d1bd792467 100644 --- a/examples/example-app-monorepo/libs/user/jest.config.js +++ b/examples/example-app-monorepo/libs/user/jest.config.js @@ -1,4 +1,4 @@ -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ module.exports = { displayName: 'user-lib', preset: 'jest-preset-angular', diff --git a/examples/example-app-monorepo/package.json b/examples/example-app-monorepo/package.json index c1104a76ce..8a3774352e 100644 --- a/examples/example-app-monorepo/package.json +++ b/examples/example-app-monorepo/package.json @@ -21,7 +21,7 @@ "@angular/platform-browser-dynamic": "~13.3.12", "@angular/router": "~13.3.12", "angular-in-memory-web-api": "^0.13.0", - "rxjs": "~7.5.7", + "rxjs": "^7.8.0", "tslib": "^2.4.1", "zone.js": "~0.11.8" }, diff --git a/examples/example-app-monorepo/yarn.lock b/examples/example-app-monorepo/yarn.lock index 8ff6051627..1597157df5 100644 --- a/examples/example-app-monorepo/yarn.lock +++ b/examples/example-app-monorepo/yarn.lock @@ -5135,7 +5135,7 @@ __metadata: jest: ^29.4.1 jest-preset-angular: ^13.0.0-next.0 ng-packagr: ^13.3.1 - rxjs: ~7.5.7 + rxjs: ^7.8.0 tslib: ^2.4.1 typescript: ~4.6.4 zone.js: ~0.11.8 @@ -9241,7 +9241,7 @@ __metadata: languageName: node linkType: hard -"rxjs@npm:^7.0.0, rxjs@npm:^7.2.0, rxjs@npm:~7.5.7": +"rxjs@npm:^7.0.0, rxjs@npm:^7.2.0": version: 7.5.7 resolution: "rxjs@npm:7.5.7" dependencies: @@ -9250,6 +9250,15 @@ __metadata: languageName: node linkType: hard +"rxjs@npm:^7.8.0": + version: 7.8.0 + resolution: "rxjs@npm:7.8.0" + dependencies: + tslib: ^2.1.0 + checksum: 61b4d4fd323c1043d8d6ceb91f24183b28bcf5def4f01ca111511d5c6b66755bc5578587fe714ef5d67cf4c9f2e26f4490d4e1d8cabf9bd5967687835e9866a2 + languageName: node + linkType: hard + "safe-buffer@npm:5.1.2, safe-buffer@npm:~5.1.0, safe-buffer@npm:~5.1.1": version: 5.1.2 resolution: "safe-buffer@npm:5.1.2" diff --git a/examples/example-app-v13/jest-esm-isolated.config.mjs b/examples/example-app-v13/jest-esm-isolated.config.mjs index 73b314695e..c0696cc27b 100644 --- a/examples/example-app-v13/jest-esm-isolated.config.mjs +++ b/examples/example-app-v13/jest-esm-isolated.config.mjs @@ -1,13 +1,18 @@ import jestCfg from './jest-esm.config.mjs'; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ const jestIsolatedCfg = { ...jestCfg, - globals: { - 'ts-jest': { - ...jestCfg.globals["ts-jest"], - isolatedModules: true, - }, + transform: { + '^.+\\.(ts|js|html|svg)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig-esm.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', + isolatedModules: true, + useESM: true, + }, + ], }, }; diff --git a/examples/example-app-v13/jest-esm.config.mjs b/examples/example-app-v13/jest-esm.config.mjs index 161e15301f..4dc972336c 100644 --- a/examples/example-app-v13/jest-esm.config.mjs +++ b/examples/example-app-v13/jest-esm.config.mjs @@ -5,21 +5,25 @@ globalThis.ngJest = { tsconfig: 'tsconfig-esm.spec.json', }; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ const jestConfig = { ...ngPreset.defaultsESM, - globals: { - 'ts-jest': { - ...ngPreset.defaultsESM.globals["ts-jest"], - tsconfig: '/tsconfig-esm.spec.json', - }, - }, globalSetup: 'jest-preset-angular/global-setup.mjs', moduleNameMapper: { tslib: 'tslib/tslib.es6.js', rxjs: '/node_modules/rxjs/dist/bundles/rxjs.umd.js', }, setupFilesAfterEnv: ['/setup-jest-esm.ts'], -} + transform: { + '^.+\\.(ts|js|html|svg)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig-esm.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', + useESM: true, + }, + ], + }, +}; export default jestConfig; diff --git a/examples/example-app-v13/jest-isolated.config.js b/examples/example-app-v13/jest-isolated.config.js index 9d6f069519..e0eb05ff6d 100644 --- a/examples/example-app-v13/jest-isolated.config.js +++ b/examples/example-app-v13/jest-isolated.config.js @@ -1,13 +1,16 @@ const jestCfg = require('./jest.config'); -const { defaults } = require('jest-preset-angular/presets'); +const { defaultTransformerOptions } = require('jest-preset-angular/presets'); -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ module.exports = { ...jestCfg, - globals: { - 'ts-jest': { - ...defaults.globals['ts-jest'], - isolatedModules: true, - }, + transform: { + '^.+\\.(ts|js|mjs|html|svg)$': [ + 'jest-preset-angular', + { + ...defaultTransformerOptions, + isolatedModules: true, + }, + ], }, }; diff --git a/examples/example-app-v13/jest.config.js b/examples/example-app-v13/jest.config.js index fa4c34012d..4e0c21a84d 100644 --- a/examples/example-app-v13/jest.config.js +++ b/examples/example-app-v13/jest.config.js @@ -7,7 +7,7 @@ globalThis.ngJest = { tsconfig: 'tsconfig.spec.json', }; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ module.exports = { preset: 'jest-preset-angular', globalSetup: 'jest-preset-angular/global-setup', diff --git a/examples/example-app-v14/jest-esm-isolated.config.mjs b/examples/example-app-v14/jest-esm-isolated.config.mjs index 73b314695e..c0696cc27b 100644 --- a/examples/example-app-v14/jest-esm-isolated.config.mjs +++ b/examples/example-app-v14/jest-esm-isolated.config.mjs @@ -1,13 +1,18 @@ import jestCfg from './jest-esm.config.mjs'; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ const jestIsolatedCfg = { ...jestCfg, - globals: { - 'ts-jest': { - ...jestCfg.globals["ts-jest"], - isolatedModules: true, - }, + transform: { + '^.+\\.(ts|js|html|svg)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig-esm.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', + isolatedModules: true, + useESM: true, + }, + ], }, }; diff --git a/examples/example-app-v14/jest-esm.config.mjs b/examples/example-app-v14/jest-esm.config.mjs index 161e15301f..4dc972336c 100644 --- a/examples/example-app-v14/jest-esm.config.mjs +++ b/examples/example-app-v14/jest-esm.config.mjs @@ -5,21 +5,25 @@ globalThis.ngJest = { tsconfig: 'tsconfig-esm.spec.json', }; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ const jestConfig = { ...ngPreset.defaultsESM, - globals: { - 'ts-jest': { - ...ngPreset.defaultsESM.globals["ts-jest"], - tsconfig: '/tsconfig-esm.spec.json', - }, - }, globalSetup: 'jest-preset-angular/global-setup.mjs', moduleNameMapper: { tslib: 'tslib/tslib.es6.js', rxjs: '/node_modules/rxjs/dist/bundles/rxjs.umd.js', }, setupFilesAfterEnv: ['/setup-jest-esm.ts'], -} + transform: { + '^.+\\.(ts|js|html|svg)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig-esm.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', + useESM: true, + }, + ], + }, +}; export default jestConfig; diff --git a/examples/example-app-v14/jest-isolated.config.js b/examples/example-app-v14/jest-isolated.config.js index 9d6f069519..e0eb05ff6d 100644 --- a/examples/example-app-v14/jest-isolated.config.js +++ b/examples/example-app-v14/jest-isolated.config.js @@ -1,13 +1,16 @@ const jestCfg = require('./jest.config'); -const { defaults } = require('jest-preset-angular/presets'); +const { defaultTransformerOptions } = require('jest-preset-angular/presets'); -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ module.exports = { ...jestCfg, - globals: { - 'ts-jest': { - ...defaults.globals['ts-jest'], - isolatedModules: true, - }, + transform: { + '^.+\\.(ts|js|mjs|html|svg)$': [ + 'jest-preset-angular', + { + ...defaultTransformerOptions, + isolatedModules: true, + }, + ], }, }; diff --git a/examples/example-app-v14/jest.config.js b/examples/example-app-v14/jest.config.js index fa4c34012d..4e0c21a84d 100644 --- a/examples/example-app-v14/jest.config.js +++ b/examples/example-app-v14/jest.config.js @@ -7,7 +7,7 @@ globalThis.ngJest = { tsconfig: 'tsconfig.spec.json', }; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ module.exports = { preset: 'jest-preset-angular', globalSetup: 'jest-preset-angular/global-setup', diff --git a/examples/example-app-v14/package.json b/examples/example-app-v14/package.json index 65d3b4dab2..4e57030ffd 100644 --- a/examples/example-app-v14/package.json +++ b/examples/example-app-v14/package.json @@ -21,7 +21,7 @@ "@angular/platform-browser-dynamic": "^14.2.12", "@angular/router": "^14.2.12", "angular-in-memory-web-api": "^0.14.0", - "rxjs": "~7.5.7", + "rxjs": "^7.8.0", "tslib": "^2.4.1", "zone.js": "^0.12.0" }, diff --git a/examples/example-app-v14/yarn.lock b/examples/example-app-v14/yarn.lock index d2fb4aea2a..84ea63afa9 100644 --- a/examples/example-app-v14/yarn.lock +++ b/examples/example-app-v14/yarn.lock @@ -4739,7 +4739,7 @@ __metadata: angular-in-memory-web-api: ^0.14.0 jest: ^29.4.1 jest-preset-angular: ^13.0.0-next.0 - rxjs: ~7.5.7 + rxjs: ^7.8.0 tslib: ^2.4.1 typescript: ^4.8.4 zone.js: ^0.12.0 @@ -8491,7 +8491,7 @@ __metadata: languageName: node linkType: hard -"rxjs@npm:^7.5.5, rxjs@npm:~7.5.7": +"rxjs@npm:^7.5.5": version: 7.5.7 resolution: "rxjs@npm:7.5.7" dependencies: @@ -8500,6 +8500,15 @@ __metadata: languageName: node linkType: hard +"rxjs@npm:^7.8.0": + version: 7.8.0 + resolution: "rxjs@npm:7.8.0" + dependencies: + tslib: ^2.1.0 + checksum: 61b4d4fd323c1043d8d6ceb91f24183b28bcf5def4f01ca111511d5c6b66755bc5578587fe714ef5d67cf4c9f2e26f4490d4e1d8cabf9bd5967687835e9866a2 + languageName: node + linkType: hard + "safe-buffer@npm:5.1.2, safe-buffer@npm:~5.1.0, safe-buffer@npm:~5.1.1": version: 5.1.2 resolution: "safe-buffer@npm:5.1.2" diff --git a/examples/example-app-v15/jest-esm-isolated.config.mjs b/examples/example-app-v15/jest-esm-isolated.config.mjs index 73b314695e..c0696cc27b 100644 --- a/examples/example-app-v15/jest-esm-isolated.config.mjs +++ b/examples/example-app-v15/jest-esm-isolated.config.mjs @@ -1,13 +1,18 @@ import jestCfg from './jest-esm.config.mjs'; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ const jestIsolatedCfg = { ...jestCfg, - globals: { - 'ts-jest': { - ...jestCfg.globals["ts-jest"], - isolatedModules: true, - }, + transform: { + '^.+\\.(ts|js|html|svg)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig-esm.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', + isolatedModules: true, + useESM: true, + }, + ], }, }; diff --git a/examples/example-app-v15/jest-esm.config.mjs b/examples/example-app-v15/jest-esm.config.mjs index 161e15301f..4dc972336c 100644 --- a/examples/example-app-v15/jest-esm.config.mjs +++ b/examples/example-app-v15/jest-esm.config.mjs @@ -5,21 +5,25 @@ globalThis.ngJest = { tsconfig: 'tsconfig-esm.spec.json', }; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ const jestConfig = { ...ngPreset.defaultsESM, - globals: { - 'ts-jest': { - ...ngPreset.defaultsESM.globals["ts-jest"], - tsconfig: '/tsconfig-esm.spec.json', - }, - }, globalSetup: 'jest-preset-angular/global-setup.mjs', moduleNameMapper: { tslib: 'tslib/tslib.es6.js', rxjs: '/node_modules/rxjs/dist/bundles/rxjs.umd.js', }, setupFilesAfterEnv: ['/setup-jest-esm.ts'], -} + transform: { + '^.+\\.(ts|js|html|svg)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig-esm.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', + useESM: true, + }, + ], + }, +}; export default jestConfig; diff --git a/examples/example-app-v15/jest-isolated.config.js b/examples/example-app-v15/jest-isolated.config.js index 9d6f069519..e0eb05ff6d 100644 --- a/examples/example-app-v15/jest-isolated.config.js +++ b/examples/example-app-v15/jest-isolated.config.js @@ -1,13 +1,16 @@ const jestCfg = require('./jest.config'); -const { defaults } = require('jest-preset-angular/presets'); +const { defaultTransformerOptions } = require('jest-preset-angular/presets'); -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ module.exports = { ...jestCfg, - globals: { - 'ts-jest': { - ...defaults.globals['ts-jest'], - isolatedModules: true, - }, + transform: { + '^.+\\.(ts|js|mjs|html|svg)$': [ + 'jest-preset-angular', + { + ...defaultTransformerOptions, + isolatedModules: true, + }, + ], }, }; diff --git a/examples/example-app-v15/jest.config.js b/examples/example-app-v15/jest.config.js index fa4c34012d..4e0c21a84d 100644 --- a/examples/example-app-v15/jest.config.js +++ b/examples/example-app-v15/jest.config.js @@ -7,7 +7,7 @@ globalThis.ngJest = { tsconfig: 'tsconfig.spec.json', }; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ module.exports = { preset: 'jest-preset-angular', globalSetup: 'jest-preset-angular/global-setup', diff --git a/examples/example-app-yarn-workspace/packages/angular-app/jest-esm-isolated.config.mjs b/examples/example-app-yarn-workspace/packages/angular-app/jest-esm-isolated.config.mjs index 73b314695e..c0696cc27b 100644 --- a/examples/example-app-yarn-workspace/packages/angular-app/jest-esm-isolated.config.mjs +++ b/examples/example-app-yarn-workspace/packages/angular-app/jest-esm-isolated.config.mjs @@ -1,13 +1,18 @@ import jestCfg from './jest-esm.config.mjs'; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ const jestIsolatedCfg = { ...jestCfg, - globals: { - 'ts-jest': { - ...jestCfg.globals["ts-jest"], - isolatedModules: true, - }, + transform: { + '^.+\\.(ts|js|html|svg)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig-esm.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', + isolatedModules: true, + useESM: true, + }, + ], }, }; 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 0393c066ca..ba33e8eec2 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 @@ -5,21 +5,25 @@ globalThis.ngJest = { tsconfig: 'tsconfig-esm.spec.json', }; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ const jestConfig = { ...ngPreset.defaultsESM, - globals: { - 'ts-jest': { - ...ngPreset.defaultsESM.globals["ts-jest"], - tsconfig: '/tsconfig-esm.spec.json', - }, - }, globalSetup: 'jest-preset-angular/global-setup.mjs', moduleNameMapper: { tslib: 'tslib/tslib.es6.js', rxjs: '/../../node_modules/rxjs/dist/bundles/rxjs.umd.js', }, setupFilesAfterEnv: ['/setup-jest-esm.ts'], -} + transform: { + '^.+\\.(ts|js|html|svg)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig-esm.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', + useESM: true, + }, + ], + }, +}; export default jestConfig; diff --git a/examples/example-app-yarn-workspace/packages/angular-app/jest-isolated.config.js b/examples/example-app-yarn-workspace/packages/angular-app/jest-isolated.config.js index 9d6f069519..e0eb05ff6d 100644 --- a/examples/example-app-yarn-workspace/packages/angular-app/jest-isolated.config.js +++ b/examples/example-app-yarn-workspace/packages/angular-app/jest-isolated.config.js @@ -1,13 +1,16 @@ const jestCfg = require('./jest.config'); -const { defaults } = require('jest-preset-angular/presets'); +const { defaultTransformerOptions } = require('jest-preset-angular/presets'); -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ module.exports = { ...jestCfg, - globals: { - 'ts-jest': { - ...defaults.globals['ts-jest'], - isolatedModules: true, - }, + transform: { + '^.+\\.(ts|js|mjs|html|svg)$': [ + 'jest-preset-angular', + { + ...defaultTransformerOptions, + isolatedModules: true, + }, + ], }, }; diff --git a/examples/example-app-yarn-workspace/packages/angular-app/jest.config.js b/examples/example-app-yarn-workspace/packages/angular-app/jest.config.js index fa4c34012d..4e0c21a84d 100644 --- a/examples/example-app-yarn-workspace/packages/angular-app/jest.config.js +++ b/examples/example-app-yarn-workspace/packages/angular-app/jest.config.js @@ -7,7 +7,7 @@ globalThis.ngJest = { tsconfig: 'tsconfig.spec.json', }; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ module.exports = { preset: 'jest-preset-angular', globalSetup: 'jest-preset-angular/global-setup', diff --git a/examples/example-app-yarn-workspace/packages/angular-app/package.json b/examples/example-app-yarn-workspace/packages/angular-app/package.json index 7a0b18325c..df7800c536 100644 --- a/examples/example-app-yarn-workspace/packages/angular-app/package.json +++ b/examples/example-app-yarn-workspace/packages/angular-app/package.json @@ -21,7 +21,7 @@ "@angular/platform-browser-dynamic": "~13.3.12", "@angular/router": "~13.3.12", "angular-in-memory-web-api": "^0.13.0", - "rxjs": "~7.5.7", + "rxjs": "^7.8.0", "tslib": "^2.4.1", "zone.js": "~0.11.8" }, diff --git a/examples/example-app-yarn-workspace/packages/user/jest-esm-isolated.config.mjs b/examples/example-app-yarn-workspace/packages/user/jest-esm-isolated.config.mjs index 73b314695e..c0696cc27b 100644 --- a/examples/example-app-yarn-workspace/packages/user/jest-esm-isolated.config.mjs +++ b/examples/example-app-yarn-workspace/packages/user/jest-esm-isolated.config.mjs @@ -1,13 +1,18 @@ import jestCfg from './jest-esm.config.mjs'; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ const jestIsolatedCfg = { ...jestCfg, - globals: { - 'ts-jest': { - ...jestCfg.globals["ts-jest"], - isolatedModules: true, - }, + transform: { + '^.+\\.(ts|js|html|svg)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig-esm.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', + isolatedModules: true, + useESM: true, + }, + ], }, }; 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 0393c066ca..ba33e8eec2 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 @@ -5,21 +5,25 @@ globalThis.ngJest = { tsconfig: 'tsconfig-esm.spec.json', }; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ const jestConfig = { ...ngPreset.defaultsESM, - globals: { - 'ts-jest': { - ...ngPreset.defaultsESM.globals["ts-jest"], - tsconfig: '/tsconfig-esm.spec.json', - }, - }, globalSetup: 'jest-preset-angular/global-setup.mjs', moduleNameMapper: { tslib: 'tslib/tslib.es6.js', rxjs: '/../../node_modules/rxjs/dist/bundles/rxjs.umd.js', }, setupFilesAfterEnv: ['/setup-jest-esm.ts'], -} + transform: { + '^.+\\.(ts|js|html|svg)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig-esm.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', + useESM: true, + }, + ], + }, +}; export default jestConfig; diff --git a/examples/example-app-yarn-workspace/packages/user/jest-isolated.config.js b/examples/example-app-yarn-workspace/packages/user/jest-isolated.config.js index 9d6f069519..e0eb05ff6d 100644 --- a/examples/example-app-yarn-workspace/packages/user/jest-isolated.config.js +++ b/examples/example-app-yarn-workspace/packages/user/jest-isolated.config.js @@ -1,13 +1,16 @@ const jestCfg = require('./jest.config'); -const { defaults } = require('jest-preset-angular/presets'); +const { defaultTransformerOptions } = require('jest-preset-angular/presets'); -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ module.exports = { ...jestCfg, - globals: { - 'ts-jest': { - ...defaults.globals['ts-jest'], - isolatedModules: true, - }, + transform: { + '^.+\\.(ts|js|mjs|html|svg)$': [ + 'jest-preset-angular', + { + ...defaultTransformerOptions, + isolatedModules: true, + }, + ], }, }; diff --git a/examples/example-app-yarn-workspace/packages/user/jest.config.js b/examples/example-app-yarn-workspace/packages/user/jest.config.js index fa4c34012d..4e0c21a84d 100644 --- a/examples/example-app-yarn-workspace/packages/user/jest.config.js +++ b/examples/example-app-yarn-workspace/packages/user/jest.config.js @@ -7,7 +7,7 @@ globalThis.ngJest = { tsconfig: 'tsconfig.spec.json', }; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ module.exports = { preset: 'jest-preset-angular', globalSetup: 'jest-preset-angular/global-setup', diff --git a/examples/example-app-yarn-workspace/packages/user/package.json b/examples/example-app-yarn-workspace/packages/user/package.json index 96b1c13d20..d98ff97e8e 100644 --- a/examples/example-app-yarn-workspace/packages/user/package.json +++ b/examples/example-app-yarn-workspace/packages/user/package.json @@ -9,12 +9,13 @@ "test-esm-isolated": "node --experimental-vm-modules --no-warnings ../../node_modules/jest/bin/jest.js -c=jest-esm-isolated.config.mjs --no-cache" }, "devDependencies": { - "@angular/common": "^13.3.12", + "@angular/cli": "~13.3.10", + "@angular/compiler-cli": "~13.3.12", "@angular/core": "^13.3.12", "@types/jest": "^29.4.0", "jest": "^29.4.1", "jest-preset-angular": "^13.0.0-next.0", - "rxjs": "^7.5.7", + "rxjs": "^7.8.0", "tslib": "^2.4.1", "typescript": "~4.6.4", "zone.js": "~0.11.8" diff --git a/examples/example-app-yarn-workspace/yarn.lock b/examples/example-app-yarn-workspace/yarn.lock index 69ecb19b44..9674140d47 100644 --- a/examples/example-app-yarn-workspace/yarn.lock +++ b/examples/example-app-yarn-workspace/yarn.lock @@ -208,7 +208,7 @@ __metadata: languageName: node linkType: hard -"@angular/common@npm:^13.3.12, @angular/common@npm:~13.3.12": +"@angular/common@npm:~13.3.12": version: 13.3.12 resolution: "@angular/common@npm:13.3.12" dependencies: @@ -2862,7 +2862,7 @@ __metadata: angular-in-memory-web-api: ^0.13.0 jest: ^29.4.1 jest-preset-angular: ^13.0.0-next.0 - rxjs: ~7.5.7 + rxjs: ^7.8.0 tslib: ^2.4.1 typescript: ~4.6.4 zone.js: ~0.11.8 @@ -8903,7 +8903,7 @@ __metadata: languageName: node linkType: hard -"rxjs@npm:^7.2.0, rxjs@npm:^7.5.7, rxjs@npm:~7.5.7": +"rxjs@npm:^7.2.0": version: 7.5.7 resolution: "rxjs@npm:7.5.7" dependencies: @@ -8912,6 +8912,15 @@ __metadata: languageName: node linkType: hard +"rxjs@npm:^7.8.0": + version: 7.8.0 + resolution: "rxjs@npm:7.8.0" + dependencies: + tslib: ^2.1.0 + checksum: 61b4d4fd323c1043d8d6ceb91f24183b28bcf5def4f01ca111511d5c6b66755bc5578587fe714ef5d67cf4c9f2e26f4490d4e1d8cabf9bd5967687835e9866a2 + languageName: node + linkType: hard + "safe-buffer@npm:5.1.2, safe-buffer@npm:~5.1.0, safe-buffer@npm:~5.1.1": version: 5.1.2 resolution: "safe-buffer@npm:5.1.2" @@ -9942,12 +9951,13 @@ __metadata: version: 0.0.0-use.local resolution: "user@workspace:packages/user" dependencies: - "@angular/common": ^13.3.12 + "@angular/cli": ~13.3.10 + "@angular/compiler-cli": ~13.3.12 "@angular/core": ^13.3.12 "@types/jest": ^29.4.0 jest: ^29.4.1 jest-preset-angular: ^13.0.0-next.0 - rxjs: ^7.5.7 + rxjs: ^7.8.0 tslib: ^2.4.1 typescript: ~4.6.4 zone.js: ~0.11.8 diff --git a/jest.config.js b/jest.config.js index aa6cc6a9eb..3c833c2082 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,11 +1,5 @@ -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ module.exports = { - globals: { - 'ts-jest': { - tsconfig: 'tsconfig.spec.json', - isolatedModules: true, - }, - }, moduleNameMapper: { '@angular/compiler-cli/ngcc': '/node_modules/@angular/compiler-cli/bundles/ngcc/main-ngcc.js', }, @@ -14,6 +8,12 @@ module.exports = { snapshotSerializers: [require.resolve('jest-snapshot-serializer-raw')], testPathIgnorePatterns: ['/node_modules/', '/examples/', '/e2e/.*/__tests__', '\\.snap$'], transform: { - '^.+\\.(ts|js|mjs|html)$': '/build/index.js', + '^.+\\.(ts|js|mjs|html)$': [ + '/build/index.js', + { + tsconfig: 'tsconfig.spec.json', + isolatedModules: true, + }, + ], }, }; diff --git a/presets/index.d.ts b/presets/index.d.ts index bdfa34f63b..fd8045e799 100644 --- a/presets/index.d.ts +++ b/presets/index.d.ts @@ -1,46 +1,22 @@ declare const _default: { defaults: { transformIgnorePatterns: string[]; - transform: { - '^.+\\.(ts|js|mjs|html|svg)$': string; - }; - globals: import('ts-jest').GlobalConfigTsJest; + transform: import('ts-jest').JestConfigWithTsJest['transform']; testEnvironment: string; moduleFileExtensions: string[]; snapshotSerializers: string[]; }; defaultsESM: { extensionsToTreatAsEsm: string[]; - globals: { - 'ts-jest': { - useESM: boolean; - tsconfig?: string | boolean | import('ts-jest').RawCompilerOptions | undefined; - isolatedModules?: boolean | undefined; - compiler?: string | undefined; - astTransformers?: import('ts-jest').ConfigCustomTransformer | undefined; - diagnostics?: - | boolean - | { - pretty?: boolean | undefined; - ignoreCodes?: string | number | Array | undefined; - exclude?: string[] | undefined; - warnOnly?: boolean | undefined; - } - | undefined; - babelConfig?: string | boolean | import('@babel/core').TransformOptions | undefined; - stringifyContentPathRegex?: string | RegExp | undefined; - }; - }; moduleNameMapper: { tslib: string; }; - transform: { - '^.+\\.(ts|js|html|svg)$': string; - }; + transform: import('ts-jest').JestConfigWithTsJest['transform']; transformIgnorePatterns: string[]; testEnvironment: string; moduleFileExtensions: string[]; snapshotSerializers: string[]; }; + defaultTransformerOptions: import('ts-jest').TsJestTransformerOptions; }; export default _default; diff --git a/presets/index.js b/presets/index.js index 5c5d36ef11..4f44021fc3 100644 --- a/presets/index.js +++ b/presets/index.js @@ -3,4 +3,5 @@ const ngJestPresets = require('../build/presets'); module.exports = { defaults: ngJestPresets.defaultPreset, defaultsESM: ngJestPresets.defaultEsmPreset, + defaultTransformerOptions: ngJestPresets.defaultTransformerOptions, }; diff --git a/src/compiler/ng-jest-compiler.spec.ts b/src/compiler/ng-jest-compiler.spec.ts index 77541ebe87..eccd686573 100644 --- a/src/compiler/ng-jest-compiler.spec.ts +++ b/src/compiler/ng-jest-compiler.spec.ts @@ -9,14 +9,16 @@ describe('NgJestCompiler', () => { extensionsToTreatAsEsm: [], testMatch: [], testRegex: [], - globals: { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - 'ts-jest': { - isolatedModules: true, - tsconfig: { - sourceMap: false, + transform: { + '^.+\\.(ts|js|mjs|html|svg)$': [ + 'ts-jest', + { + isolatedModules: true, + tsconfig: { + sourceMap: false, + }, }, - }, + ], }, } as any); // eslint-disable-line @typescript-eslint/no-explicit-any const compiler = new NgJestCompiler(ngJestConfig, new Map()); diff --git a/src/index.ts b/src/index.ts index cfcb288c27..17b024f5c0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,8 @@ +import type { TsJestTransformerOptions } from 'ts-jest'; + import { NgJestTransformer } from './ng-jest-transformer'; export default { - createTransformer: (): NgJestTransformer => new NgJestTransformer(), + createTransformer: (tsJestConfig?: TsJestTransformerOptions): NgJestTransformer => + new NgJestTransformer(tsJestConfig), }; diff --git a/src/ng-jest-transformer.spec.ts b/src/ng-jest-transformer.spec.ts index e8b4d8c732..68081975e4 100644 --- a/src/ng-jest-transformer.spec.ts +++ b/src/ng-jest-transformer.spec.ts @@ -1,11 +1,10 @@ import { transformSync } from 'esbuild'; +import { TsJestTransformer } from 'ts-jest'; import { NgJestCompiler } from './compiler/ng-jest-compiler'; import { NgJestConfig } from './config/ng-jest-config'; import { NgJestTransformer } from './ng-jest-transformer'; -const tr = new NgJestTransformer(); - jest.mock('esbuild', () => { return { transformSync: jest.fn().mockReturnValue({ @@ -17,7 +16,16 @@ jest.mock('esbuild', () => { const mockedTransformSync = jest.mocked(transformSync); describe('NgJestTransformer', () => { + beforeEach(() => { + // @ts-expect-error testing purpose + TsJestTransformer._cachedConfigSets = []; + }); + test('should create NgJestCompiler and NgJestConfig instances', () => { + const tr = new NgJestTransformer({ + isolatedModules: true, + }); + // @ts-expect-error testing purpose const cs = tr._createConfigSet({ cwd: process.cwd(), @@ -35,6 +43,9 @@ describe('NgJestTransformer', () => { }); test('should not use esbuild to process js files which are not from `node_modules`', () => { + const tr = new NgJestTransformer({ + isolatedModules: true, + }); tr.process( ` const pi = parseFloat(3.124); @@ -48,11 +59,6 @@ describe('NgJestTransformer', () => { extensionsToTreatAsEsm: [], testMatch: [], testRegex: [], - globals: { - 'ts-jest': { - isolatedModules: true, - }, - }, }, } as any, // eslint-disable-line @typescript-eslint/no-explicit-any, ); @@ -61,6 +67,9 @@ describe('NgJestTransformer', () => { }); test('should not use esbuild to process tslib file', () => { + const tr = new NgJestTransformer({ + isolatedModules: true, + }); tr.process( ` const pi = parseFloat(3.124); @@ -74,11 +83,6 @@ describe('NgJestTransformer', () => { extensionsToTreatAsEsm: [], testMatch: [], testRegex: [], - globals: { - 'ts-jest': { - isolatedModules: true, - }, - }, }, } as any, // eslint-disable-line @typescript-eslint/no-explicit-any, ); @@ -109,15 +113,15 @@ describe('NgJestTransformer', () => { testMatch: [], testRegex: [], globals: { - 'ts-jest': { - tsconfig, - }, ngJest: { processWithEsbuild: ['node_modules/foo.js'], }, }, }, } as any; // eslint-disable-line @typescript-eslint/no-explicit-any + const tr = new NgJestTransformer({ + tsconfig, + }); tr.process( ` const pi = parseFloat(3.124); @@ -166,10 +170,6 @@ describe('NgJestTransformer', () => { testMatch: [], testRegex: [], globals: { - 'ts-jest': { - tsconfig, - useESM: true, - }, ngJest: { processWithEsbuild: ['node_modules/foo.js'], }, @@ -177,6 +177,10 @@ describe('NgJestTransformer', () => { }, supportsStaticESM: true, } as any; // eslint-disable-line @typescript-eslint/no-explicit-any + const tr = new NgJestTransformer({ + tsconfig, + useESM: true, + }); tr.process( ` const pi = parseFloat(3.124); diff --git a/src/ng-jest-transformer.ts b/src/ng-jest-transformer.ts index dcf627cffd..b029cf6a00 100644 --- a/src/ng-jest-transformer.ts +++ b/src/ng-jest-transformer.ts @@ -1,8 +1,8 @@ import { spawnSync } from 'child_process'; -import type { TransformedSource } from '@jest/transform'; +import type { TransformedSource, TransformOptions } from '@jest/transform'; import { LogContexts, LogLevels, type Logger, createLogger } from 'bs-logger'; -import { type ProjectConfigTsJest, type TransformOptionsTsJest, ConfigSet, TsJestTransformer } from 'ts-jest'; +import { type TsJestTransformerOptions, type ProjectConfigTsJest, ConfigSet, TsJestTransformer } from 'ts-jest'; import { NgJestCompiler } from './compiler/ng-jest-compiler'; import { NgJestConfig } from './config/ng-jest-config'; @@ -16,8 +16,8 @@ export class NgJestTransformer extends TsJestTransformer { #ngJestLogger: Logger; #esbuildImpl: typeof import('esbuild'); - constructor() { - super(); + constructor(tsJestConfig?: TsJestTransformerOptions) { + super(tsJestConfig); this.#ngJestLogger = createLogger({ context: { [LogContexts.package]: 'jest-preset-angular', @@ -49,7 +49,7 @@ export class NgJestTransformer extends TsJestTransformer { this._compiler = new NgJestCompiler(configSet, cacheFS); } - process(fileContent: string, filePath: string, transformOptions: TransformOptionsTsJest): TransformedSource { + process(fileContent: string, filePath: string, transformOptions: TransformOptions): TransformedSource { // @ts-expect-error we are accessing the private cache to avoid creating new objects all the time const configSet = super._configsFor(transformOptions); if (configSet.processWithEsbuild(filePath)) { diff --git a/src/presets/__snapshots__/index.spec.ts.snap b/src/presets/__snapshots__/index.spec.ts.snap index b54b204975..87f668d745 100644 --- a/src/presets/__snapshots__/index.spec.ts.snap +++ b/src/presets/__snapshots__/index.spec.ts.snap @@ -4,47 +4,23 @@ exports[`Jest presets should have the correct types which come from \`ts-jest\` "declare const _default: { defaults: { transformIgnorePatterns: string[]; - transform: { - '^.+\\\\.(ts|js|mjs|html|svg)$': string; - }; - globals: import('ts-jest').GlobalConfigTsJest; + transform: import('ts-jest').JestConfigWithTsJest['transform']; testEnvironment: string; moduleFileExtensions: string[]; snapshotSerializers: string[]; }; defaultsESM: { extensionsToTreatAsEsm: string[]; - globals: { - 'ts-jest': { - useESM: boolean; - tsconfig?: string | boolean | import('ts-jest').RawCompilerOptions | undefined; - isolatedModules?: boolean | undefined; - compiler?: string | undefined; - astTransformers?: import('ts-jest').ConfigCustomTransformer | undefined; - diagnostics?: - | boolean - | { - pretty?: boolean | undefined; - ignoreCodes?: string | number | Array | undefined; - exclude?: string[] | undefined; - warnOnly?: boolean | undefined; - } - | undefined; - babelConfig?: string | boolean | import('@babel/core').TransformOptions | undefined; - stringifyContentPathRegex?: string | RegExp | undefined; - }; - }; moduleNameMapper: { tslib: string; }; - transform: { - '^.+\\\\.(ts|js|html|svg)$': string; - }; + transform: import('ts-jest').JestConfigWithTsJest['transform']; transformIgnorePatterns: string[]; testEnvironment: string; moduleFileExtensions: string[]; snapshotSerializers: string[]; }; + defaultTransformerOptions: import('ts-jest').TsJestTransformerOptions; }; export default _default; " @@ -52,12 +28,6 @@ export default _default; exports[`Jest presets should return the correct jest config 1`] = ` { - "globals": { - "ts-jest": { - "stringifyContentPathRegex": "\\.(html|svg)$", - "tsconfig": "/tsconfig.spec.json", - }, - }, "moduleFileExtensions": [ "ts", "html", @@ -72,7 +42,13 @@ exports[`Jest presets should return the correct jest config 1`] = ` ], "testEnvironment": "jsdom", "transform": { - "^.+\\.(ts|js|mjs|html|svg)$": "jest-preset-angular", + "^.+\\.(ts|js|mjs|html|svg)$": [ + "jest-preset-angular", + { + "stringifyContentPathRegex": "\\.(html|svg)$", + "tsconfig": "/tsconfig.spec.json", + }, + ], }, "transformIgnorePatterns": [ "node_modules/(?!.*\\.mjs$)", @@ -85,13 +61,6 @@ exports[`Jest presets should return the correct jest config 2`] = ` "extensionsToTreatAsEsm": [ ".ts", ], - "globals": { - "ts-jest": { - "stringifyContentPathRegex": "\\.(html|svg)$", - "tsconfig": "/tsconfig.spec.json", - "useESM": true, - }, - }, "moduleFileExtensions": [ "ts", "html", @@ -109,7 +78,14 @@ exports[`Jest presets should return the correct jest config 2`] = ` ], "testEnvironment": "jsdom", "transform": { - "^.+\\.(ts|js|html|svg)$": "jest-preset-angular", + "^.+\\.(ts|js|html|svg)$": [ + "jest-preset-angular", + { + "stringifyContentPathRegex": "\\.(html|svg)$", + "tsconfig": "/tsconfig.spec.json", + "useESM": true, + }, + ], }, "transformIgnorePatterns": [ "node_modules/(?!tslib)", diff --git a/src/presets/index.ts b/src/presets/index.ts index bb15091f91..0a195d0c7a 100644 --- a/src/presets/index.ts +++ b/src/presets/index.ts @@ -1,46 +1,42 @@ -import type { ProjectConfigTsJest } from 'ts-jest'; +import type { JestConfigWithTsJest, TsJestTransformerOptions } from 'ts-jest'; import snapshotSerializers from '../serializers'; -const baseConfig: Pick< - ProjectConfigTsJest, - 'globals' | 'testEnvironment' | 'moduleFileExtensions' | 'snapshotSerializers' -> = { - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - stringifyContentPathRegex: '\\.(html|svg)$', - }, - }, +const baseConfig: Pick = { testEnvironment: 'jsdom', moduleFileExtensions: ['ts', 'html', 'js', 'json', 'mjs'], snapshotSerializers, }; +const defaultTransformerOptions: TsJestTransformerOptions = { + tsconfig: '/tsconfig.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', +}; + const defaultPreset = { ...baseConfig, transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'], transform: { - '^.+\\.(ts|js|mjs|html|svg)$': 'jest-preset-angular', + '^.+\\.(ts|js|mjs|html|svg)$': ['jest-preset-angular', defaultTransformerOptions], }, }; const defaultEsmPreset = { ...baseConfig, extensionsToTreatAsEsm: ['.ts'], - globals: { - 'ts-jest': { - ...baseConfig.globals['ts-jest'], - useESM: true, - }, - }, moduleNameMapper: { tslib: 'tslib/tslib.es6.js', }, transform: { - '^.+\\.(ts|js|html|svg)$': 'jest-preset-angular', + '^.+\\.(ts|js|html|svg)$': [ + 'jest-preset-angular', + { + ...defaultTransformerOptions, + useESM: true, + }, + ], }, transformIgnorePatterns: ['node_modules/(?!tslib)'], }; -export { defaultPreset, defaultEsmPreset }; +export { defaultPreset, defaultEsmPreset, defaultTransformerOptions }; diff --git a/website/docs/getting-started/options.md b/website/docs/getting-started/options.md index 91cd3c8296..f379b5b12c 100644 --- a/website/docs/getting-started/options.md +++ b/website/docs/getting-started/options.md @@ -3,10 +3,10 @@ id: options title: Options --- -`jest-preset-angular` uses `ts-jest` options under the hood, which are located under the `globals` of Jest config object +`jest-preset-angular` uses `ts-jest` options under the hood, which are located under the `transform` of Jest config object in the `package.json` file of your project, or through a `jest.config.js`, or `jest.config.ts` file. -More information about `ts-jest` options, see https://kulshekhar.github.io/ts-jest/docs/getting-started/options +More information about `ts-jest` options, see :::important @@ -80,19 +80,19 @@ export default jestConfig; const snapshotSerializers = require('../build/serializers'); module.exports = { - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - stringifyContentPathRegex: '\\.(html|svg)$', - }, - }, moduleFileExtensions: ['ts', 'html', 'js', 'json', 'mjs'], resolver: 'jest-preset-angular/build/resolvers/ng-jest-resolver.js', snapshotSerializers, testEnvironment: 'jsdom', transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'], transform: { - '^.+\\.(ts|js|mjs|html|svg)$': 'jest-preset-angular', + '^.+\\.(ts|js|mjs|html|svg)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', + }, + ], }, }; ``` @@ -102,19 +102,19 @@ import type { Config } from 'jest'; import snapshotSerializers from 'jest-preset-angular/build/serializers'; const jestConfig: Config = { - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - stringifyContentPathRegex: '\\.(html|svg)$', - }, - }, moduleFileExtensions: ['ts', 'html', 'js', 'json', 'mjs'], resolver: 'jest-preset-angular/build/resolvers/ng-jest-resolver.js', snapshotSerializers, testEnvironment: 'jsdom', transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'], transform: { - '^.+\\.(ts|js|mjs|html|svg)$': 'jest-preset-angular', + '^.+\\.(ts|js|mjs|html|svg)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', + }, + ], }, }; @@ -130,7 +130,7 @@ Jest runs with `jest-preset-angular` neither in browser nor through dev server. ### Brief explanation of config -- We're using some `"globals"` to pass information about configuration to use for code compilation with `ts-jest`. +- We're using `"transform"` to pass information about configuration to use for code compilation with `ts-jest`. - `"moduleFileExtensions"` – our modules are TypeScript (`ts`), HTML (`html`), JavaScript (`js`), JSON (`json`) and ESM JavaScript (`mjs`) files. - `"moduleNameMapper"` – if you're using absolute imports here's how to tell Jest where to look for them; uses `RegExp`. - `"resolver"` - instruct Jest how to resolve entry file based on `package.json` definitions. diff --git a/website/docs/getting-started/presets.md b/website/docs/getting-started/presets.md index 7682cc6aa3..c75e165cde 100644 --- a/website/docs/getting-started/presets.md +++ b/website/docs/getting-started/presets.md @@ -58,23 +58,26 @@ copy the original options and override the options you need: :::important -If you choose to override `globals` in order to point at a specific tsconfig, you will need to make sure that original `ts-jest` -options provided through the default preset are defined to the `globals.ts-jest` section too, otherwise you will get +If you choose to override `transform` in order to point at a specific tsconfig, you will need to make sure that original `ts-jest` +options provided through the default preset are defined to the `transform` section too, otherwise you will get errors. ::: ```js tab -const { defaults: jestNgPreset } = require('jest-preset-angular/presets'); -// const { defaultsESM: jestNgPreset } = require('jest-preset-angular/presets') +const { defaultTransformerOptions } = require('jest-preset-angular/presets'); +// const { defaultTransformerOptions } = require('jest-preset-angular/presets') module.exports = { // [...] - globals: { - 'ts-jest': { - ...jestNgPreset.globals['ts-jest'], - // [...your overriden options] - }, + transform: { + '^.+\\.(ts|js|mjs|html|svg)$': [ + 'jest-preset-angular', + { + ...defaultTransformerOptions, + // [...your overriden options] + }, + ], }, }; ``` @@ -85,11 +88,14 @@ import presets from 'jest-preset-angular/presets'; const jestConfig: Config = { // [...] - globals: { - 'ts-jest': { - ...presets.defaults.globals['ts-jest'], - // [...your overriden options] - }, + transform: { + '^.+\\.(ts|js|mjs|html|svg)$': [ + 'jest-preset-angular', + { + ...presets.defaultTransformerOptions, + // [...your overriden options] + }, + ], }, }; diff --git a/website/docs/guides/angular-13+.md b/website/docs/guides/angular-13+.md index 37c0381b89..f748b332b3 100644 --- a/website/docs/guides/angular-13+.md +++ b/website/docs/guides/angular-13+.md @@ -23,7 +23,7 @@ Starting from **v11.0.0**, `jest-preset-angular` introduces a few extra changes ## Migration steps from Angular < 13 -- Upgrade the project to **Angular 13** following https://update.angular.io/ +- Upgrade the project to **Angular 13** following - If one is using the default preset as following: @@ -55,15 +55,19 @@ Your `jest.config.js` should be changed to something like: const { pathsToModuleNameMapper } = require('ts-jest/utils'); const { paths } = require('./tsconfig.json').compilerOptions; -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ module.exports = { preset: 'jest-preset-angular/presets/defaults-esm', - globals: { - 'ts-jest': { - useESM: true, - stringifyContentPathRegex: '\\.(html|svg)$', - tsconfig: '/tsconfig-esm.spec.json', - }, + transform: { + '^.+\\.(ts|js|html|svg)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig-esm.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', + isolatedModules: true, + useESM: true, + }, + ], }, moduleNameMapper: { ...pathsToModuleNameMapper(paths, { prefix: '' }), @@ -80,12 +84,16 @@ import { compilerOptions } from './tsconfig.json'; const jestConfig: Config = { preset: 'jest-preset-angular/presets/defaults-esm', - globals: { - 'ts-jest': { - useESM: true, - stringifyContentPathRegex: '\\.(html|svg)$', - tsconfig: '/tsconfig-esm.spec.json', - }, + transform: { + '^.+\\.(ts|js|html|svg)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig-esm.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', + isolatedModules: true, + useESM: true, + }, + ], }, moduleNameMapper: { ...pathsToModuleNameMapper(compilerOptions.paths, { prefix: '' }), diff --git a/website/docs/guides/esm-support.md b/website/docs/guides/esm-support.md index 066f958abf..0ff15e761c 100644 --- a/website/docs/guides/esm-support.md +++ b/website/docs/guides/esm-support.md @@ -29,12 +29,15 @@ import 'jest-preset-angular/setup-jest.mjs'; module.exports = { //... extensionsToTreatAsEsm: ['.ts'], - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - stringifyContentPathRegex: '\\.html$', - useESM: true, - }, + transform: { + '^.+\\.(ts|js|html)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig.spec.json', + stringifyContentPathRegex: '\\.(html)$', + useESM: true, + }, + ], }, }; ``` @@ -45,12 +48,15 @@ import type { Config } from 'jest'; const jestConfig: Config = { //... extensionsToTreatAsEsm: ['.ts'], - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - stringifyContentPathRegex: '\\.html$', - useESM: true, - }, + transform: { + '^.+\\.(ts|js|html|svg)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', + useESM: true, + }, + ], }, }; @@ -62,13 +68,16 @@ export default jestConfig; //... "jest": { "extensionsToTreatAsEsm": [".ts"], - "globals": { - "ts-jest": { - "tsconfig": "/tsconfig.spec.json", - "stringifyContentPathRegex": "\\.html$", - "useESM": true - } - } + "transform": { + "^.+\\.(ts|js|html|svg)$": [ + "jest-preset-angular", + { + "tsconfig": "/tsconfig.spec.json", + "stringifyContentPathRegex": "\\.(html|svg)$", + "useESM": true, + }, + ], + }, } } ```