feat(cypress): simplify inferred cypress command (#21337)
This commit is contained in:
parent
f4011ec92d
commit
2faaaf3a19
@ -73,10 +73,10 @@ describe('@nx/cypress/plugin', () => {
|
|||||||
"targets": {
|
"targets": {
|
||||||
"e2e": {
|
"e2e": {
|
||||||
"cache": true,
|
"cache": true,
|
||||||
"command": "cypress run --config-file cypress.config.js --e2e",
|
"command": "cypress run",
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"production": {
|
"production": {
|
||||||
"command": "cypress run --config-file cypress.config.js --e2e --env webServerCommand="nx run my-app:serve:production"",
|
"command": "cypress run --env webServerCommand="nx run my-app:serve:production"",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"inputs": [
|
"inputs": [
|
||||||
@ -132,7 +132,7 @@ describe('@nx/cypress/plugin', () => {
|
|||||||
"targets": {
|
"targets": {
|
||||||
"component-test": {
|
"component-test": {
|
||||||
"cache": true,
|
"cache": true,
|
||||||
"command": "cypress open --config-file cypress.config.js --component",
|
"command": "cypress open --component",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
"default",
|
"default",
|
||||||
"^production",
|
"^production",
|
||||||
@ -190,10 +190,10 @@ describe('@nx/cypress/plugin', () => {
|
|||||||
"targets": {
|
"targets": {
|
||||||
"e2e": {
|
"e2e": {
|
||||||
"cache": true,
|
"cache": true,
|
||||||
"command": "cypress run --config-file cypress.config.js --e2e",
|
"command": "cypress run",
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"production": {
|
"production": {
|
||||||
"command": "cypress run --config-file cypress.config.js --e2e --env webServerCommand="my-app:serve:production"",
|
"command": "cypress run --env webServerCommand="my-app:serve:production"",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"inputs": [
|
"inputs": [
|
||||||
@ -239,7 +239,7 @@ describe('@nx/cypress/plugin', () => {
|
|||||||
},
|
},
|
||||||
"e2e-ci--src/test.cy.ts": {
|
"e2e-ci--src/test.cy.ts": {
|
||||||
"cache": true,
|
"cache": true,
|
||||||
"command": "cypress run --config-file cypress.config.js --e2e --env webServerCommand="my-app:serve-static" --spec src/test.cy.ts",
|
"command": "cypress run --env webServerCommand="my-app:serve-static" --spec src/test.cy.ts",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
"default",
|
"default",
|
||||||
"^production",
|
"^production",
|
||||||
|
|||||||
@ -57,7 +57,7 @@ export const createDependencies: CreateDependencies = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const createNodes: CreateNodes<CypressPluginOptions> = [
|
export const createNodes: CreateNodes<CypressPluginOptions> = [
|
||||||
'**/cypress.config.{js,ts,mjs,mts,cjs,cts}',
|
'**/cypress.config.{js,ts,mjs,cjs}',
|
||||||
(configFilePath, options, context) => {
|
(configFilePath, options, context) => {
|
||||||
options = normalizeOptions(options);
|
options = normalizeOptions(options);
|
||||||
const projectRoot = dirname(configFilePath);
|
const projectRoot = dirname(configFilePath);
|
||||||
@ -157,15 +157,13 @@ function buildCypressTargets(
|
|||||||
const webServerCommands: Record<string, string> =
|
const webServerCommands: Record<string, string> =
|
||||||
pluginPresetOptions?.webServerCommands;
|
pluginPresetOptions?.webServerCommands;
|
||||||
|
|
||||||
const relativeConfigPath = relative(projectRoot, configFilePath);
|
|
||||||
|
|
||||||
const namedInputs = getNamedInputs(projectRoot, context);
|
const namedInputs = getNamedInputs(projectRoot, context);
|
||||||
|
|
||||||
const targets: Record<string, TargetConfiguration> = {};
|
const targets: Record<string, TargetConfiguration> = {};
|
||||||
|
|
||||||
if ('e2e' in cypressConfig) {
|
if ('e2e' in cypressConfig) {
|
||||||
targets[options.targetName] = {
|
targets[options.targetName] = {
|
||||||
command: `cypress run --config-file ${relativeConfigPath} --e2e`,
|
command: `cypress run`,
|
||||||
options: { cwd: projectRoot },
|
options: { cwd: projectRoot },
|
||||||
cache: true,
|
cache: true,
|
||||||
inputs: getInputs(namedInputs),
|
inputs: getInputs(namedInputs),
|
||||||
@ -182,7 +180,7 @@ function buildCypressTargets(
|
|||||||
webServerCommands ?? {}
|
webServerCommands ?? {}
|
||||||
)) {
|
)) {
|
||||||
targets[options.targetName].configurations[configuration] = {
|
targets[options.targetName].configurations[configuration] = {
|
||||||
command: `cypress run --config-file ${relativeConfigPath} --e2e --env webServerCommand="${webServerCommand}"`,
|
command: `cypress run --env webServerCommand="${webServerCommand}"`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -215,7 +213,7 @@ function buildCypressTargets(
|
|||||||
outputs,
|
outputs,
|
||||||
inputs,
|
inputs,
|
||||||
cache: true,
|
cache: true,
|
||||||
command: `cypress run --config-file ${relativeConfigPath} --e2e --env webServerCommand="${ciWebServerCommand}" --spec ${relativeSpecFilePath}`,
|
command: `cypress run --env webServerCommand="${ciWebServerCommand}" --spec ${relativeSpecFilePath}`,
|
||||||
options: {
|
options: {
|
||||||
cwd: projectRoot,
|
cwd: projectRoot,
|
||||||
},
|
},
|
||||||
@ -241,7 +239,7 @@ function buildCypressTargets(
|
|||||||
if ('component' in cypressConfig) {
|
if ('component' in cypressConfig) {
|
||||||
// This will not override the e2e target if it is the same
|
// This will not override the e2e target if it is the same
|
||||||
targets[options.componentTestingTargetName] ??= {
|
targets[options.componentTestingTargetName] ??= {
|
||||||
command: `cypress open --config-file ${relativeConfigPath} --component`,
|
command: `cypress open --component`,
|
||||||
options: { cwd: projectRoot },
|
options: { cwd: projectRoot },
|
||||||
cache: true,
|
cache: true,
|
||||||
inputs: getInputs(namedInputs),
|
inputs: getInputs(namedInputs),
|
||||||
@ -259,7 +257,7 @@ function getCypressConfig(
|
|||||||
const resolvedPath = join(context.workspaceRoot, configFilePath);
|
const resolvedPath = join(context.workspaceRoot, configFilePath);
|
||||||
|
|
||||||
let module: any;
|
let module: any;
|
||||||
if (['.ts', '.mts', '.cts'].includes(extname(configFilePath))) {
|
if (extname(configFilePath) === '.ts') {
|
||||||
const tsConfigPath = getRootTsConfigPath();
|
const tsConfigPath = getRootTsConfigPath();
|
||||||
|
|
||||||
if (tsConfigPath) {
|
if (tsConfigPath) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user