From 212dd84cdeb5547d24e743948aa56ef166c88220 Mon Sep 17 00:00:00 2001 From: Caleb Ukle Date: Fri, 12 Aug 2022 14:44:37 -0500 Subject: [PATCH] cleanup(testing): add extra e2e test asserting cypress env var behaviors cypress env arg parsing has had multiple regressions this change asserts the usage of commandline, cypress.env.json file, and executor options will work properly ISSUES CLOSED: #10808 --- e2e/cypress/src/cypress.test.ts | 85 +++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 5 deletions(-) diff --git a/e2e/cypress/src/cypress.test.ts b/e2e/cypress/src/cypress.test.ts index 91b5d26a3f398..62fffefdb7cca 100644 --- a/e2e/cypress/src/cypress.test.ts +++ b/e2e/cypress/src/cypress.test.ts @@ -1,11 +1,13 @@ import { checkFilesExist, + createFile, killPorts, newProject, readJson, runCLI, uniq, updateFile, + updateJson, } from '@nrwl/e2e/utils'; describe('Cypress E2E Test runner', () => { @@ -34,10 +36,53 @@ describe('Cypress E2E Test runner', () => { }, 1000000); it('should execute e2e tests using Cypress', async () => { + // make sure env vars work + createFile( + `apps/${myapp}-e2e/cypress.env.json`, + ` +{ + "cypressEnvJson": "i am from the cypress.env.json file" +}` + ); + + updateJson(`apps/${myapp}-e2e/project.json`, (json) => { + json.targets.e2e.options = { + ...json.targets.e2e.options, + env: { + projectJson: 'i am from the nx project json file', + }, + }; + return json; + }); + createFile( + `apps/${myapp}-e2e/src/e2e/env.cy.ts`, + ` +describe('env vars', () => { + it('should have cli args', () => { + assert.equal(Cypress.env('cliArg'), 'i am from the cli args'); + }); + + it('should have cypress.env.json vars', () => { + assert.equal( + Cypress.env('cypressEnvJson'), + 'i am from the cypress.env.json file' + ); + }); + + it('cli args should not merged project.json vars', () => { + assert.equal( + Cypress.env('projectJson'), + undefined + ); + }); +});` + ); + // contains the correct output and works - const run1 = runCLI(`e2e ${myapp}-e2e --no-watch`); + const run1 = runCLI( + `e2e ${myapp}-e2e --no-watch --env.cliArg="i am from the cli args"` + ); expect(run1).toContain('All specs passed!'); - await killPorts(4200); // tests should not fail because of a config change updateFile( @@ -50,13 +95,43 @@ export default defineConfig({ e2e: { ...nxE2EPreset(__dirname), fixturesFolder: undefined, - } - , + }, });` ); - const run2 = runCLI(`e2e ${myapp}-e2e --no-watch`); + const run2 = runCLI( + `e2e ${myapp}-e2e --no-watch --env.cliArg="i am from the cli args"` + ); expect(run2).toContain('All specs passed!'); + await killPorts(4200); + + // make sure project.json env vars also work + updateFile( + `apps/${myapp}-e2e/src/e2e/env.cy.ts`, + ` +describe('env vars', () => { + it('should not have cli args', () => { + assert.equal(Cypress.env('cliArg'), undefined); + }); + + it('should have cypress.env.json vars', () => { + assert.equal( + Cypress.env('cypressEnvJson'), + 'i am from the cypress.env.json file' + ); + }); + + it('should have project.json vars', () => { + assert.equal( + Cypress.env('projectJson'), + 'i am from the nx project json file' + ); + }); +});` + ); + const run3 = runCLI(`e2e ${myapp}-e2e --no-watch`); + expect(run3).toContain('All specs passed!'); + expect(await killPorts(4200)).toBeTruthy(); }, 1000000); });