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

feat(misc): remove usages of @nx/cypress:cypress-project internally #19766

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
"type": "string",
"description": "A directory where the project is placed relative from the project root",
"default": "cypress"
},
"jsx": {
"description": "Whether or not this project uses JSX.",
"type": "boolean",
"default": true
}
},
"required": ["project"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@
"enum": ["vite", "webpack", "none"],
"x-prompt": "Which Cypress bundler do you want to use?",
"default": "webpack"
},
"jsx": {
"description": "Whether or not this project uses JSX.",
"type": "boolean",
"default": true
}
},
"required": ["project"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@
"description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
"default": false
},
"standaloneConfig": {
"description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside workspace.json.",
"type": "boolean",
"default": true,
"x-deprecated": "Nx only supports standaloneConfig"
},
"skipPackageJson": {
"type": "boolean",
"default": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@
"enum": ["eslint", "none"],
"default": "eslint"
},
"standaloneConfig": {
"description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
"type": "boolean",
"default": true,
"x-deprecated": "Nx only supports standaloneConfig"
},
"ciTargetName": {
"type": "string",
"description": "The name of the devServerTarget to use for the Cypress CI configuration. Used to control if using <storybook-project>:static-storybook:ci or <storybook-project>:storybook:ci",
Expand All @@ -49,6 +43,11 @@
"type": "boolean",
"default": false,
"x-priority": "internal"
},
"projectNameAndRootFormat": {
"description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
"type": "string",
"enum": ["as-provided", "derived"]
}
},
"required": ["name"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh
"compilerOptions": {
"allowJs": true,
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
Expand All @@ -383,9 +384,12 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh
},
"extends": "../../../tsconfig.base.json",
"include": [
"src/**/*.ts",
"src/**/*.js",
"**/*.ts",
"**/*.js",
"cypress.config.ts",
"**/*.cy.ts",
"**/*.cy.js",
"**/*.d.ts",
],
}
`;
Expand Down Expand Up @@ -609,6 +613,7 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh
"compilerOptions": {
"allowJs": true,
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
Expand All @@ -623,9 +628,12 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh
},
"extends": "../../tsconfig.base.json",
"include": [
"src/**/*.ts",
"src/**/*.js",
"**/*.ts",
"**/*.js",
"cypress.config.ts",
"**/*.cy.ts",
"**/*.cy.js",
"**/*.d.ts",
jaysoo marked this conversation as resolved.
Show resolved Hide resolved
],
}
`;
Expand Down Expand Up @@ -874,6 +882,7 @@ exports[`app --strict should enable strict type checking: e2e tsconfig.json 1`]
"compilerOptions": {
"allowJs": true,
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
Expand All @@ -888,9 +897,12 @@ exports[`app --strict should enable strict type checking: e2e tsconfig.json 1`]
},
"extends": "../tsconfig.base.json",
"include": [
"src/**/*.ts",
"src/**/*.js",
"**/*.ts",
"**/*.js",
"cypress.config.ts",
"**/*.cy.ts",
"**/*.cy.js",
"**/*.d.ts",
],
}
`;
Expand Down Expand Up @@ -1218,6 +1230,7 @@ exports[`app not nested should generate files: e2e tsconfig.json 1`] = `
"compilerOptions": {
"allowJs": true,
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
Expand All @@ -1232,9 +1245,12 @@ exports[`app not nested should generate files: e2e tsconfig.json 1`] = `
},
"extends": "../tsconfig.base.json",
"include": [
"src/**/*.ts",
"src/**/*.js",
"**/*.ts",
"**/*.js",
"cypress.config.ts",
"**/*.cy.ts",
"**/*.cy.js",
"**/*.d.ts",
],
}
`;
Expand Down
23 changes: 14 additions & 9 deletions packages/angular/src/generators/application/lib/add-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,27 @@ import {
} from '@nx/devkit';
import { nxVersion } from '../../../utils/versions';
import type { NormalizedSchema } from './normalized-schema';
import { cypressProjectGenerator } from '@nx/cypress';
import { configurationGenerator } from '@nx/cypress';

export async function addE2e(tree: Tree, options: NormalizedSchema) {
if (options.e2eTestRunner === 'cypress') {
// TODO: This can call `@nx/web:static-config` generator when ready
addFileServerTarget(tree, options, 'serve-static');

await cypressProjectGenerator(tree, {
name: options.e2eProjectName,
directory: options.e2eProjectRoot,
// the name and root are already normalized, instruct the generator to use them as is
projectNameAndRootFormat: 'as-provided',
project: options.name,
addProjectConfiguration(tree, options.e2eProjectName, {
projectType: 'application',
root: options.e2eProjectRoot,
sourceRoot: joinPathFragments(options.e2eProjectRoot, 'src'),
targets: {},
tags: [],
implicitDependencies: [options.name],
});
await configurationGenerator(tree, {
project: options.e2eProjectName,
directory: 'src',
linter: options.linter,
standaloneConfig: options.standaloneConfig,
skipPackageJson: options.skipPackageJson,
skipFormat: true,
devServerTarget: `${options.name}:serve:development`,
});
} else if (options.e2eTestRunner === 'playwright') {
const { configurationGenerator: playwrightConfigurationGenerator } =
Expand All @@ -35,6 +39,7 @@ export async function addE2e(tree: Tree, options: NormalizedSchema) {
nxVersion
);
addProjectConfiguration(tree, options.e2eProjectName, {
projectType: 'application',
root: options.e2eProjectRoot,
sourceRoot: joinPathFragments(options.e2eProjectRoot, 'src'),
targets: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { librarySecondaryEntryPointGenerator } from '../library-secondary-entry-
import { generateTestApplication, generateTestLibrary } from '../utils/testing';
import { cypressComponentConfiguration } from './cypress-component-configuration';

let projectGraph: ProjectGraph;
let projectGraph: ProjectGraph = { nodes: {}, dependencies: {} };
jest.mock('@nx/cypress/src/utils/cypress-version');
jest.mock('@nx/devkit', () => ({
...jest.requireActual<any>('@nx/devkit'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,11 @@ export class E2eMigrator extends ProjectMigrator<SupportedTargets> {
private async migrateCypressE2eProject(): Promise<void> {
const oldCypressConfigFilePath = this.getOldCypressConfigFilePath();

// TODO(v18): This needs to be removed before v18 since the generator is going away.
await cypressProjectGenerator(this.tree, {
name: this.project.name,
project: this.appName,
linter: this.isProjectUsingEsLint ? Linter.EsLint : Linter.None,
standaloneConfig: true,
skipFormat: true,
});

Expand Down
9 changes: 7 additions & 2 deletions packages/cypress/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { configurationGenerator } from './src/generators/configuration/configuration';
import { componentConfigurationGenerator } from './src/generators/component-configuration/component-configuration';
import { cypressProjectGenerator as _cypressProjectGenerator } from './src/generators/cypress-project/cypress-project';

export { configurationGenerator, componentConfigurationGenerator };

// Maintain backwards compatibility with the old names in case community plugins used them.
/** @deprecated Use `configurationGenerator` instead. */
// TODO(v18): Remove old name
/** @deprecated Use `configurationGenerator` instead. It will be removed in Nx 18. */
export const cypressComponentConfiguration = componentConfigurationGenerator;

export { configurationGenerator as cypressE2EConfigurationGenerator };
export { cypressProjectGenerator } from './src/generators/cypress-project/cypress-project';
// TODO(v18): Remove project generator
/** @deprecated Add a new project and call `configurationGenerator` instead. It will be removed in Nx 18. */
export const cypressProjectGenerator = _cypressProjectGenerator;
export { cypressInitGenerator } from './src/generators/init/init';
export { migrateCypressProject } from './src/generators/migrate-to-cypress-11/migrate-to-cypress-11';
2 changes: 2 additions & 0 deletions packages/cypress/src/generators/base-setup/base-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface CypressBaseSetupSchema {
* default is `cypress`
* */
directory?: string;
jsx?: boolean;
}

export function addBaseCypressSetup(
Expand All @@ -33,6 +34,7 @@ export function addBaseCypressSetup(

generateFiles(tree, join(__dirname, 'files'), projectConfig.root, {
...opts,
jsx: !!opts.jsx,
offsetFromRoot: offsetFromRoot(projectConfig.root),
offsetFromProjectRoot: opts.hasTsConfig ? opts.offsetFromProjectRoot : '',
tsConfigPath: opts.hasTsConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"**/*.js",
"<%= offsetFromProjectRoot %>cypress.config.ts",
"<%= offsetFromProjectRoot %>**/*.cy.ts",
"<%= offsetFromProjectRoot %>**/*.cy.tsx",
<% if (jsx) { %> "<%= offsetFromProjectRoot %>**/*.cy.tsx",<% } %>
"<%= offsetFromProjectRoot %>**/*.cy.js",
"<%= offsetFromProjectRoot %>**/*.cy.jsx",
<% if (jsx) { %>"<%= offsetFromProjectRoot %>**/*.cy.jsx",<% } %>
"<%= offsetFromProjectRoot %>**/*.d.ts"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ describe('Cypress Component Configuration', () => {
await componentConfigurationGenerator(tree, {
project: 'cool-lib',
skipFormat: false,
jsx: true,
});
const projectConfig = readProjectConfiguration(tree, 'cool-lib');
expect(tree.exists('libs/cool-lib/cypress.config.ts')).toEqual(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function addProjectFiles(
addBaseCypressSetup(tree, {
project: opts.project,
directory: opts.directory,
jsx: opts.jsx,
});

generateFiles(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export interface CypressComponentConfigurationSchema {
skipFormat: boolean;
directory?: string;
bundler?: 'webpack' | 'vite';
jsx?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
"type": "string",
"description": "A directory where the project is placed relative from the project root",
"default": "cypress"
},
"jsx": {
"description": "Whether or not this project uses JSX.",
"type": "boolean",
"default": true
}
},
"required": ["project"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ describe('Cypress e2e configuration', () => {
expect(readProjectConfiguration(tree, 'my-app').targets.e2e)
.toMatchInlineSnapshot(`
{
"configurations": {
"production": {
"devServerTarget": "my-app:serve:production",
},
},
"executor": "@nx/cypress:cypress",
"options": {
"cypressConfig": "apps/my-app/cypress.config.ts",
Expand Down Expand Up @@ -85,9 +80,7 @@ describe('Cypress e2e configuration', () => {
"**/*.js",
"cypress.config.ts",
"**/*.cy.ts",
"**/*.cy.tsx",
"**/*.cy.js",
"**/*.cy.jsx",
"**/*.d.ts",
],
}
Expand Down Expand Up @@ -208,9 +201,7 @@ describe('Cypress e2e configuration', () => {
"**/*.js",
"../../cypress.config.ts",
"../../**/*.cy.ts",
"../../**/*.cy.tsx",
"../../**/*.cy.js",
"../../**/*.cy.jsx",
"../../**/*.d.ts",
],
}
Expand Down
27 changes: 19 additions & 8 deletions packages/cypress/src/generators/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface CypressE2EConfigSchema {
devServerTarget?: string;
linter?: Linter;
port?: number | 'cypress-auto';
jsx?: boolean;
}

type NormalizedSchema = ReturnType<typeof normalizeOptions>;
Expand All @@ -55,10 +56,12 @@ export async function configurationGenerator(
}
await addFiles(tree, opts);
addTarget(tree, opts);
addLinterToCyProject(tree, {

const linterTask = await addLinterToCyProject(tree, {
...opts,
cypressDir: opts.directory,
});
tasks.push(linterTask);

if (!opts.skipFormat) {
await formatFiles(tree);
Expand Down Expand Up @@ -132,6 +135,7 @@ async function addFiles(tree: Tree, options: NormalizedSchema) {
addBaseCypressSetup(tree, {
project: options.project,
directory: options.directory,
jsx: options.jsx,
});

const cyFile = joinPathFragments(projectConfig.root, 'cypress.config.ts');
Expand Down Expand Up @@ -197,18 +201,25 @@ function addTarget(tree: Tree, opts: NormalizedSchema) {
port: opts.port,
};

projectConfig.targets.e2e.configurations = {
[parsedTarget.configuration || 'production']: {
devServerTarget: `${opts.devServerTarget}${
parsedTarget.configuration ? '' : ':production'
}`,
},
};
const devServerProjectConfig = readProjectConfiguration(
tree,
parsedTarget.project
);
// Add production e2e target if serve target is found
if (
parsedTarget.configuration !== 'production' &&
devServerProjectConfig.targets?.[parsedTarget.target]?.configurations?.[
'production'
]
) {
projectConfig.targets.e2e.configurations ??= {};
projectConfig.targets.e2e.configurations['production'] = {
devServerTarget: `${parsedTarget.project}:${parsedTarget.target}:production`,
};
}
// Add ci/static e2e target if serve target is found
if (devServerProjectConfig.targets?.['serve-static']) {
projectConfig.targets.e2e.configurations ??= {};
projectConfig.targets.e2e.configurations.ci = {
devServerTarget: `${parsedTarget.project}:serve-static`,
};
Expand Down
Loading