From 0e87b4477d3a443fba847194a9e555ce23907656 Mon Sep 17 00:00:00 2001 From: Svana Date: Thu, 21 Nov 2024 12:52:56 +0000 Subject: [PATCH] chore(tests): Support more options E2E Playwright config --- libs/testing/e2e/README.md | 16 ++++----- .../e2e/src/lib/config/playwright-config.ts | 35 ++++++++++++++----- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/libs/testing/e2e/README.md b/libs/testing/e2e/README.md index 40fedb39f715..2b25fca2891f 100644 --- a/libs/testing/e2e/README.md +++ b/libs/testing/e2e/README.md @@ -41,7 +41,7 @@ export default playwrightConfig Use the following command structure to run tests for any app: ```bash -yarn e2e +yarn nx e2e ``` ### Useful Playwright Commands and Flags @@ -49,26 +49,26 @@ yarn e2e - **Run with UI Mode**: Launch the tests with a UI to select and debug tests interactively. ```bash - yarn e2e --ui + yarn nx e2e --ui ``` - **Run Tests Without Caching**: Ensure a fresh run of tests without using cached results. ```bash - yarn e2e --skip-nx-cache + yarn nx e2e --skip-nx-cache ``` - **Run Tests with Tags**: Use tags to include or exclude specific tests. ```bash # Run only tests tagged with @fast - yarn e2e --grep @fast + yarn nx e2e --grep @fast # Exclude tests tagged with @fast - yarn e2e --grep-invert @fast + yarn nx e2e --grep-invert @fast # Run tests tagged with either @fast or @slow - yarn e2e --grep "@fast|@slow" + yarn nx e2e --grep "@fast|@slow" ``` - **View the Test Report**: After running tests, use this command to view the generated report: @@ -80,13 +80,13 @@ yarn e2e - **Run Specific Tests**: Use `--grep` to run tests matching a specific pattern: ```bash - yarn e2e --grep "Home Page Test" + yarn nx e2e --grep "Home Page Test" ``` - **Debug Mode**: Run tests in debug mode for better visibility: ```bash - yarn e2e --debug + yarn nx e2e --debug ``` For more details on Playwright commands and flags, refer to the [official documentation](https://playwright.dev/docs/test-cli) diff --git a/libs/testing/e2e/src/lib/config/playwright-config.ts b/libs/testing/e2e/src/lib/config/playwright-config.ts index d888387b0874..07f83d07d5df 100644 --- a/libs/testing/e2e/src/lib/config/playwright-config.ts +++ b/libs/testing/e2e/src/lib/config/playwright-config.ts @@ -3,7 +3,10 @@ import { defineConfig, ReporterDescription } from '@playwright/test' interface PlaywrightConfigParams { webServerUrl: string port?: number - command: string + command?: string + app?: string + dependencies?: string[] + proxies?: boolean cwd?: string timeoutMs?: number } @@ -18,6 +21,9 @@ interface PlaywrightConfigParams { * @param {string} config.command - Command to start the web server. * @param {string} config.cwd - Working directory for the web server command. * @param {number} config.timeoutMs - Timeout in milliseconds for server startup. + * @param {string} config.app - Application to run. + * @param {string} config.dependencies - Space-separated list of dependencies. + * @param {boolean} config.proxies - Whether to use proxies. * * @returns A configuration object for Playwright E2E tests. */ @@ -27,8 +33,24 @@ export const createPlaywrightConfig = ({ command, cwd, timeoutMs = 5 * 60 * 1000, -}: PlaywrightConfigParams) => - defineConfig({ + app, + dependencies = [], + proxies = false, +}: PlaywrightConfigParams) => { + if (!command) { + if (!app) { + throw new Error('Either command or app must be specified.') + } + command = `yarn infra run-local-env ${app} --print --no-secrets` + if (dependencies.length > 0) { + command += ` --dependencies ${dependencies}` + } + if (proxies) { + command += ' --proxies' + } + } + + return defineConfig({ testDir: 'e2e', fullyParallel: true, forbidOnly: !!process.env.CI, @@ -40,16 +62,10 @@ export const createPlaywrightConfig = ({ : [['dot']]) as ReporterDescription[]), ['html', { open: 'never' }], ], - use: { baseURL: webServerUrl, trace: 'on-first-retry', }, - projects: [ - { name: 'everything', testMatch: 'e2e/**/*.spec.[tj]s' }, - { name: 'smoke', testMatch: 'e2e/smoke/**/*.spec.[tj]s' }, - { name: 'acceptance', testMatch: 'e2e/acceptance/**/*.spec.[tj]s' }, - ], webServer: { stdout: 'pipe', port: port ? port : undefined, @@ -60,3 +76,4 @@ export const createPlaywrightConfig = ({ cwd, }, }) +}