You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: learn/guides/testing/ComponentTesting.md
+23Lines changed: 23 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,29 @@ npm run test-components
27
27
28
28
**Note:** Component tests run sequentially (single worker) to prevent state pollution in the shared `empty-viewport` app.
29
29
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
+
30
53
## Writing a Component Test
31
54
32
55
The recommended way to write component tests is using the custom `neo` fixture provided by `test/playwright/fixtures.mjs`.
Copy file name to clipboardExpand all lines: learn/guides/testing/UnitTesting.md
+31Lines changed: 31 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,37 @@ To run the logic-heavy unit tests in the simulated Node.js environment:
16
16
npm run test-unit
17
17
```
18
18
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
+
19
50
## Unit Testing Architecture
20
51
21
52
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