Skip to content

Commit

Permalink
refactor: deprecate ngcc-jest-processor and replace with global set…
Browse files Browse the repository at this point in the history
…up (#1275)
  • Loading branch information
ahnpnl authored Jan 16, 2022
1 parent 62409e1 commit 75e7368
Show file tree
Hide file tree
Showing 19 changed files with 34 additions and 18 deletions.
2 changes: 1 addition & 1 deletion examples/example-app-v11/jest-esm.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require('jest-preset-angular/ngcc-jest-processor');
const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { paths } = require('./tsconfig.json').compilerOptions;

Expand All @@ -12,6 +11,7 @@ module.exports = {
tsconfig: '<rootDir>/tsconfig-esm.spec.json',
},
},
globalSetup: 'jest-preset-angular/global-setup',
moduleNameMapper: {
...pathsToModuleNameMapper(paths, { prefix: '<rootDir>' }),
tslib: 'tslib/tslib.es6.js',
Expand Down
2 changes: 1 addition & 1 deletion examples/example-app-v11/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require('jest-preset-angular/ngcc-jest-processor');
const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { paths } = require('./tsconfig.json').compilerOptions;

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'jest-preset-angular',
globalSetup: 'jest-preset-angular/global-setup',
moduleNameMapper: pathsToModuleNameMapper(paths, { prefix: '<rootDir>' }),
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
};
1 change: 1 addition & 0 deletions examples/example-app-v12-monorepo/jest-esm.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
globalSetup: 'jest-preset-angular/global-setup',
projects: ['<rootDir>/projects/app1/jest-esm.config.js', '<rootDir>/projects/app2/jest-esm.config.js'],
};
1 change: 1 addition & 0 deletions examples/example-app-v12-monorepo/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
globalSetup: 'jest-preset-angular/global-setup',
projects: ['<rootDir>/projects/app1', '<rootDir>/projects/app2'],
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require('jest-preset-angular/ngcc-jest-processor');

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'jest-preset-angular/presets/defaults-esm',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require('jest-preset-angular/ngcc-jest-processor');

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'jest-preset-angular',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require('jest-preset-angular/ngcc-jest-processor');

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'jest-preset-angular/presets/defaults-esm',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require('jest-preset-angular/ngcc-jest-processor');

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'jest-preset-angular',
Expand Down
2 changes: 1 addition & 1 deletion examples/example-app-v12/jest-esm.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require('jest-preset-angular/ngcc-jest-processor');
const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { paths } = require('./tsconfig.json').compilerOptions;

Expand All @@ -12,6 +11,7 @@ module.exports = {
tsconfig: '<rootDir>/tsconfig-esm.spec.json',
},
},
globalSetup: 'jest-preset-angular/global-setup',
moduleNameMapper: {
...pathsToModuleNameMapper(paths, { prefix: '<rootDir>' }),
tslib: 'tslib/tslib.es6.js',
Expand Down
2 changes: 1 addition & 1 deletion examples/example-app-v12/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require('jest-preset-angular/ngcc-jest-processor');
const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { paths } = require('./tsconfig.json').compilerOptions;

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'jest-preset-angular',
globalSetup: 'jest-preset-angular/global-setup',
moduleNameMapper: pathsToModuleNameMapper(paths, { prefix: '<rootDir>' }),
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
};
2 changes: 1 addition & 1 deletion examples/example-app-v13/jest-esm.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require('jest-preset-angular/ngcc-jest-processor');
const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { paths } = require('./tsconfig.json').compilerOptions;

Expand All @@ -12,6 +11,7 @@ module.exports = {
tsconfig: '<rootDir>/tsconfig-esm.spec.json',
},
},
globalSetup: 'jest-preset-angular/global-setup',
moduleNameMapper: {
...pathsToModuleNameMapper(paths, { prefix: '<rootDir>' }),
tslib: 'tslib/tslib.es6.js',
Expand Down
2 changes: 1 addition & 1 deletion examples/example-app-v13/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require('jest-preset-angular/ngcc-jest-processor');
const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { paths } = require('./tsconfig.json').compilerOptions;

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'jest-preset-angular',
globalSetup: 'jest-preset-angular/global-setup',
moduleNameMapper: pathsToModuleNameMapper(paths, { prefix: '<rootDir>' }),
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require('jest-preset-angular/ngcc-jest-processor');
const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { paths } = require('./tsconfig.json').compilerOptions;

Expand All @@ -12,6 +11,7 @@ module.exports = {
tsconfig: '<rootDir>/tsconfig-esm.spec.json',
},
},
globalSetup: 'jest-preset-angular/global-setup',
moduleNameMapper: {
...pathsToModuleNameMapper(paths, { prefix: '<rootDir>' }),
tslib: 'tslib/tslib.es6.js',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require('jest-preset-angular/ngcc-jest-processor');
const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { paths } = require('./tsconfig.json').compilerOptions;

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'jest-preset-angular',
globalSetup: 'jest-preset-angular/global-setup',
moduleNameMapper: pathsToModuleNameMapper(paths, { prefix: '<rootDir>' }),
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
};
1 change: 1 addition & 0 deletions global-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./build/config/global-setup');
10 changes: 10 additions & 0 deletions ngcc-jest-processor.js
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
console.warn(
'ng-jest-processor is deprecated and will be removed in the next major version v12.' +
' Please use jest-preset-angular/global-setup in Jest config instead, e.g. \n' +
`
module.exports = {
globalSetup: 'jest-preset-angular/global-setup',
};
`
);

module.exports = require('./build/utils/ngcc-jest-processor');
10 changes: 9 additions & 1 deletion scripts/test-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ const executeTest = (projectPath) => {
logger.log('installing bundled version of jest-preset-angular');
logger.log();

['build', 'presets', 'jest-preset.js', 'ngcc-jest-processor.js', 'package.json', 'setup-jest.js'].forEach((asset) => {
[
'build',
'presets',
'global-setup.js',
'jest-preset.js',
'ngcc-jest-processor.js',
'package.json',
'setup-jest.js',
].forEach((asset) => {
const assetToReplace = join(projectPath, 'node_modules', 'jest-preset-angular', asset);
const assetToCopy = join(rootDir, asset);
copySync(assetToCopy, assetToReplace);
Expand Down
3 changes: 3 additions & 0 deletions src/config/global-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export = async () => {
await import('../utils/ngcc-jest-processor');
};
2 changes: 1 addition & 1 deletion src/utils/ngcc-jest-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const nodeModuleDirPath = findNodeModulesDirectory();

if (!process.argv.find((arg) => IGNORE_ARGS.includes(arg))) {
if (nodeModuleDirPath) {
process.stdout.write('ngcc-jest-processor: running ngcc\n');
process.stdout.write('\nngcc-jest-processor: running ngcc\n');
// We spawn instead of using the API because:
// - NGCC Async uses clustering which is problematic when used via the API which means
// that we cannot setup multiple cluster masters with different options.
Expand Down

0 comments on commit 75e7368

Please sign in to comment.