feat(testing): update generated Playwright test and config (#18282)

This commit is contained in:
Jack Hsu 2023-07-24 15:13:34 -04:00 committed by GitHub
parent 7567a65975
commit 14b3f42900
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 28 deletions

View File

@ -22,7 +22,6 @@ describe('Playwright E2E Test runner', () => {
ensurePlaywrightBrowsersInstallation();
const e2eResults = runCLI(`e2e demo-e2e`);
expect(e2eResults).toContain('6 passed');
expect(e2eResults).toContain('Successfully ran target e2e for project');
const lintResults = runCLI(`lint demo-e2e`);
@ -41,7 +40,6 @@ describe('Playwright E2E Test runner', () => {
ensurePlaywrightBrowsersInstallation();
const e2eResults = runCLI(`e2e demo-js-e2e`);
expect(e2eResults).toContain('6 passed');
expect(e2eResults).toContain('Successfully ran target e2e for project');
const lintResults = runCLI(`lint demo-e2e`);

View File

@ -1,18 +1,8 @@
import { test, expect } from '@playwright/test';
test('has title', async ({ page }) => {
await page.goto('https://playwright.dev/');
await page.goto('/');
// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Playwright/);
});
test('get started link', async ({ page }) => {
await page.goto('https://playwright.dev/');
// Click the get started link.
await page.getByRole('link', { name: 'Get started' }).click();
// Expects the URL to contain intro.
await expect(page).toHaveURL(/.*intro/);
await expect(page).toHaveTitle(/Welcome/);
});

View File

@ -3,6 +3,9 @@ import { nxE2EPreset } from '@nx/playwright/preset';
<% if(!webServerCommand || !webServerAddress) { %>// eslint-disable-next-line @typescript-eslint/no-unused-vars <% } %>
import { workspaceRoot } from '@nx/devkit';
// For CI, you may want to set BASE_URL to the deployed application.
const baseURL = process.env['BASE_URL'] || '<% if(webServerAddress) {%><%= webServerAddress %><% } else {%>http://localhost:3000<% } %>';
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
@ -13,17 +16,23 @@ import { workspaceRoot } from '@nx/devkit';
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
...nxE2EPreset(__filename, { testDir: './<%= directory %>' }),
/* Run your local dev server before starting the tests */<% if(webServerCommand && webServerAddress) {%>
webServer: {
command: '<%= webServerCommand %>',
url: '<%= webServerAddress %>',
reuseExistingServer: !process.env.CI,
cwd: workspaceRoot
},<% } else {%>// webServer: {
...nxE2EPreset(__filename, { testDir: './<>' }),
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
baseURL,
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},
/* Run your local dev server before starting the tests */<% if(webServerCommand && webServerAddress) {%>
webServer: {
command: '<%= webServerCommand %>',
url: '<%= webServerAddress %>',
reuseExistingServer: !process.env.CI,
cwd: workspaceRoot
},<% } else {%>// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// cwd: workspaceRoot
// cwd: workspaceRoot,
// },<% } %>
});

View File

@ -133,11 +133,6 @@ export function nxE2EPreset(
},
],
],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},
projects,
});
}