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..f70cff4535eb 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 - List of dependencies. + * @param {boolean} config.proxies - Whether to use proxies. * * @returns A configuration object for Playwright E2E tests. */ @@ -27,8 +33,25 @@ export const createPlaywrightConfig = ({ command, cwd, timeoutMs = 5 * 60 * 1000, -}: PlaywrightConfigParams) => - defineConfig({ + app, + dependencies = [], + proxies = false, +}: PlaywrightConfigParams) => { + if (!command && !app) { + throw new Error('Either command or app must be specified.') + } + + if (!command) { + command = `yarn infra run-local-env ${app} --print --no-secrets` + if (dependencies.length > 0) { + command += ` --dependencies ${dependencies.join(' ')}` + } + if (proxies) { + command += ' --proxies' + } + } + + return defineConfig({ testDir: 'e2e', fullyParallel: true, forbidOnly: !!process.env.CI, @@ -40,16 +63,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 +77,4 @@ export const createPlaywrightConfig = ({ cwd, }, }) +}