Skip to content

Commit

Permalink
fix(repo): ensure cypress is installed for the e2e tests (#12615)
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Oct 14, 2022
1 parent 5fc1ce5 commit d0f590d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions e2e/cypress/src/cypress.test.ts
Expand Up @@ -2,6 +2,7 @@ import {
checkFilesExist,
cleanupProject,
createFile,
ensureCypressInstallation,
killPorts,
newProject,
readJson,
Expand All @@ -16,6 +17,7 @@ describe('Cypress E2E Test runner', () => {

beforeAll(() => {
newProject();
ensureCypressInstallation();
});

afterAll(() => cleanupProject());
Expand Down
32 changes: 30 additions & 2 deletions e2e/utils/index.ts
@@ -1,5 +1,4 @@
import {
createProjectGraphAsync,
joinPathFragments,
parseJson,
ProjectConfiguration,
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit d0f590d

Please sign in to comment.