feat(testing): rename jest-project generator to "configuration" generator for consistency in naming (#18006)

This commit is contained in:
Jack Hsu 2023-07-07 16:17:41 -04:00 committed by GitHub
parent 5a7ffb93c9
commit 38fa586b78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 176 additions and 78 deletions

View File

@ -5174,9 +5174,9 @@
"disableCollapsible": false
},
{
"id": "jest-project",
"path": "/packages/jest/generators/jest-project",
"name": "jest-project",
"id": "configuration",
"path": "/packages/jest/generators/configuration",
"name": "configuration",
"children": [],
"isExternal": false,
"disableCollapsible": false

View File

@ -963,13 +963,13 @@
"path": "/packages/jest/generators/init",
"type": "generator"
},
"/packages/jest/generators/jest-project": {
"/packages/jest/generators/configuration": {
"description": "Add Jest configuration to a project.",
"file": "generated/packages/jest/generators/jest-project.json",
"file": "generated/packages/jest/generators/configuration.json",
"hidden": true,
"name": "jest-project",
"originalFilePath": "/packages/jest/src/generators/jest-project/schema.json",
"path": "/packages/jest/generators/jest-project",
"name": "configuration",
"originalFilePath": "/packages/jest/src/generators/configuration/schema.json",
"path": "/packages/jest/generators/configuration",
"type": "generator"
}
},

View File

@ -950,11 +950,11 @@
},
{
"description": "Add Jest configuration to a project.",
"file": "generated/packages/jest/generators/jest-project.json",
"file": "generated/packages/jest/generators/configuration.json",
"hidden": true,
"name": "jest-project",
"originalFilePath": "/packages/jest/src/generators/jest-project/schema.json",
"path": "jest/generators/jest-project",
"name": "configuration",
"originalFilePath": "/packages/jest/src/generators/configuration/schema.json",
"path": "jest/generators/configuration",
"type": "generator"
}
],

View File

@ -0,0 +1,89 @@
{
"name": "configuration",
"factory": "./src/generators/configuration/configuration",
"schema": {
"$schema": "http://json-schema.org/schema",
"$id": "NxJestProject",
"cli": "nx",
"title": "Add Jest Configuration to a project",
"description": "Add Jest Configuration to a project.",
"type": "object",
"properties": {
"project": {
"type": "string",
"description": "The name of the project.",
"$default": { "$source": "projectName" },
"x-priority": "important"
},
"skipSetupFile": {
"type": "boolean",
"description": "Skips the setup file required for angular.",
"default": false,
"x-deprecated": "Use `--setup-file` instead."
},
"setupFile": {
"type": "string",
"enum": ["none", "angular", "web-components"],
"description": "The setup file to be generated.",
"default": "none",
"x-priority": "important"
},
"skipSerializers": {
"type": "boolean",
"description": "Skips the serializers required to snapshot angular templates.",
"default": false
},
"supportTsx": {
"type": "boolean",
"description": "Setup `tsx` support.",
"default": false,
"x-priority": "important"
},
"testEnvironment": {
"type": "string",
"enum": ["jsdom", "node", "none"],
"description": "The test environment for jest.",
"default": "jsdom",
"x-priority": "important"
},
"compiler": {
"type": "string",
"enum": ["tsc", "babel", "swc"],
"description": "The compiler to use for source and tests.",
"default": "tsc"
},
"babelJest": {
"type": "boolean",
"alias": "babel-jest",
"description": "Use `babel-jest` instead of `ts-jest`.",
"x-deprecated": "Use `--compiler=babel` instead.",
"default": false
},
"skipFormat": {
"description": "Skip formatting files",
"type": "boolean",
"default": false,
"x-priority": "internal"
},
"skipPackageJson": {
"type": "boolean",
"default": false,
"description": "Do not add dependencies to `package.json`.",
"x-priority": "internal"
},
"js": {
"type": "boolean",
"default": false,
"description": "Use JavaScript instead of TypeScript for config files"
}
},
"required": [],
"presets": []
},
"description": "Add Jest configuration to a project.",
"hidden": true,
"implementation": "/packages/jest/src/generators/configuration/configuration.ts",
"aliases": [],
"path": "/packages/jest/src/generators/configuration/schema.json",
"type": "generator"
}

