-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
65 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,62 @@ | ||
## NX Currents example | ||
This repository shows how to use NX with Currents | ||
|
||
## How to test it? | ||
It is ready to use. You only need to: | ||
- Install dependencies: `npm install` | ||
- Execute in the root of the project: `CURRENTS_RECORD_KEY=your-key CURRENTS_PROJECT_ID=your-id CURRENTS_CI_BUILD_ID=unique-id npx nx run-many -t e2e --verbose --parallel=2` | ||
|
||
## Explanation | ||
This NX workspace contains 2 projects within `apps` folder: `example-app` and `example-app-e2e`. | ||
These two projects has as target `e2e` to that will be the target to run when using `-t e2e` in the previous command. | ||
The `--parallel=2` will execute each project in different machines parallelizing the execution by project. | ||
|
||
## Considerations | ||
- The `pwc-p` is being used as executed command in `project.json` files | ||
- When using `CURRENTS_CI_BUILD_ID` env variable is will generate a single run for all your parallelized project | ||
- IMPORTANT: It is not advisable to use the same Playwright project names across NX projects because it can cause a mismatch in the reported results | ||
- [See this job](https://github.com/miguelangaranocurrents/nx-example/actions/runs/11958598465) to understand how parallelized orchestration works with NX | ||
# Currents Playwright NX Example | ||
|
||
This repository shows how to use NX + Playwright with Currents. | ||
|
||
## Setup | ||
|
||
```sh | ||
npm i -g nx@latest | ||
npm i | ||
``` | ||
|
||
## Run | ||
|
||
```sh | ||
CURRENTS_RECORD_KEY=recordkey \ | ||
CURRENTS_PROJECT_ID=projectid \ | ||
CURRENTS_CI_BUILD_ID=`date +%s` \ | ||
nx run-many -t e2e --parallel=2 --verbose | ||
``` | ||
|
||
### Output directory | ||
|
||
Playwright output directory is set in `project.json` > `targets.e2e.options.output`, for example: | ||
|
||
```json | ||
"targets": { | ||
"e2e": { | ||
"executor": "@nx/playwright:playwright", | ||
"options": { | ||
"skipInstall": true, | ||
"output": "{workspaceRoot}/playwright-report/{projectName}", | ||
"config": "{projectRoot}/playwright.config.ts" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
After running the tests, results will appear as: | ||
|
||
```plain | ||
playwright-report/ | ||
├── e2e-01/ | ||
│ └── .last-run.json | ||
└── e2e-02/ | ||
└── .last-run.json | ||
``` | ||
|
||
ℹ️ `playwright.config.ts` for each project use `nxE2EPreset` - it sets a different `output` directory, but `project.json:output` overrides it. | ||
|
||
## Last Failed | ||
|
||
nx passes down unrecognized arguments to the target command, for example | ||
|
||
```sh | ||
nx run-many -t e2e --parallel=2 --verbose --last-failed | ||
# ... | ||
|
||
NX Ran target e2e for 2 projects (7s) | ||
|
||
With additional flags: | ||
--last-failed=true | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,5 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
test('e2e-02', async ({ page }) => { | ||
await page.goto('https://todomvc.com/examples/backbone/dist/'); | ||
|
||
// Use locators to represent a selector and re-use them | ||
const inputBox = page.locator('input.new-todo'); | ||
const todoList = page.locator('.todo-list'); | ||
|
||
await inputBox.fill('Learn Playwright'); | ||
await inputBox.press('Enter'); | ||
await expect(todoList).toHaveText('Learn Playwright'); | ||
test('e2e-02', async () => { | ||
expect(1).toBe(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters