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

chore(tests): Support more options E2E Playwright config #16982

Merged
merged 4 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 8 additions & 8 deletions libs/testing/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,34 @@ export default playwrightConfig
Use the following command structure to run tests for any app:

```bash
yarn e2e <app-name>
yarn nx e2e <app-name>
```

### Useful Playwright Commands and Flags

- **Run with UI Mode**: Launch the tests with a UI to select and debug tests interactively.

```bash
yarn e2e <app-name> --ui
yarn nx e2e <app-name> --ui
```

- **Run Tests Without Caching**: Ensure a fresh run of tests without using cached results.

```bash
yarn e2e <app-name> --skip-nx-cache
yarn nx e2e <app-name> --skip-nx-cache
```

- **Run Tests with Tags**: Use tags to include or exclude specific tests.

```bash
# Run only tests tagged with @fast
yarn e2e <app-name> --grep @fast
yarn nx e2e <app-name> --grep @fast

# Exclude tests tagged with @fast
yarn e2e <app-name> --grep-invert @fast
yarn nx e2e <app-name> --grep-invert @fast

# Run tests tagged with either @fast or @slow
yarn e2e <app-name> --grep "@fast|@slow"
yarn nx e2e <app-name> --grep "@fast|@slow"
```

- **View the Test Report**: After running tests, use this command to view the generated report:
Expand All @@ -80,13 +80,13 @@ yarn e2e <app-name>
- **Run Specific Tests**: Use `--grep` to run tests matching a specific pattern:

```bash
yarn e2e <app-name> --grep "Home Page Test"
yarn nx e2e <app-name> --grep "Home Page Test"
```

- **Debug Mode**: Run tests in debug mode for better visibility:

```bash
yarn e2e <app-name> --debug
yarn nx e2e <app-name> --debug
```

For more details on Playwright commands and flags, refer to the [official documentation](https://playwright.dev/docs/test-cli)
Expand Down
35 changes: 26 additions & 9 deletions libs/testing/e2e/src/lib/config/playwright-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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.
*/
Expand All @@ -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'
}
svanaeinars marked this conversation as resolved.
Show resolved Hide resolved
}
svanaeinars marked this conversation as resolved.
Show resolved Hide resolved

return defineConfig({
testDir: 'e2e',
fullyParallel: true,
forbidOnly: !!process.env.CI,
Expand All @@ -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,
Expand All @@ -60,3 +76,4 @@ export const createPlaywrightConfig = ({
cwd,
},
})
}