View File

@ -393,7 +393,7 @@
- [jest](/packages/jest/executors/jest)
- [generators](/packages/jest/generators)
- [init](/packages/jest/generators/init)
- [jest-project](/packages/jest/generators/jest-project)
- [configuration](/packages/jest/generators/configuration)
- [js](/packages/js)
- [documents](/packages/js/documents)
- [Overview](/packages/js/documents/overview)

View File

@ -164,8 +164,8 @@ describe('nx-dev: Packages Section', () => {
{ title: '@nx/jest', path: '/packages/jest' },
{ title: '@nx/jest:init', path: '/packages/jest/generators/init' },
{
title: '@nx/jest:jest-project',
path: '/packages/jest/generators/jest-project',
title: '@nx/jest:configuration',
path: '/packages/jest/generators/configuration',
},
{ title: '@nx/jest', path: '/packages/jest/executors/jest' },
{ title: '@nx/js', path: '/packages/js' },

View File

@ -150,6 +150,8 @@ const schemaUrls = {
'/packages/cypress/generators/component-configuration',
'/packages/esbuild/generators/esbuild-project':
'/packages/esbuild/generators/configuration',
'/packages/jest/generators/jest-project':
'/packages/jest/generators/configuration',
'/packages/nx-plugin/generators/executor':
'/packages/plugin/generators/executor',
'/packages/nx-plugin/generators/migration':

View File

@ -1,13 +1,13 @@
import { Tree, joinPathFragments } from '@nx/devkit';
import type { NormalizedSchema } from './normalized-schema';
import { jestProjectGenerator } from '@nx/jest';
import { configurationGenerator } from '@nx/jest';
import { UnitTestRunner } from '../../../utils/test-runners';
export async function addUnitTestRunner(host: Tree, options: NormalizedSchema) {
if (options.unitTestRunner === UnitTestRunner.Jest) {
await jestProjectGenerator(host, {
await configurationGenerator(host, {
project: options.name,
setupFile: 'angular',
supportTsx: false,

View File

@ -5,7 +5,7 @@ import {
joinPathFragments,
Tree,
} from '@nx/devkit';
import { jestProjectGenerator } from '@nx/jest';
import { configurationGenerator } from '@nx/jest';
import { Linter } from '@nx/linter';
import { addTsConfigPath } from '@nx/js';
import { lt } from 'semver';
@ -124,7 +124,7 @@ async function addUnitTestRunner(
options: NormalizedSchema['libraryOptions']
) {
if (options.unitTestRunner === 'jest') {
await jestProjectGenerator(host, {
await configurationGenerator(host, {
project: options.name,
setupFile: 'angular',
supportTsx: false,

View File

@ -1,5 +1,5 @@
import { Tree } from '@nx/devkit';
import { jestProjectGenerator } from '@nx/jest';
import { configurationGenerator } from '@nx/jest';
export async function addJest(
host: Tree,
@ -13,7 +13,7 @@ export async function addJest(
return () => {};
}
const jestTask = await jestProjectGenerator(host, {
const jestTask = await configurationGenerator(host, {
js,
project: projectName,
supportTsx: true,

View File

@ -9,9 +9,9 @@
"aliases": ["ng-add"],
"hidden": true
},
"jest-project": {
"factory": "./src/generators/jest-project/jest-project#jestProjectSchematic",
"schema": "./src/generators/jest-project/schema.json",
"configuration": {
"factory": "./src/generators/configuration/configuration#compat",
"schema": "./src/generators/configuration/schema.json",
"description": "Add Jest configuration to a project.",
"hidden": true
}
@ -24,9 +24,9 @@
"aliases": ["ng-add"],
"hidden": true
},
"jest-project": {
"factory": "./src/generators/jest-project/jest-project#jestProjectGenerator",
"schema": "./src/generators/jest-project/schema.json",
"configuration": {
"factory": "./src/generators/configuration/configuration",
"schema": "./src/generators/configuration/schema.json",
"description": "Add Jest configuration to a project.",
"hidden": true
}

View File

@ -1,9 +1,15 @@
import { configurationGenerator } from './src/generators/configuration/configuration';
export { configurationGenerator };
// Exported for backwards compatibility in case a plugin is using the old name.
/** @deprecated Use `configurationGenerator` instead. */
export const jestProjectGenerator = configurationGenerator;
export {
addPropertyToJestConfig,
removePropertyFromJestConfig,
} from './src/utils/config/update-config';
export { jestConfigObjectAst } from './src/utils/config/functions';
export { jestProjectGenerator } from './src/generators/jest-project/jest-project';
export { jestInitGenerator } from './src/generators/init/init';
export {
getJestProjects,

View File

@ -8,7 +8,7 @@ import {
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { jestConfigObject } from '../../utils/config/functions';
import { jestProjectGenerator } from './jest-project';
import configurationGenerator from './configuration';
import { JestProjectSchema } from './schema.d';
describe('jestProject', () => {
@ -45,7 +45,7 @@ describe('jestProject', () => {
});
it('should generate files', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
setupFile: 'angular',
@ -61,7 +61,7 @@ describe('jestProject', () => {
});
it('should alter project configuration', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
setupFile: 'angular',
@ -87,7 +87,7 @@ describe('jestProject', () => {
});
it('should create a jest.config.ts', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
} as JestProjectSchema);
@ -95,7 +95,7 @@ describe('jestProject', () => {
});
it('should add a reference to solution tsconfig.json', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
} as JestProjectSchema);
@ -106,7 +106,7 @@ describe('jestProject', () => {
});
it('should create a tsconfig.spec.json', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
setupFile: 'angular',
@ -132,7 +132,7 @@ describe('jestProject', () => {
describe('--setup-file', () => {
it('should generate src/test-setup.ts', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
} as JestProjectSchema);
@ -143,7 +143,7 @@ describe('jestProject', () => {
});
it('should have setupFilesAfterEnv in the jest.config when generated for web-components', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
setupFile: 'web-components',
@ -154,7 +154,7 @@ describe('jestProject', () => {
});
it('should have setupFilesAfterEnv and globals.ts-jest in the jest.config when generated for angular', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
setupFile: 'angular',
@ -168,7 +168,7 @@ describe('jestProject', () => {
});
it('should not list the setup file in project configuration', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
setupFile: 'none',
@ -178,7 +178,7 @@ describe('jestProject', () => {
});
it('should not list the setup file in tsconfig.spec.json', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
setupFile: 'none',
@ -190,7 +190,7 @@ describe('jestProject', () => {
describe('--skip-setup-file', () => {
it('should generate src/test-setup.ts', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
skipSetupFile: true,
@ -199,7 +199,7 @@ describe('jestProject', () => {
});
it('should not list the setup file in project configuration', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
skipSetupFile: true,
@ -209,7 +209,7 @@ describe('jestProject', () => {
});
it('should not list the setup file in tsconfig.spec.json', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
skipSetupFile: true,
@ -221,7 +221,7 @@ describe('jestProject', () => {
describe('--skip-serializers', () => {
it('should not list the serializers in jest.config.ts', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
skipSerializers: true,
@ -239,7 +239,7 @@ describe('jestProject', () => {
describe('--support-tsx', () => {
it('should add jest.transform', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
supportTsx: true,
@ -254,7 +254,7 @@ describe('jestProject', () => {
});
it('should add tsx to moduleExtensions', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
supportTsx: true,
@ -270,7 +270,7 @@ describe('jestProject', () => {
});
it('should create jest.config.js with --js flag', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
js: true,
@ -284,7 +284,7 @@ describe('jestProject', () => {
});
it('should use jest.config.js in project config with --js flag', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
js: true,
@ -297,7 +297,7 @@ describe('jestProject', () => {
it('should always use jest.preset.js with --js', async () => {
tree.write('jest.preset.ts', '');
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
js: true,
@ -309,7 +309,7 @@ describe('jestProject', () => {
});
it('should use module.exports with --js flag', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
js: true,
@ -322,7 +322,7 @@ describe('jestProject', () => {
describe('--babelJest', () => {
it('should generate proper jest.transform when babelJest is true', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
babelJest: true,
@ -338,7 +338,7 @@ describe('jestProject', () => {
});
it('should generate proper jest.transform when babelJest and supportTsx is true', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
babelJest: true,
@ -348,7 +348,7 @@ describe('jestProject', () => {
});
it('should generate proper jest.transform when --compiler=swc and supportTsx is true', async () => {
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
compiler: 'swc',
@ -371,7 +371,7 @@ describe('jestProject', () => {
name: 'my-project',
targets: {},
});
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'my-project',
});
@ -402,7 +402,7 @@ describe('jestProject', () => {
name: 'my-project',
targets: {},
});
await jestProjectGenerator(tree, {
await configurationGenerator(tree, {
...defaultOptions,
project: 'my-project',
js: true,

View File

@ -56,7 +56,7 @@ function normalizeOptions(
};
}
export async function jestProjectGenerator(
export async function configurationGenerator(
tree: Tree,
schema: JestProjectSchema
): Promise<GeneratorCallback> {
@ -74,4 +74,6 @@ export async function jestProjectGenerator(
return installTask;
}
export const jestProjectSchematic = convertNxGenerator(jestProjectGenerator);
export default configurationGenerator;
export const compat = convertNxGenerator(configurationGenerator);

View File

@ -68,7 +68,7 @@ function createJestConfig(tree: Tree, options: NormalizedSchema) {
addTestInputs(tree);
}
if (options.rootProject) {
// we don't want any config to be made because the `jestProjectGenerator`
// we don't want any config to be made because the `configurationGenerator` will do it.
// will copy the template config file
return;
}

View File

@ -366,8 +366,8 @@ async function addJest(
tree: Tree,
options: NormalizedSchema
): Promise<GeneratorCallback> {
const { jestProjectGenerator } = ensurePackage('@nx/jest', nxVersion);
return await jestProjectGenerator(tree, {
const { configurationGenerator } = ensurePackage('@nx/jest', nxVersion);
return await configurationGenerator(tree, {
...options,
project: options.name,
setupFile: 'none',

View File

@ -30,10 +30,9 @@ export async function lintWorkspaceRulesProjectGenerator(
tree: Tree,
options: LintWorkspaceRulesProjectGeneratorOptions = {}
) {
const { addPropertyToJestConfig, jestProjectGenerator } = ensurePackage(
'@nx/jest',
nxVersion
);
const { addPropertyToJestConfig, configurationGenerator } = ensurePackage<
typeof import('@nx/jest')
>('@nx/jest', nxVersion);
// Noop if the workspace rules project already exists
try {
@ -70,7 +69,7 @@ export async function lintWorkspaceRulesProjectGenerator(
}
// Add jest to the project and return installation task
const installTask = await jestProjectGenerator(tree, {
const installTask = await configurationGenerator(tree, {
project: WORKSPACE_RULES_PROJECT_NAME,
supportTsx: false,
skipSerializers: true,

View File

@ -14,11 +14,11 @@ export async function addJest(host: Tree, options: NormalizedSchema) {
return () => {};
}
const { jestProjectGenerator } = ensurePackage<typeof import('@nx/jest')>(
const { configurationGenerator } = ensurePackage<typeof import('@nx/jest')>(
'@nx/jest',
nxVersion
);
const jestTask = await jestProjectGenerator(host, {
const jestTask = await configurationGenerator(host, {
...options,
project: options.projectName,
supportTsx: true,

View File

@ -23,7 +23,7 @@ import {
updateTsConfigsToJs,
} from '@nx/devkit';
import { Linter, lintProjectGenerator } from '@nx/linter';
import { jestProjectGenerator } from '@nx/jest';
import { configurationGenerator } from '@nx/jest';
import { getRelativePathToRootTsConfig, tsConfigBaseOptions } from '@nx/js';
import { join } from 'path';
@ -391,7 +391,7 @@ export async function applicationGenerator(tree: Tree, schema: Schema) {
}
if (options.unitTestRunner === 'jest') {
const jestTask = await jestProjectGenerator(tree, {
const jestTask = await configurationGenerator(tree, {
...options,
project: options.name,
setupFile: 'none',

View File

@ -16,7 +16,7 @@ import {
runTasksInSerial,
updateProjectConfiguration,
} from '@nx/devkit';
import { addPropertyToJestConfig, jestProjectGenerator } from '@nx/jest';
import { addPropertyToJestConfig, configurationGenerator } from '@nx/jest';
import { getRelativePathToRootTsConfig } from '@nx/js';
import { setupVerdaccio } from '@nx/js/src/generators/setup-verdaccio/generator';
import { addLocalRegistryScripts } from '@nx/js/src/utils/add-local-registry-scripts';
@ -93,7 +93,7 @@ async function addJest(host: Tree, options: NormalizedSchema) {
implicitDependencies: [options.pluginName],
});
const jestTask = await jestProjectGenerator(host, {
const jestTask = await configurationGenerator(host, {
project: options.projectName,
setupFile: 'none',
supportTsx: false,

View File

@ -1,5 +1,5 @@
import { Tree } from '@nx/devkit';
import { jestProjectGenerator } from '@nx/jest';
import { configurationGenerator } from '@nx/jest';
export async function addJest(
host: Tree,
@ -13,7 +13,7 @@ export async function addJest(
return () => {};
}
const jestTask = await jestProjectGenerator(host, {
const jestTask = await configurationGenerator(host, {
js,
project: projectName,
supportTsx: true,

View File

@ -6,7 +6,7 @@ export async function addJest(
host: Tree,
options: NormalizedSchema
): Promise<GeneratorCallback> {
const { jestProjectGenerator } = ensurePackage<typeof import('@nx/jest')>(
const { configurationGenerator } = ensurePackage<typeof import('@nx/jest')>(
'@nx/jest',
nxVersion
);
@ -15,7 +15,7 @@ export async function addJest(
return () => {};
}
return await jestProjectGenerator(host, {
return await configurationGenerator(host, {
...options,
project: options.projectName,
supportTsx: true,

View File

@ -84,12 +84,12 @@ export async function libraryGenerator(host: Tree, schema: Schema) {
// Set up test target
if (options.unitTestRunner === 'jest') {
const { jestProjectGenerator } = ensurePackage<typeof import('@nx/jest')>(
const { configurationGenerator } = ensurePackage<typeof import('@nx/jest')>(
'@nx/jest',
nxVersion
);
const jestTask = await jestProjectGenerator(host, {
const jestTask = await configurationGenerator(host, {
...options,
project: options.name,
setupFile: 'none',

View File

@ -273,10 +273,10 @@ export async function applicationGenerator(host: Tree, schema: Schema) {
tasks.push(cypressTask);
}
if (options.unitTestRunner === 'jest') {
const { jestProjectGenerator } = await ensurePackage<
const { configurationGenerator } = await ensurePackage<
typeof import('@nx/jest')
>('@nx/jest', nxVersion);
const jestTask = await jestProjectGenerator(host, {
const jestTask = await configurationGenerator(host, {
project: options.projectName,
skipSerializers: true,
setupFile: 'web-components',