diff --git a/e2e/cypress/src/cypress.test.ts b/e2e/cypress/src/cypress.test.ts index 61feae4b9dbe2..df92558d33bd8 100644 --- a/e2e/cypress/src/cypress.test.ts +++ b/e2e/cypress/src/cypress.test.ts @@ -2,6 +2,7 @@ import { checkFilesExist, cleanupProject, createFile, + ensureCypressInstallation, killPorts, newProject, readJson, @@ -16,6 +17,7 @@ describe('Cypress E2E Test runner', () => { beforeAll(() => { newProject(); + ensureCypressInstallation(); }); afterAll(() => cleanupProject()); diff --git a/e2e/utils/index.ts b/e2e/utils/index.ts index 1b44b1420935d..cd4b5bada5e99 100644 --- a/e2e/utils/index.ts +++ b/e2e/utils/index.ts @@ -1,5 +1,4 @@ import { - createProjectGraphAsync, joinPathFragments, parseJson, ProjectConfiguration, @@ -399,7 +398,36 @@ export async function cleanupProject(opts?: RunCmdOpts) { } export function runCypressTests() { - return process.env.NX_E2E_RUN_CYPRESS === 'true'; + if (process.env.NX_E2E_RUN_CYPRESS === 'true') { + ensureCypressInstallation(); + return true; + } + return false; +} + +export function ensureCypressInstallation() { + let cypressVerified = true; + try { + const r = execSync('npx cypress verify', { + stdio: 'inherit', + encoding: 'utf-8', + cwd: tmpProjPath(), + }); + if (r.indexOf('Verified Cypress!') === -1) { + cypressVerified = false; + } + } catch { + cypressVerified = false; + } finally { + if (!cypressVerified) { + e2eConsoleLogger('Cypress was not verified. Installing Cypress now.'); + execSync('npx cypress install', { + stdio: 'inherit', + encoding: 'utf-8', + cwd: tmpProjPath(), + }); + } + } } export function isNotWindows() {