From 99cfe5146de739a518fdf3584b94b004a183f7e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Thu, 28 Mar 2024 12:27:48 +0100 Subject: [PATCH] feat(testing): infer open-cypress task --- .../generators/application/application.spec.ts | 2 ++ .../cypress/src/generators/init/init.spec.ts | 2 ++ packages/cypress/src/generators/init/init.ts | 2 ++ packages/cypress/src/plugins/plugin.spec.ts | 18 ++++++++++++++++++ packages/cypress/src/plugins/plugin.ts | 7 +++++++ 5 files changed, 31 insertions(+) diff --git a/packages/angular/src/generators/application/application.spec.ts b/packages/angular/src/generators/application/application.spec.ts index b838a1e60b373..0e58f6287fccf 100644 --- a/packages/angular/src/generators/application/application.spec.ts +++ b/packages/angular/src/generators/application/application.spec.ts @@ -553,7 +553,9 @@ describe('app', () => { [ { "options": { + "ciTargetName": "e2e-ci", "componentTestingTargetName": "component-test", + "openTargetName": "open-cypress", "targetName": "e2e", }, "plugin": "@nx/cypress/plugin", diff --git a/packages/cypress/src/generators/init/init.spec.ts b/packages/cypress/src/generators/init/init.spec.ts index 7b44f8309a5e5..0b43f78e4aa66 100644 --- a/packages/cypress/src/generators/init/init.spec.ts +++ b/packages/cypress/src/generators/init/init.spec.ts @@ -80,7 +80,9 @@ describe('init', () => { "plugins": [ { "options": { + "ciTargetName": "e2e-ci", "componentTestingTargetName": "component-test", + "openTargetName": "open-cypress", "targetName": "e2e", }, "plugin": "@nx/cypress/plugin", diff --git a/packages/cypress/src/generators/init/init.ts b/packages/cypress/src/generators/init/init.ts index 0431d0bffdfa3..f4b0fafc864cc 100644 --- a/packages/cypress/src/generators/init/init.ts +++ b/packages/cypress/src/generators/init/init.ts @@ -74,6 +74,8 @@ export function addPlugin(tree: Tree) { options: { targetName: 'e2e', componentTestingTargetName: 'component-test', + ciTargetName: 'e2e-ci', + openTargetName: 'open-cypress', } as CypressPluginOptions, }); updateNxJson(tree, nxJson); diff --git a/packages/cypress/src/plugins/plugin.spec.ts b/packages/cypress/src/plugins/plugin.spec.ts index 38314bc73355e..d6b511b94b7d4 100644 --- a/packages/cypress/src/plugins/plugin.spec.ts +++ b/packages/cypress/src/plugins/plugin.spec.ts @@ -102,6 +102,12 @@ describe('@nx/cypress/plugin', () => { "{projectRoot}/dist/screenshots", ], }, + "open-cypress": { + "command": "cypress open", + "options": { + "cwd": ".", + }, + }, }, }, }, @@ -161,6 +167,12 @@ describe('@nx/cypress/plugin', () => { "{projectRoot}/dist/screenshots", ], }, + "open-cypress": { + "command": "cypress open", + "options": { + "cwd": ".", + }, + }, }, }, }, @@ -279,6 +291,12 @@ describe('@nx/cypress/plugin', () => { "{projectRoot}/dist/cypress/screenshots", ], }, + "open-cypress": { + "command": "cypress open", + "options": { + "cwd": ".", + }, + }, }, }, }, diff --git a/packages/cypress/src/plugins/plugin.ts b/packages/cypress/src/plugins/plugin.ts index ac6b405f9cb16..5229fd9a6b65e 100644 --- a/packages/cypress/src/plugins/plugin.ts +++ b/packages/cypress/src/plugins/plugin.ts @@ -26,6 +26,7 @@ import { loadConfigFile } from '@nx/devkit/src/utils/config-utils'; export interface CypressPluginOptions { ciTargetName?: string; targetName?: string; + openTargetName?: string; componentTestingTargetName?: string; } @@ -268,12 +269,18 @@ async function buildCypressTargets( }; } + targets[options.openTargetName] = { + command: `cypress open`, + options: { cwd: projectRoot }, + }; + return { targets, targetGroups }; } function normalizeOptions(options: CypressPluginOptions): CypressPluginOptions { options ??= {}; options.targetName ??= 'e2e'; + options.openTargetName ??= 'open-cypress'; options.componentTestingTargetName ??= 'component-test'; options.ciTargetName ??= 'e2e-ci'; return options;