cleanup(misc): increase cypress web server timeout in flaky e2e tests (#22069)

This commit is contained in:
Leosvel Pérez Espinosa 2024-02-29 15:02:35 +01:00 committed by GitHub
parent c523d52414
commit 036e31764c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 33 additions and 50 deletions

View File

@ -13,6 +13,7 @@ import {
runCLI, runCLI,
runCommandUntil, runCommandUntil,
runE2ETests, runE2ETests,
setCypressWebServerTimeout,
tmpProjPath, tmpProjPath,
uniq, uniq,
updateFile, updateFile,
@ -127,6 +128,7 @@ describe('Angular Projects', () => {
// check e2e tests // check e2e tests
if (runE2ETests('cypress')) { if (runE2ETests('cypress')) {
setCypressWebServerTimeout(`${app1}-e2e/cypress.config.ts`);
const e2eResults = runCLI(`e2e ${app1}-e2e`); const e2eResults = runCLI(`e2e ${app1}-e2e`);
expect(e2eResults).toContain('All specs passed!'); expect(e2eResults).toContain('All specs passed!');
expect(await killPort(4200)).toBeTruthy(); expect(await killPort(4200)).toBeTruthy();

View File

@ -4,11 +4,11 @@ import {
cleanupProject, cleanupProject,
killProcessAndPorts, killProcessAndPorts,
newProject, newProject,
readFile,
readJson, readJson,
runCLI, runCLI,
runCommandUntil, runCommandUntil,
runE2ETests, runE2ETests,
setCypressWebServerTimeout,
uniq, uniq,
updateFile, updateFile,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
@ -377,20 +377,8 @@ describe('Angular Module Federation', () => {
const buildRemoteOutput = runCLI(`build ${remote}`); const buildRemoteOutput = runCLI(`build ${remote}`);
expect(buildRemoteOutput).toContain('Successfully ran target build'); expect(buildRemoteOutput).toContain('Successfully ran target build');
// increase default timeout for the Cypress web server, MF apps can take longer to start
const cypressConfig = readFile(`${host}-e2e/cypress.config.ts`);
updateFile(
`${host}-e2e/cypress.config.ts`,
cypressConfig.replace(
`nxE2EPreset(__filename, {`,
`nxE2EPreset(__filename, {
webServerConfig: {
timeout: 60000,
},`
)
);
if (runE2ETests('cypress')) { if (runE2ETests('cypress')) {
setCypressWebServerTimeout(`${host}-e2e/cypress.config.ts`);
const e2eProcess = await runCommandUntil(`e2e ${host}-e2e`, (output) => const e2eProcess = await runCommandUntil(`e2e ${host}-e2e`, (output) =>
output.includes('All specs passed!') output.includes('All specs passed!')
); );
@ -481,20 +469,8 @@ describe('Angular Module Federation', () => {
const buildRemoteOutput = runCLI(`build ${remote}`); const buildRemoteOutput = runCLI(`build ${remote}`);
expect(buildRemoteOutput).toContain('Successfully ran target build'); expect(buildRemoteOutput).toContain('Successfully ran target build');
// increase default timeout for the Cypress web server, MF apps can take longer to start
const cypressConfig = readFile(`${host}-e2e/cypress.config.ts`);
updateFile(
`${host}-e2e/cypress.config.ts`,
cypressConfig.replace(
`nxE2EPreset(__filename, {`,
`nxE2EPreset(__filename, {
webServerConfig: {
timeout: 60000,
},`
)
);
if (runE2ETests('cypress')) { if (runE2ETests('cypress')) {
setCypressWebServerTimeout(`${host}-e2e/cypress.config.ts`);
const e2eProcess = await runCommandUntil(`e2e ${host}-e2e`, (output) => const e2eProcess = await runCommandUntil(`e2e ${host}-e2e`, (output) =>
output.includes('All specs passed!') output.includes('All specs passed!')
); );

View File

@ -7,6 +7,7 @@ import {
readJson, readJson,
runCLI, runCLI,
runE2ETests, runE2ETests,
setCypressWebServerTimeout,
uniq, uniq,
updateFile, updateFile,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
@ -76,6 +77,7 @@ describe('env vars', () => {
); );
if (runE2ETests('cypress')) { if (runE2ETests('cypress')) {
setCypressWebServerTimeout(`apps/${myapp}-e2e/cypress.config.ts`);
// contains the correct output and works // contains the correct output and works
const run1 = runCLI( const run1 = runCLI(
`e2e ${myapp}-e2e --config \\'{\\"env\\":{\\"cliArg\\":\\"i am from the cli args\\"}}\\'` `e2e ${myapp}-e2e --config \\'{\\"env\\":{\\"cliArg\\":\\"i am from the cli args\\"}}\\'`
@ -98,6 +100,9 @@ export default defineConfig({
production: 'nx run ${myapp}:preview', production: 'nx run ${myapp}:preview',
}, },
ciWebServerCommand: 'nx run ${myapp}:serve-static', ciWebServerCommand: 'nx run ${myapp}:serve-static',
webServerConfig: {
timeout: 60_000,
},
}), }),
baseUrl: 'http://localhost:4200', baseUrl: 'http://localhost:4200',
}, },
@ -164,6 +169,7 @@ export default defineConfig({
); );
if (runE2ETests('cypress')) { if (runE2ETests('cypress')) {
setCypressWebServerTimeout(`apps/${appName}/cypress.config.ts`);
expect(runCLI(`run ${appName}:component-test`)).toContain( expect(runCLI(`run ${appName}:component-test`)).toContain(
'All specs passed!' 'All specs passed!'
); );
@ -192,6 +198,7 @@ export default defineConfig({
); );
if (runE2ETests('cypress')) { if (runE2ETests('cypress')) {
setCypressWebServerTimeout(`apps/${appName}/cypress.config.ts`);
expect(runCLI(`run ${appName}:component-test`)).toContain( expect(runCLI(`run ${appName}:component-test`)).toContain(
'All specs passed!' 'All specs passed!'
); );

View File

@ -6,6 +6,7 @@ import {
readFile, readFile,
runCLI, runCLI,
runE2ETests, runE2ETests,
setCypressWebServerTimeout,
uniq, uniq,
updateFile, updateFile,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
@ -192,28 +193,8 @@ describe('Next.js Applications', () => {
`generate @nx/next:app ${appName} --no-interactive --style=css --project-name-and-root-format=as-provided` `generate @nx/next:app ${appName} --no-interactive --style=css --project-name-and-root-format=as-provided`
); );
// Update the cypress timeout to 25 seconds since we need to build and wait for the server to start if (runE2ETests('cypress')) {
updateFile(`${appName}-e2e/cypress.config.ts`, (_) => { setCypressWebServerTimeout(`${appName}-e2e/cypress.config.ts`);
return `import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
import { defineConfig } from 'cypress';
export default defineConfig({
e2e: {
...nxE2EPreset(__filename, {
cypressDir: 'src',
webServerCommands: { default: 'nx run ${appName}:start' },
webServerConfig: { timeout: 25_000 },
ciWebServerCommand: 'nx run ${appName}:serve-static',
}),
baseUrl: 'http://localhost:3000',
},
});
`;
});
if (runE2ETests()) {
const e2eResults = runCLI(`e2e-ci ${appName}-e2e --verbose`, { const e2eResults = runCLI(`e2e-ci ${appName}-e2e --verbose`, {
verbose: true, verbose: true,
}); });

View File

@ -6,7 +6,7 @@ import {
runCommand, runCommand,
} from './command-utils'; } from './command-utils';
import { uniq } from './create-project-utils'; import { uniq } from './create-project-utils';
import { readFile } from './file-utils'; import { readFile, updateFile } from './file-utils';
type GeneratorsWithDefaultTests = type GeneratorsWithDefaultTests =
| '@nx/js:lib' | '@nx/js:lib'
@ -57,3 +57,20 @@ export function expectNoTsJestInJestConfig(appName: string) {
export function expectCodeIsFormatted() { export function expectCodeIsFormatted() {
expect(() => runCLI(`format:check`)).not.toThrow(); expect(() => runCLI(`format:check`)).not.toThrow();
} }
export function setCypressWebServerTimeout(
cypressConfigPath: string,
timeout = 60_000
) {
const cypressConfig = readFile(cypressConfigPath);
updateFile(
cypressConfigPath,
cypressConfig.replace(
`nxE2EPreset(__filename, {`,
`nxE2EPreset(__filename, {
webServerConfig: {
timeout: ${timeout},
},`
)
);
}