Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: deprecate ngcc-jest-processor and replace with global setup #1275

Merged
merged 1 commit into from
Jan 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.' +

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be ngcc-jest-processor

' 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