Skip to content

Commit

Permalink
feat: support Jest 29 (#1937)
Browse files Browse the repository at this point in the history
Co-authored-by: Ismaïl Ouazzany <iouazzany@smartadserver.com>
Co-authored-by: Tim <tja2353@gmail.com>
  • Loading branch information
3 people authored Jan 27, 2023
1 parent 54ed21c commit b0b57a7
Show file tree
Hide file tree
Showing 73 changed files with 583 additions and 462 deletions.
12 changes: 8 additions & 4 deletions e2e/ast-transformers/hoisting/jest-isolated.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ const baseCfg = require('./jest.config');

module.exports = {
...baseCfg,
globals: {
'ts-jest': {
isolatedModules: true,
},
transform: {
...baseCfg.transform,
'^.+\\.(ts|js|html)$': [
'<rootDir>/../../../build/index.js',
{
isolatedModules: true,
},
],
},
};
14 changes: 9 additions & 5 deletions e2e/ast-transformers/ng-jit-transformers/jest-isolated.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)$': [
'<rootDir>/../../../build/index.js',
{
...require('./ts-jest.config'),
isolatedModules: true,
},
],
},
};
7 changes: 1 addition & 6 deletions e2e/ast-transformers/ng-jit-transformers/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
module.exports = {
globals: {
'ts-jest': {
stringifyContentPathRegex: '\\.html$',
},
},
resolver: '<rootDir>/../../../build/resolvers/ng-jest-resolver',
setupFilesAfterEnv: ['<rootDir>/../../../setup-jest.js'],
testEnvironment: 'jsdom',
transform: {
'^.+\\.(ts|js|mjs|html)$': '<rootDir>/../../../build/index.js',
'^.+\\.(ts|js|mjs|html)$': ['<rootDir>/../../../build/index.js', require('./ts-jest.config')],
},
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
};
3 changes: 3 additions & 0 deletions e2e/ast-transformers/ng-jit-transformers/ts-jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
stringifyContentPathRegex: '\\.html$',
};
14 changes: 9 additions & 5 deletions e2e/async/jest-isolated.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)$': [
'<rootDir>/../../build/index.js',
{
...require('./ts-jest.config'),
isolatedModules: true,
},
],
},
};
14 changes: 3 additions & 11 deletions e2e/async/jest.config.js
Original file line number Diff line number Diff line change
@@ -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: '<rootDir>/../../build/resolvers/ng-jest-resolver',
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['<rootDir>/../../setup-jest.js'],
transform: { '^.+\\.(ts|mjs|js|html)$': '<rootDir>/../../build/index.js' },
transform: {
'^.+\\.(ts|mjs|js|html)$': ['<rootDir>/../../build/index.js', require('./ts-jest.config')],
},
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
};
8 changes: 8 additions & 0 deletions e2e/async/ts-jest.config.js
Original file line number Diff line number Diff line change
@@ -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',
},
};
16 changes: 8 additions & 8 deletions e2e/babel-support/jest-isolated.config.js
Original file line number Diff line number Diff line change
@@ -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)$': [
'<rootDir>/../../build/index.js',
{
...require('./ts-jest.config'),
isolatedModules: true,
},
],
},
};
7 changes: 1 addition & 6 deletions e2e/babel-support/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
module.exports = {
globals: {
'ts-jest': {
babelConfig: true,
},
},
transform: {
'^.+\\.(ts|js|html)$': '<rootDir>/../../build/index.js',
'^.+\\.(ts|js|html)$': ['<rootDir>/../../build/index.js', require('./ts-jest.config')],
},
};
3 changes: 3 additions & 0 deletions e2e/babel-support/ts-jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
babelConfig: true,
};
11 changes: 7 additions & 4 deletions e2e/custom-typings/jest-isolated.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ const baseCfg = require('./jest.config');

