Skip to content

Commit

Permalink
feat(cypress): simplify inferred cypress command (nrwl#21337)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo authored Jan 25, 2024
1 parent f4011ec commit 2faaaf3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
12 changes: 6 additions & 6 deletions packages/cypress/src/plugins/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ describe('@nx/cypress/plugin', () => {
"targets": {
"e2e": {
"cache": true,
"command": "cypress run --config-file cypress.config.js --e2e",
"command": "cypress run",
"configurations": {
"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": [
Expand Down Expand Up @@ -132,7 +132,7 @@ describe('@nx/cypress/plugin', () => {
"targets": {
"component-test": {
"cache": true,
"command": "cypress open --config-file cypress.config.js --component",
"command": "cypress open --component",
"inputs": [
"default",
"^production",
Expand Down Expand Up @@ -190,10 +190,10 @@ describe('@nx/cypress/plugin', () => {
"targets": {
"e2e": {
"cache": true,
"command": "cypress run --config-file cypress.config.js --e2e",
"command": "cypress run",
"configurations": {
"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": [
Expand Down Expand Up @@ -239,7 +239,7 @@ describe('@nx/cypress/plugin', () => {
},
"e2e-ci--src/test.cy.ts": {
"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": [
"default",
"^production",
Expand Down
14 changes: 6 additions & 8 deletions packages/cypress/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const createDependencies: CreateDependencies = () => {
};

export const createNodes: CreateNodes<CypressPluginOptions> = [
'**/cypress.config.{js,ts,mjs,mts,cjs,cts}',
'**/cypress.config.{js,ts,mjs,cjs}',
(configFilePath, options, context) => {
options = normalizeOptions(options);
const projectRoot = dirname(configFilePath);
Expand Down Expand Up @@ -157,15 +157,13 @@ function buildCypressTargets(
const webServerCommands: Record<string, string> =
pluginPresetOptions?.webServerCommands;

const relativeConfigPath = relative(projectRoot, configFilePath);

const namedInputs = getNamedInputs(projectRoot, context);

const targets: Record<string, TargetConfiguration> = {};

if ('e2e' in cypressConfig) {
targets[options.targetName] = {
command: `cypress run --config-file ${relativeConfigPath} --e2e`,
command: `cypress run`,
options: { cwd: projectRoot },
cache: true,
inputs: getInputs(namedInputs),
Expand All @@ -182,7 +180,7 @@ function buildCypressTargets(
webServerCommands ?? {}
)) {
targets[options.targetName].configurations[configuration] = {
command: `cypress run --config-file ${relativeConfigPath} --e2e --env webServerCommand="${webServerCommand}"`,
command: `cypress run --env webServerCommand="${webServerCommand}"`,
};
}
}
Expand Down Expand Up @@ -215,7 +213,7 @@ function buildCypressTargets(
outputs,
inputs,
cache: true,
command: `cypress run --config-file ${relativeConfigPath} --e2e --env webServerCommand="${ciWebServerCommand}" --spec ${relativeSpecFilePath}`,
command: `cypress run --env webServerCommand="${ciWebServerCommand}" --spec ${relativeSpecFilePath}`,
options: {
cwd: projectRoot,
},
Expand All @@ -241,7 +239,7 @@ function buildCypressTargets(
if ('component' in cypressConfig) {
// This will not override the e2e target if it is the same
targets[options.componentTestingTargetName] ??= {
command: `cypress open --config-file ${relativeConfigPath} --component`,
command: `cypress open --component`,
options: { cwd: projectRoot },
cache: true,
inputs: getInputs(namedInputs),
Expand All @@ -259,7 +257,7 @@ function getCypressConfig(
const resolvedPath = join(context.workspaceRoot, configFilePath);

let module: any;
if (['.ts', '.mts', '.cts'].includes(extname(configFilePath))) {
if (extname(configFilePath) === '.ts') {
const tsConfigPath = getRootTsConfigPath();

if (tsConfigPath) {
Expand Down

0 comments on commit 2faaaf3

Please sign in to comment.