Skip to content
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

fix(testing): playwright plugin clean up #18447

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ jobs:
GIT_COMMITTER_NAME: Test
NX_E2E_CI_CACHE_KEY: e2e-circleci-<< parameters.os >>
SELECTED_PM: << parameters.pm >>
NX_E2E_RUN_CYPRESS: 'true'
NX_E2E_RUN_E2E: 'true'
NX_VERBOSE_LOGGING: 'false'
NX_NATIVE_LOGGING: 'false'
NX_PERF_LOGGING: 'false'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ jobs:
YARN_REGISTRY: http://localhost:4872
NX_CACHE_DIRECTORY: 'tmp'
NX_E2E_SKIP_BUILD_CLEANUP: 'true'
NX_E2E_RUN_CYPRESS: 'true'
NX_E2E_RUN_E2E: 'true'
NX_E2E_VERBOSE_LOGGING: 'true'
NX_PERF_LOGGING: 'false'
NX_DAEMON: 'true'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ jobs:
npm_config_registry: http://localhost:4872
NX_CACHE_DIRECTORY: 'tmp'
NX_E2E_SKIP_BUILD_CLEANUP: 'true'
NX_E2E_RUN_CYPRESS: 'true'
NX_E2E_RUN_E2E: 'true'
NX_E2E_VERBOSE_LOGGING: 'true'
NX_PERF_LOGGING: 'false'
NX_DAEMON: 'true'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@
"uiPort": {
"type": "string",
"description": "Port to serve UI on, 0 for any free port; specifying this option opens UI in a browser tab"
},
"skipInstall": {
"type": "boolean",
"description": "Skip running playwright install before running playwright tests. This is to ensure that playwright browsers are installed before running tests.",
"default": false
}
},
"required": [],
Expand Down
5 changes: 5 additions & 0 deletions docs/generated/packages/playwright/generators/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
"default": false,
"description": "Do not add dependencies to `package.json`.",
"x-priority": "internal"
},
"skipInstall": {
"type": "boolean",
"description": "Skip running `playwright install`. This is to ensure that playwright browsers are installed.",
"default": false
}
},
"required": [],
Expand Down
8 changes: 3 additions & 5 deletions e2e/angular-core/src/projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { names } from '@nx/devkit';
import {
checkFilesExist,
cleanupProject,
ensurePlaywrightBrowsersInstallation,
getSize,
killPorts,
killProcessAndPorts,
Expand All @@ -11,7 +10,7 @@ import {
removeFile,
runCLI,
runCommandUntil,
runCypressTests,
runE2ETests,
tmpProjPath,
uniq,
updateFile,
Expand Down Expand Up @@ -98,7 +97,7 @@ describe('Angular Projects', () => {
);

// check e2e tests
if (runCypressTests()) {
if (runE2ETests()) {
const e2eResults = runCLI(`e2e ${app1}-e2e --no-watch`);
expect(e2eResults).toContain('All specs passed!');
expect(await killPorts()).toBeTruthy();
Expand Down Expand Up @@ -131,8 +130,7 @@ describe('Angular Projects', () => {
`generate @nx/angular:app ${app} --e2eTestRunner=playwright --no-interactive`
);

if (runCypressTests()) {
ensurePlaywrightBrowsersInstallation();
if (runE2ETests()) {
const e2eResults = runCLI(`e2e ${app}-e2e`);
expect(e2eResults).toContain(
`Successfully ran target e2e for project ${app}-e2e`
Expand Down
14 changes: 7 additions & 7 deletions e2e/angular-extensions/src/cypress-component-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
createFile,
newProject,
runCLI,
runCypressTests,
runE2ETests,
uniq,
updateFile,
updateProjectConfig,
Expand Down Expand Up @@ -39,7 +39,7 @@ describe('Angular Cypress Component Tests', () => {
runCLI(
`generate @nx/angular:cypress-component-configuration --project=${appName} --generate-tests --no-interactive`
);
if (runCypressTests()) {
if (runE2ETests()) {
expect(runCLI(`component-test ${appName} --no-watch`)).toContain(
'All specs passed!'
);
Expand All @@ -50,7 +50,7 @@ describe('Angular Cypress Component Tests', () => {
runCLI(
`generate @nx/angular:cypress-component-configuration --project=${usedInAppLibName} --generate-tests --no-interactive`
);
if (runCypressTests()) {
if (runE2ETests()) {
expect(runCLI(`component-test ${usedInAppLibName} --no-watch`)).toContain(
'All specs passed!'
);
Expand All @@ -70,7 +70,7 @@ describe('Angular Cypress Component Tests', () => {
runCLI(
`generate @nx/angular:cypress-component-configuration --project=${buildableLibName} --generate-tests --build-target=${appName}:build --no-interactive`
);
if (runCypressTests()) {
if (runE2ETests()) {
expect(runCLI(`component-test ${buildableLibName} --no-watch`)).toContain(
'All specs passed!'
);
Expand All @@ -92,7 +92,7 @@ describe('Angular Cypress Component Tests', () => {
}
);

if (runCypressTests()) {
if (runE2ETests()) {
expect(runCLI(`component-test ${buildableLibName} --no-watch`)).toContain(
'All specs passed!'
);
Expand All @@ -108,7 +108,7 @@ describe('Angular Cypress Component Tests', () => {

updateBuilableLibTestsToAssertAppStyles(appName, buildableLibName);

if (runCypressTests()) {
if (runE2ETests()) {
expect(runCLI(`component-test ${buildableLibName} --no-watch`)).toContain(
'All specs passed!'
);
Expand All @@ -122,7 +122,7 @@ describe('Angular Cypress Component Tests', () => {
checkFilesExist('tailwind.config.js');
checkFilesDoNotExist(`libs/${buildableLibName}/tailwind.config.js`);

if (runCypressTests()) {
if (runE2ETests()) {
expect(runCLI(`component-test ${buildableLibName} --no-watch`)).toContain(
'All specs passed!'
);
Expand Down
6 changes: 3 additions & 3 deletions e2e/cypress/src/cypress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
newProject,
readJson,
runCLI,
runCypressTests,
runE2ETests,
uniq,
updateFile,
updateJson,
Expand Down Expand Up @@ -200,15 +200,15 @@ async function testCtAndE2eInProject(
`generate @nx/${projectType}:cypress-component-configuration --project=${appName} --generate-tests --no-interactive`
);

if (runCypressTests()) {
if (runE2ETests()) {
expect(runCLI(`run ${appName}:component-test --no-watch`)).toContain(
'All specs passed!'
);
}

runCLI(`generate @nx/cypress:e2e --project=${appName} --no-interactive`);

if (runCypressTests()) {
if (runE2ETests()) {
expect(runCLI(`run ${appName}:e2e --no-watch`)).toContain(
'All specs passed!'
);
Expand Down
14 changes: 7 additions & 7 deletions e2e/next/src/next-component-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
createFile,
newProject,
runCLI,
runCypressTests,
runE2ETests,
uniq,
updateFile,
} from '@nx/e2e/utils';
Expand All @@ -17,13 +17,13 @@ describe('NextJs Component Testing', () => {
it('should test a NextJs app', () => {
const appName = uniq('next-app');
createAppWithCt(appName);
if (runCypressTests()) {
if (runE2ETests()) {
expect(runCLI(`component-test ${appName} --no-watch`)).toContain(
'All specs passed!'
);
}
addTailwindToApp(appName);
if (runCypressTests()) {
if (runE2ETests()) {
expect(runCLI(`component-test ${appName} --no-watch`)).toContain(
'All specs passed!'
);
Expand All @@ -33,13 +33,13 @@ describe('NextJs Component Testing', () => {
it('should test a NextJs lib', async () => {
const libName = uniq('next-lib');
createLibWithCt(libName, false);
if (runCypressTests()) {
if (runE2ETests()) {
expect(runCLI(`component-test ${libName} --no-watch`)).toContain(
'All specs passed!'
);
}
addTailwindToLib(libName);
if (runCypressTests()) {
if (runE2ETests()) {
expect(runCLI(`component-test ${libName} --no-watch`)).toContain(
'All specs passed!'
);
Expand All @@ -49,14 +49,14 @@ describe('NextJs Component Testing', () => {
it('should test a NextJs buildable lib', async () => {
const buildableLibName = uniq('next-buildable-lib');
createLibWithCt(buildableLibName, true);
if (runCypressTests()) {
if (runE2ETests()) {
expect(runCLI(`component-test ${buildableLibName} --no-watch`)).toContain(
'All specs passed!'
);
}

addTailwindToLib(buildableLibName);
if (runCypressTests()) {
if (runE2ETests()) {
expect(runCLI(`component-test ${buildableLibName} --no-watch`)).toContain(
'All specs passed!'
);
Expand Down
4 changes: 2 additions & 2 deletions e2e/next/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
readJson,
runCLI,
runCLIAsync,
runCypressTests,
runE2ETests,
} from '../../utils';

export async function checkApp(
Expand Down Expand Up @@ -40,7 +40,7 @@ export async function checkApp(
expect(packageJson.dependencies['react-dom']).toBeDefined();
expect(packageJson.dependencies.next).toBeDefined();

if (opts.checkE2E && runCypressTests()) {
if (opts.checkE2E && runE2ETests()) {
const e2eResults = runCLI(
`e2e ${appName}-e2e --no-watch --configuration=production`
);
Expand Down
1 change: 0 additions & 1 deletion e2e/react-core/src/react-module-federation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
readProjectConfig,
runCLI,
runCLIAsync,
runCypressTests,
uniq,
updateFile,
} from '@nx/e2e/utils';
Expand Down
4 changes: 2 additions & 2 deletions e2e/react-core/src/react.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
readFile,
runCLI,
runCLIAsync,
runCypressTests,
runE2ETests,
uniq,
updateFile,
updateJson,
Expand Down Expand Up @@ -363,7 +363,7 @@ async function testGeneratedApp(
'Test Suites: 1 passed, 1 total'
);

if (opts.checkE2E && runCypressTests()) {
if (opts.checkE2E && runE2ETests()) {
const e2eResults = runCLI(`e2e ${appName}-e2e --no-watch`);
expect(e2eResults).toContain('All specs passed!');
expect(await killPorts()).toBeTruthy();
Expand Down
14 changes: 7 additions & 7 deletions e2e/react-extensions/src/cypress-component-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ensureCypressInstallation,
newProject,
runCLI,
runCypressTests,
runE2ETests,
uniq,
updateFile,
updateJson,
Expand Down Expand Up @@ -147,7 +147,7 @@ export default Input;
runCLI(
`generate @nx/react:cypress-component-configuration --project=${appName} --generate-tests`
);
if (runCypressTests()) {
if (runE2ETests()) {
expect(runCLI(`component-test ${appName} --no-watch`)).toContain(
'All specs passed!'
);
Expand All @@ -158,7 +158,7 @@ export default Input;
runCLI(
`generate @nx/react:cypress-component-configuration --project=${usedInAppLibName} --generate-tests`
);
if (runCypressTests()) {
if (runE2ETests()) {
expect(runCLI(`component-test ${usedInAppLibName} --no-watch`)).toContain(
'All specs passed!'
);
Expand Down Expand Up @@ -190,7 +190,7 @@ describe(Input.name, () => {
`generate @nx/react:cypress-component-configuration --project=${buildableLibName} --generate-tests --build-target=${appName}:build`
);

if (runCypressTests()) {
if (runE2ETests()) {
expect(runCLI(`component-test ${buildableLibName} --no-watch`)).toContain(
'All specs passed!'
);
Expand Down Expand Up @@ -221,7 +221,7 @@ ${content}`;
}
);

if (runCypressTests()) {
if (runE2ETests()) {
expect(runCLI(`component-test ${buildableLibName} --no-watch`)).toContain(
'All specs passed!'
);
Expand Down Expand Up @@ -260,7 +260,7 @@ ${content}`;
return config;
});

if (runCypressTests()) {
if (runE2ETests()) {
const results = runCLI(`component-test ${appName}`);
expect(results).toContain('I am from the custom async Webpack config');
expect(results).toContain('All specs passed!');
Expand Down Expand Up @@ -291,7 +291,7 @@ export default MyComponent;`;
runCLI(
`generate @nrwl/react:cypress-component-configuration --project=${viteLibName} --generate-tests --bundler=vite --build-target=${appName}:build`
);
if (runCypressTests()) {
if (runE2ETests()) {
expect(runCLI(`component-test ${viteLibName}`)).toContain(
'All specs passed!'
);
Expand Down
17 changes: 13 additions & 4 deletions e2e/utils/command-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { packageInstall, tmpProjPath } from './create-project-utils';
import {
detectPackageManager,
ensureCypressInstallation,
ensurePlaywrightBrowsersInstallation,
getNpmMajorVersion,
getPublishedVersion,
getStrippedEnvironmentVariables,
Expand Down Expand Up @@ -175,15 +176,23 @@ export function getPackageManagerCommand({
}[packageManager.trim() as PackageManager];
}

export function runCypressTests() {
if (process.env.NX_E2E_RUN_CYPRESS === 'true') {
export function runE2ETests() {
if (process.env.NX_E2E_RUN_E2E === 'true') {
ensureCypressInstallation();
ensurePlaywrightBrowsersInstallation();
return true;
} else {
}

console.warn(
'Not running E2E tests because NX_E2E_RUN_E2E is not set to true.'
);

if (process.env.NX_E2E_RUN_CYPRESS) {
console.warn(
'Not running Cypress because NX_E2E_RUN_CYPRESS is not set to true.'
'NX_E2E_RUN_CYPRESS is deprecated, use NX_E2E_RUN_E2E instead.'
);
}

return false;
}

Expand Down
4 changes: 2 additions & 2 deletions e2e/web/src/web-vite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
removeFile,
runCLI,
runCLIAsync,
runCypressTests,
runE2ETests,
uniq,
} from '@nx/e2e/utils';

Expand All @@ -35,7 +35,7 @@ describe('Web Components Applications with bundler set as vite', () => {

expect(lintE2eResults).toContain('All files pass linting.');

if (isNotWindows() && runCypressTests()) {
if (isNotWindows() && runE2ETests()) {
const e2eResults = runCLI(`e2e ${appName}-e2e --no-watch`);
expect(e2eResults).toContain('All specs passed!');
expect(await killPorts()).toBeTruthy();
Expand Down
Loading