module.exports = {
...baseCfg,
globals: {
'ts-jest': {
isolatedModules: true,
},
transform: {
'^.+\\.(ts|js|html)$': [
'<rootDir>/../../build/index.js',
{
isolatedModules: true,
},
],
},
};
12 changes: 8 additions & 4 deletions e2e/full-ivy-lib/jest-isolated.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ const baseCfg = require('./jest.config');

module.exports = {
...baseCfg,
globals: {
'ts-jest': {
isolatedModules: true,
},
transform: {
...baseCfg.transform,
'^.+\\.(ts|js|mjs|html)$': [
'<rootDir>/../../build/index.js',
{
isolatedModules: true,
},
],
},
};
12 changes: 8 additions & 4 deletions e2e/jest-globals/jest-isolated.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ const baseCfg = require('./jest.config');

module.exports = {
...baseCfg,
globals: {
'ts-jest': {
isolatedModules: true,
},
transform: {
...baseCfg.transform,
'^.+\\.(ts|js|html)$': [
'<rootDir>/../../build/index.js',
{
isolatedModules: true,
},
],
},
};
12 changes: 8 additions & 4 deletions e2e/ng-deep-import/jest-isolated.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ const baseCfg = require('./jest.config');

module.exports = {
...baseCfg,
globals: {
'ts-jest': {
isolatedModules: true,
},
transform: {
...baseCfg.transform,
'^.+\\.(ts|js|mjs|html)$': [
'<rootDir>/../../build/index.js',
{
isolatedModules: true,
},
],
},
};
12 changes: 8 additions & 4 deletions e2e/partial-ivy-lib/jest-isolated.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ const baseCfg = require('./jest.config');

module.exports = {
...baseCfg,
globals: {
'ts-jest': {
isolatedModules: true,
},
transform: {
...baseCfg.transform,
'^.+\\.(ts|js|mjs|html)$': [
'<rootDir>/../../build/index.js',
{
isolatedModules: true,
},
],
},
};
12 changes: 8 additions & 4 deletions e2e/path-mapping/jest-isolated.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ const baseCfg = require('./jest.config');

module.exports = {
...baseCfg,
globals: {
'ts-jest': {
isolatedModules: true,
},
transform: {
...baseCfg.transform,
'^.+\\.(ts|js|html)$': [
'<rootDir>/../../build/index.js',
{
isolatedModules: true,
},
],
},
};
13 changes: 5 additions & 8 deletions e2e/process-js-packages/jest-esm.config.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
export default {
extensionsToTreatAsEsm: ['.ts'],
globals: {
'ts-jest': {
tsconfig: 'tsconfig-esm.spec.json',
extensionsToTreatAsEsm: [".ts"],
transform: {
"^.+\\.(ts|js)$": ["<rootDir>/../../build/index.js", {
tsconfig: "tsconfig-esm.spec.json",
useESM: true,
isolatedModules: true,
},
},
transform: {
'^.+\\.(ts|js)$': '<rootDir>/../../build/index.js',
}],
},
moduleNameMapper: {
'@googlemaps/markerclusterer': '@googlemaps/markerclusterer/dist/index.esm.js',
Expand Down
12 changes: 7 additions & 5 deletions e2e/process-js-packages/jest.config.js
Original file line number Diff line number Diff line change
@@ -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)$': '<rootDir>/../../build/index.js',
'^.+\\.(ts|js|mjs)$': [
'<rootDir>/../../build/index.js',
{
tsconfig: 'tsconfig.spec.json',
isolatedModules: true,
},
],
},
transformIgnorePatterns: ['node_modules/(?!lodash-es)'],
};
13 changes: 8 additions & 5 deletions e2e/snapshot-serializers/jest-isolated.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)$': [
'<rootDir>/../../build/index.js',
{
...require('./ts-jest.config'),
isolatedModules: true,
},
],
},
};
7 changes: 1 addition & 6 deletions e2e/snapshot-serializers/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
module.exports = {
globals: {
'ts-jest': {
stringifyContentPathRegex: '\\.html$',
},
},
resolver: '<rootDir>/../../build/resolvers/ng-jest-resolver',
setupFilesAfterEnv: ['<rootDir>/../../setup-jest.js'],
snapshotSerializers: [
Expand All @@ -13,7 +8,7 @@ module.exports = {
],
testEnvironment: 'jsdom',
transform: {
'^.+\\.(ts|js|mjs|html)$': '<rootDir>/../../build/index.js',
'^.+\\.(ts|js|mjs|html)$': ['<rootDir>/../../build/index.js', require('./ts-jest.config')],
},
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
};
3 changes: 3 additions & 0 deletions e2e/snapshot-serializers/ts-jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
stringifyContentPathRegex: '\\.html$',
};
Original file line number Diff line number Diff line change
@@ -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: '<rootDir>/tsconfig-esm.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
isolatedModules: true,
useESM: true,
},
transform: {
'^.+\\.(ts|js|html|svg)$': [
'jest-preset-angular',
{
tsconfig: '<rootDir>/tsconfig-esm.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
isolatedModules: true,
useESM: true,
},
],
},
};

Expand Down
20 changes: 12 additions & 8 deletions examples/example-app-monorepo/apps/app1/jest-esm.config.mjs
Original file line number Diff line number Diff line change
@@ -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: '<rootDir>/tsconfig-esm.spec.json',
},
},
moduleNameMapper: {
tslib: 'tslib/tslib.es6.js',
rxjs: '<rootDir>/../../node_modules/rxjs/dist/bundles/rxjs.umd.js',
},
setupFilesAfterEnv: ['<rootDir>/setup-jest-esm.ts'],
}
transform: {
'^.+\\.(ts|js|html|svg)$': [
'jest-preset-angular',
{
tsconfig: '<rootDir>/tsconfig-esm.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
useESM: true,
},
],
},
};

export default jestConfig;
Loading

0 comments on commit b0b57a7

Please sign in to comment.