-
Notifications
You must be signed in to change notification settings - Fork 2.6k
chore(repo): split slow e2e tests - ng-add, cypress, eslint linter, a… #33012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f9e7107
chore(repo): split slow e2e tests - ng-add, cypress, eslint linter, a…
rarmatei ca8ca1f
Merge remote-tracking branch 'upstream/master' into split-remaining-s…
rarmatei e75377a
Merge branch 'master' into split-remaining-slow-e2e-1
lourw 3b3b7b5
chore(repo): fix failing tests
rarmatei a4c559f
chore(repo): undo ng-add split
rarmatei 8632f17
chore(repo): fix failing tests
rarmatei 5baba3d
chore(repo): fix failing tests
rarmatei 51869f2
chore(repo): fix failing tests
rarmatei d32f582
Merge branch 'master' into split-remaining-slow-e2e-1
rarmatei a7b5713
chore(repo): fix failing tests
rarmatei 8c1461b
chore(repo): combine git tests
rarmatei ede1187
chore(repo): bust cache
rarmatei cda692b
chore(repo): run conflicting tests serially
rarmatei e40e2c3
chore(repo): switch all e2e tests to run serially
rarmatei 6ff36b1
chore(core): merge upstream/master into split-remaining-slow-e2e-1
rarmatei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { killPort, runCLI, runE2ETests, uniq } from '@nx/e2e-utils'; | ||
| import { setupCypressTest, cleanupCypressTest } from './cypress-setup'; | ||
|
|
||
| const TEN_MINS_MS = 600_000; | ||
|
|
||
| describe('Cypress E2E Test runner', () => { | ||
| beforeAll(() => { | ||
| setupCypressTest(); | ||
| }); | ||
|
|
||
| afterAll(() => cleanupCypressTest()); | ||
|
|
||
| it( | ||
| `should allow CT and e2e in same project for an angular project`, | ||
| async () => { | ||
| let appName = uniq(`angular-cy-app`); | ||
| runCLI( | ||
| `generate @nx/angular:app apps/${appName} --e2eTestRunner=none --no-interactive --bundler=webpack` | ||
| ); | ||
| runCLI( | ||
| `generate @nx/angular:component apps/${appName}/src/app/btn/btn --no-interactive` | ||
| ); | ||
| runCLI( | ||
| `generate @nx/angular:cypress-component-configuration --project=${appName} --generate-tests --no-interactive` | ||
| ); | ||
| runCLI( | ||
| `generate @nx/cypress:e2e --project=${appName} --baseUrl=http://localhost:4200 --no-interactive` | ||
| ); | ||
|
|
||
| if (runE2ETests('cypress')) { | ||
| expect(runCLI(`run ${appName}:component-test`)).toContain( | ||
| 'All specs passed!' | ||
| ); | ||
| expect(runCLI(`run ${appName}:e2e`)).toContain('All specs passed!'); | ||
| } | ||
| expect(await killPort(4200)).toBeTruthy(); | ||
| }, | ||
| TEN_MINS_MS | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { killPort, runCLI, runE2ETests, uniq } from '@nx/e2e-utils'; | ||
| import { setupCypressTest, cleanupCypressTest } from './cypress-setup'; | ||
|
|
||
| const TEN_MINS_MS = 600_000; | ||
|
|
||
| describe('Cypress E2E Test runner', () => { | ||
| beforeAll(() => { | ||
| setupCypressTest(); | ||
| }); | ||
|
|
||
| afterAll(() => cleanupCypressTest()); | ||
|
|
||
| it( | ||
| `should allow CT and e2e in same project for a next project`, | ||
| async () => { | ||
| const appName = uniq('next-cy-app'); | ||
| runCLI( | ||
| `generate @nx/next:app apps/${appName} --e2eTestRunner=none --no-interactive ` | ||
| ); | ||
| runCLI( | ||
| `generate @nx/next:component apps/${appName}/components/btn --no-interactive` | ||
| ); | ||
| runCLI( | ||
| `generate @nx/next:cypress-component-configuration --project=${appName} --generate-tests --no-interactive` | ||
| ); | ||
| runCLI( | ||
| `generate @nx/cypress:configuration --project=${appName} --devServerTarget=${appName}:dev --baseUrl=http://localhost:3000 --no-interactive` | ||
| ); | ||
|
|
||
| if (runE2ETests('cypress')) { | ||
| expect(runCLI(`run ${appName}:component-test`)).toContain( | ||
| 'All specs passed!' | ||
| ); | ||
| expect(runCLI(`run ${appName}:e2e`)).toContain('All specs passed!'); | ||
| } | ||
| expect(await killPort(4200)).toBeTruthy(); | ||
| }, | ||
| TEN_MINS_MS | ||
| ); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| import { | ||
| checkFilesExist, | ||
| createFile, | ||
| readJson, | ||
| runCLI, | ||
| runE2ETests, | ||
| updateFile, | ||
| } from '@nx/e2e-utils'; | ||
| import { setupCypressTest, cleanupCypressTest } from './cypress-setup'; | ||
|
|
||
| const TEN_MINS_MS = 600_000; | ||
|
|
||
| describe('Cypress E2E Test runner', () => { | ||
| let myapp: string; | ||
|
|
||
| beforeAll(() => { | ||
| const context = setupCypressTest(); | ||
| myapp = context.myapp; | ||
| runCLI( | ||
| `generate @nx/react:app apps/${myapp} --e2eTestRunner=cypress --linter=eslint` | ||
| ); | ||
| }); | ||
|
|
||
| afterAll(() => cleanupCypressTest()); | ||
|
|
||
| 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" | ||
| }` | ||
| ); | ||
|
|
||
| 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' | ||
| ); | ||
| }); | ||
| });` | ||
| ); | ||
|
|
||
| if (runE2ETests('cypress')) { | ||
| // contains the correct output and works | ||
| const run1 = runCLI( | ||
| `e2e ${myapp}-e2e --config \\'{\\"env\\":{\\"cliArg\\":\\"i am from the cli args\\"}}\\'` | ||
| ); | ||
| expect(run1).toContain('All specs passed!'); | ||
| // tests should not fail because of a config change | ||
| updateFile( | ||
| `apps/${myapp}-e2e/cypress.config.ts`, | ||
| ` | ||
| import { defineConfig } from 'cypress'; | ||
| import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'; | ||
|
|
||
| export default defineConfig({ | ||
| e2e: { | ||
| ...nxE2EPreset(__filename, { | ||
| cypressDir: 'src', | ||
| webServerCommands: { | ||
| default: 'nx run ${myapp}:serve', | ||
| production: 'nx run ${myapp}:preview', | ||
| }, | ||
| ciWebServerCommand: 'nx run ${myapp}:serve-static', | ||
| webServerConfig: { | ||
| timeout: 60_000, | ||
| }, | ||
| }), | ||
| baseUrl: 'http://localhost:4200', | ||
| }, | ||
| env: { | ||
| fromCyConfig: 'i am from the cypress config file' | ||
| } | ||
| });` | ||
| ); | ||
|
|
||
| const run2 = runCLI( | ||
| `e2e ${myapp}-e2e --config \\'{\\"env\\":{\\"cliArg\\":\\"i am from the cli args\\"}}\\'` | ||
| ); | ||
| expect(run2).toContain('All specs passed!'); | ||
|
|
||
| // make sure project.json env vars also work | ||
| checkFilesExist(`apps/${myapp}-e2e/src/e2e/env.cy.ts`); | ||
| 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 cypress config vars', () => { | ||
| assert.equal( | ||
| Cypress.env('fromCyConfig'), | ||
| 'i am from the cypress config file' | ||
| ); | ||
| }); | ||
| });` | ||
| ); | ||
| const run3 = runCLI(`e2e ${myapp}-e2e`); | ||
| expect(run3).toContain('All specs passed!'); | ||
| } | ||
| }, | ||
| TEN_MINS_MS | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { checkFilesExist, readJson, runCLI } from '@nx/e2e-utils'; | ||
| import { setupCypressTest, cleanupCypressTest } from './cypress-setup'; | ||
|
|
||
| const TEN_MINS_MS = 600_000; | ||
|
|
||
| describe('Cypress E2E Test runner', () => { | ||
| let myapp: string; | ||
|
|
||
| beforeAll(() => { | ||
| const context = setupCypressTest(); | ||
| myapp = context.myapp; | ||
| }); | ||
|
|
||
| afterAll(() => cleanupCypressTest()); | ||
|
|
||
| it( | ||
| 'should generate an app with the Cypress as e2e test runner', | ||
| () => { | ||
| runCLI( | ||
| `generate @nx/react:app apps/${myapp} --e2eTestRunner=cypress --linter=eslint` | ||
| ); | ||
|
|
||
| // Making sure the package.json file contains the Cypress dependency | ||
| const packageJson = readJson('package.json'); | ||
| expect(packageJson.devDependencies['cypress']).toBeTruthy(); | ||
|
|
||
| // Making sure the cypress folders & files are created | ||
| checkFilesExist(`apps/${myapp}-e2e/cypress.config.ts`); | ||
| checkFilesExist(`apps/${myapp}-e2e/tsconfig.json`); | ||
|
|
||
| checkFilesExist(`apps/${myapp}-e2e/src/fixtures/example.json`); | ||
| checkFilesExist(`apps/${myapp}-e2e/src/e2e/app.cy.ts`); | ||
| checkFilesExist(`apps/${myapp}-e2e/src/support/app.po.ts`); | ||
| checkFilesExist(`apps/${myapp}-e2e/src/support/e2e.ts`); | ||
| checkFilesExist(`apps/${myapp}-e2e/src/support/commands.ts`); | ||
| }, | ||
| TEN_MINS_MS | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { cleanupProject, newProject, uniq } from '@nx/e2e-utils'; | ||
|
|
||
| export interface CypressTestContext { | ||
| myapp: string; | ||
| } | ||
|
|
||
| export function setupCypressTest(): CypressTestContext { | ||
| const myapp = uniq('myapp'); | ||
| newProject({ packages: ['@nx/angular', '@nx/next', '@nx/react'] }); | ||
| return { myapp }; | ||
| } | ||
|
|
||
| export function cleanupCypressTest() { | ||
| cleanupProject(); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The port being killed (4200) doesn't match the port configured for the Next.js app (3000). Consider updating line 36 to
expect(await killPort(3000)).toBeTruthy();to ensure the correct port is terminated after the test completes.Spotted by Graphite Agent

Is this helpful? React 👍 or 👎 to let us know.