Skip to content

Commit 39af09c

Browse files
committed
docs: Add Developer Workflow to Testing Guides (#8881)
1 parent 92f8427 commit 39af09c

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

learn/guides/testing/ComponentTesting.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,29 @@ npm run test-components
2727

2828
**Note:** Component tests run sequentially (single worker) to prevent state pollution in the shared `empty-viewport` app.
2929

30+
## Developer Workflow
31+
32+
### 1. Running a Single File
33+
To run a specific component test file, point to the component config:
34+
35+
```bash
36+
npx playwright test test/playwright/component/my/file.spec.mjs -c test/playwright/playwright.config.component.mjs
37+
```
38+
39+
### 2. Visual Debugging
40+
Component tests are visual by nature. Use `--headed` to watch the browser execution:
41+
42+
```bash
43+
# Run with a visible browser window
44+
npx playwright test test/playwright/component/my/file.spec.mjs -c test/playwright/playwright.config.component.mjs --headed
45+
46+
# Run with the Inspector to step through
47+
npx playwright test test/playwright/component/my/file.spec.mjs -c test/playwright/playwright.config.component.mjs --debug
48+
```
49+
50+
### 3. Verify Isolation
51+
Since component tests share the same `apps/empty-viewport`, ensure you run the full suite (`npm run test-components`) before committing to verify that your tests clean up after themselves (using `neo.destroyComponent`) and don't leave artifacts that break subsequent tests.
52+
3053
## Writing a Component Test
3154

3255
The recommended way to write component tests is using the custom `neo` fixture provided by `test/playwright/fixtures.mjs`.

learn/guides/testing/UnitTesting.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,37 @@ To run the logic-heavy unit tests in the simulated Node.js environment:
1616
npm run test-unit
1717
```
1818

19+
## Developer Workflow (Best Practices)
20+
21+
### 1. Running a Single File (Focus Mode)
22+
During development, you don't want to wait for the entire suite. You can run a specific test file using `npx playwright`.
23+
24+
**Critical:** You **MUST** specify the unit test config (`-c test/playwright/playwright.config.unit.mjs`). If you don't, Playwright will default to the generic config and fail to load the environment correctly.
25+
26+
```bash
27+
# Correct way to run a single unit test file
28+
npx playwright test test/playwright/unit/my/file.spec.mjs -c test/playwright/playwright.config.unit.mjs
29+
```
30+
31+
### 2. Debugging
32+
To step through your tests visually or pause execution:
33+
```bash
34+
# Opens the Playwright Inspector
35+
npx playwright test test/playwright/unit/my/file.spec.mjs -c test/playwright/playwright.config.unit.mjs --debug
36+
```
37+
38+
To filter tests by name (e.g., only run tests with "sort" in the title):
39+
```bash
40+
npx playwright test -c test/playwright/playwright.config.unit.mjs -g "sort"
41+
```
42+
43+
### 3. The "Safety Net" (Cross-Test Side Effects)
44+
**Warning:** Playwright distributes test files across multiple **Node.js worker processes** to run them in parallel. However, within a *single* Playwright worker process, the environment (and the global `Neo` namespace) persists across multiple test files.
45+
46+
* **The Risk:** We do *not* clean up the `Neo` namespace between tests (doing so would be slow). If Test File A defines a class `Test.MockComponent` and Test File B tries to define the same class with different behavior, `Neo.setupClass` will throw a "Namespace Collision" error.
47+
* **The Strategy:** Ensure every test class has a **unique namespace**, ideally scoped to the test file (e.g., `Test.Unit.MyFeature.MockComponent`).
48+
* **The Rule:** Even if your specific test file passes, you **MUST** run the full suite (`npm run test-unit`) before committing. This verifies that your new namespaces don't accidentally collide with existing ones when Playwright groups them together.
49+
1950
## Unit Testing Architecture
2051

2152
The unit tests located in `test/playwright/unit/` are the backbone of our testing strategy. They run in a **Node.js environment**, effectively simulating the Neo.mjs App Worker (and parts of the VDom/Data workers) within a single thread.

0 commit comments

Comments
 (0)