@swedevtools/livedoc-vitest 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/LICENSE +20 -20
- package/README.md +160 -95
- package/dist/{RuleContext-BZhuy-zS.d.cts → RuleContext-DQ8o_n1D.d.ts} +62 -62
- package/dist/globals.d.ts +99 -99
- package/dist/{index-Blmp569T.d.cts → index-sbV15ohX.d.ts} +21 -2
- package/dist/index.d.ts +7 -5
- package/dist/index.js +1062 -159
- package/dist/reporter/index.d.ts +2 -2
- package/dist/reporter/index.js +629 -84
- package/package.json +14 -12
- package/tools/livedoc-setup.mjs +172 -164
- package/tools/skills/SKILL.md +339 -244
- package/tools/skills/VALIDATION.md +37 -29
- package/tools/skills/examples/routing.md +75 -60
- package/tools/skills/resources/anti-patterns.md +19 -0
- package/tools/skills/resources/bdd-features.md +231 -231
- package/tools/skills/resources/partial-testing.md +77 -0
- package/tools/skills/resources/playwright.md +148 -148
- package/tools/skills/resources/reporter-config.md +213 -163
- package/tools/skills/resources/specifications.md +159 -159
- package/tools/skills/resources/test-strategy.md +103 -0
- package/tools/skills/resources/web-testing.md +62 -0
- package/dist/RuleContext-BZhuy-zS.d.ts +0 -206
- package/dist/globals.cjs +0 -2
- package/dist/globals.d.cts +0 -104
- package/dist/index-CysiWbtk.d.ts +0 -687
- package/dist/index.cjs +0 -10024
- package/dist/index.d.cts +0 -291
- package/dist/playwright/index.cjs +0 -103
- package/dist/playwright/index.d.cts +0 -129
- package/dist/reporter/index.cjs +0 -8676
- package/dist/reporter/index.d.cts +0 -7
- package/dist/setup.cjs +0 -14
- package/dist/setup.d.cts +0 -2
|
@@ -1,148 +1,148 @@
|
|
|
1
|
-
# Playwright Integration — Full Reference
|
|
2
|
-
|
|
3
|
-
Browser-based testing with `@swedevtools/livedoc-vitest/playwright`.
|
|
4
|
-
|
|
5
|
-
## Prerequisites
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install -D playwright # or: pnpm add -D playwright
|
|
9
|
-
npx playwright install chromium # install browser binary
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
## Import
|
|
13
|
-
|
|
14
|
-
```typescript
|
|
15
|
-
import { useBrowser, screenshot } from "@swedevtools/livedoc-vitest/playwright";
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## useBrowser(options?)
|
|
19
|
-
|
|
20
|
-
Manages browser lifecycle for the current feature file. **Call at module scope** (outside any scenario). Launches the browser in `beforeAll`, closes in `afterAll`.
|
|
21
|
-
|
|
22
|
-
```typescript
|
|
23
|
-
import { feature, scenario, given, when, Then as then } from "@swedevtools/livedoc-vitest";
|
|
24
|
-
import { useBrowser, screenshot } from "@swedevtools/livedoc-vitest/playwright";
|
|
25
|
-
|
|
26
|
-
const { page, context, browser } = useBrowser();
|
|
27
|
-
|
|
28
|
-
feature("Viewer Navigation", () => {
|
|
29
|
-
scenario("Loading the homepage", () => {
|
|
30
|
-
when("navigating to the homepage", async (ctx) => {
|
|
31
|
-
await page().goto("http://localhost:3000");
|
|
32
|
-
await screenshot(page(), ctx);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
then("the page title should be visible", async () => {
|
|
36
|
-
const title = await page().locator("h1").textContent();
|
|
37
|
-
expect(title).toBeTruthy();
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### Options
|
|
44
|
-
|
|
45
|
-
| Option | Type | Default | Description |
|
|
46
|
-
| --- | --- | --- | --- |
|
|
47
|
-
| `browser` | `'chromium' \| 'firefox' \| 'webkit'` | `'chromium'` | Browser engine |
|
|
48
|
-
| `headless` | `boolean` | `true` | Run headless (set `false` for debugging) |
|
|
49
|
-
| `viewport` | `{width, height}` | `1280×720` | Browser viewport size |
|
|
50
|
-
| `freshContextPerScenario` | `boolean` | `false` | Create a fresh browser context for each scenario |
|
|
51
|
-
|
|
52
|
-
### Return Value
|
|
53
|
-
|
|
54
|
-
`useBrowser()` returns **getter functions**, not direct references:
|
|
55
|
-
|
|
56
|
-
- `page()` — returns the current Playwright Page
|
|
57
|
-
- `context()` — returns the current BrowserContext
|
|
58
|
-
- `browser()` — returns the Browser instance
|
|
59
|
-
|
|
60
|
-
```typescript
|
|
61
|
-
const { page } = useBrowser({ headless: false });
|
|
62
|
-
|
|
63
|
-
// ✅ CORRECT: Call page() inside a step
|
|
64
|
-
when("clicking the button", async () => {
|
|
65
|
-
await page().click("button#submit");
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// ❌ WRONG: page() at module scope — browser not launched yet
|
|
69
|
-
const p = page(); // Will throw or return undefined
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### Headed Mode (Debugging)
|
|
73
|
-
|
|
74
|
-
```typescript
|
|
75
|
-
const { page } = useBrowser({ headless: false });
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
The browser window stays visible for debugging. Combine with `scenario.only()` to focus on a single test.
|
|
79
|
-
|
|
80
|
-
## screenshot(page, ctx, options?)
|
|
81
|
-
|
|
82
|
-
Captures a screenshot and attaches it to the current step.
|
|
83
|
-
|
|
84
|
-
```typescript
|
|
85
|
-
when("viewing the dashboard", async (ctx) => {
|
|
86
|
-
await screenshot(page(), ctx);
|
|
87
|
-
// Auto-named: "viewing-the-dashboard-0.png"
|
|
88
|
-
});
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
### Parameters
|
|
92
|
-
|
|
93
|
-
- `page` — Playwright Page instance (use `page()` getter)
|
|
94
|
-
- `ctx` — Step context from the step callback
|
|
95
|
-
- `options.name` — Custom screenshot name (optional; auto-generated from step title if omitted)
|
|
96
|
-
- `options.fullPage` — Capture full page vs viewport only (optional)
|
|
97
|
-
|
|
98
|
-
### Custom Named Screenshots
|
|
99
|
-
|
|
100
|
-
```typescript
|
|
101
|
-
when("viewing the dashboard", async (ctx) => {
|
|
102
|
-
await screenshot(page(), ctx, { name: "dashboard-initial-load" });
|
|
103
|
-
// ... interact with page ...
|
|
104
|
-
await screenshot(page(), ctx, { name: "dashboard-after-filter" });
|
|
105
|
-
});
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
## Global Setup for Dev Server
|
|
109
|
-
|
|
110
|
-
When testing against a local dev server, use Vitest's `globalSetup` to start it:
|
|
111
|
-
|
|
112
|
-
```typescript
|
|
113
|
-
// vitest.config.ts
|
|
114
|
-
export default defineConfig({
|
|
115
|
-
test: {
|
|
116
|
-
globalSetup: './global-setup.ts',
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// global-setup.ts
|
|
121
|
-
export async function setup() {
|
|
122
|
-
// Start your dev server, wait for it to be ready
|
|
123
|
-
}
|
|
124
|
-
export async function teardown() {
|
|
125
|
-
// Stop the server
|
|
126
|
-
}
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
## CI Configuration
|
|
130
|
-
|
|
131
|
-
```yaml
|
|
132
|
-
# .github/workflows/test.yml
|
|
133
|
-
- name: Install Playwright
|
|
134
|
-
run: npx playwright install --with-deps chromium
|
|
135
|
-
- name: Run tests
|
|
136
|
-
run: npx vitest run
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
## Troubleshooting
|
|
140
|
-
|
|
141
|
-
| Problem | Cause | Solution |
|
|
142
|
-
| --- | --- | --- |
|
|
143
|
-
| `Cannot find module 'playwright'` | Not installed | `npm install -D playwright` |
|
|
144
|
-
| `Browser not found` | Binaries not installed | `npx playwright install chromium` |
|
|
145
|
-
| `page() returns undefined` | Called at module scope | Call `page()` inside step callbacks only |
|
|
146
|
-
| `useBrowser is not a function` | Wrong import path | Use `@swedevtools/livedoc-vitest/playwright` |
|
|
147
|
-
| Tests timeout | Slow network/server | Increase vitest timeout, ensure server is running |
|
|
148
|
-
| Screenshots are blank | Page not loaded | Add `await page().waitForLoadState()` before screenshot |
|
|
1
|
+
# Playwright Integration — Full Reference
|
|
2
|
+
|
|
3
|
+
Browser-based testing with `@swedevtools/livedoc-vitest/playwright`.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -D playwright # or: pnpm add -D playwright
|
|
9
|
+
npx playwright install chromium # install browser binary
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Import
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import { useBrowser, screenshot } from "@swedevtools/livedoc-vitest/playwright";
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## useBrowser(options?)
|
|
19
|
+
|
|
20
|
+
Manages browser lifecycle for the current feature file. **Call at module scope** (outside any scenario). Launches the browser in `beforeAll`, closes in `afterAll`.
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { feature, scenario, given, when, Then as then } from "@swedevtools/livedoc-vitest";
|
|
24
|
+
import { useBrowser, screenshot } from "@swedevtools/livedoc-vitest/playwright";
|
|
25
|
+
|
|
26
|
+
const { page, context, browser } = useBrowser();
|
|
27
|
+
|
|
28
|
+
feature("Viewer Navigation", () => {
|
|
29
|
+
scenario("Loading the homepage", () => {
|
|
30
|
+
when("navigating to the homepage", async (ctx) => {
|
|
31
|
+
await page().goto("http://localhost:3000");
|
|
32
|
+
await screenshot(page(), ctx);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
then("the page title should be visible", async () => {
|
|
36
|
+
const title = await page().locator("h1").textContent();
|
|
37
|
+
expect(title).toBeTruthy();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Options
|
|
44
|
+
|
|
45
|
+
| Option | Type | Default | Description |
|
|
46
|
+
| --- | --- | --- | --- |
|
|
47
|
+
| `browser` | `'chromium' \| 'firefox' \| 'webkit'` | `'chromium'` | Browser engine |
|
|
48
|
+
| `headless` | `boolean` | `true` | Run headless (set `false` for debugging) |
|
|
49
|
+
| `viewport` | `{width, height}` | `1280×720` | Browser viewport size |
|
|
50
|
+
| `freshContextPerScenario` | `boolean` | `false` | Create a fresh browser context for each scenario |
|
|
51
|
+
|
|
52
|
+
### Return Value
|
|
53
|
+
|
|
54
|
+
`useBrowser()` returns **getter functions**, not direct references:
|
|
55
|
+
|
|
56
|
+
- `page()` — returns the current Playwright Page
|
|
57
|
+
- `context()` — returns the current BrowserContext
|
|
58
|
+
- `browser()` — returns the Browser instance
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
const { page } = useBrowser({ headless: false });
|
|
62
|
+
|
|
63
|
+
// ✅ CORRECT: Call page() inside a step
|
|
64
|
+
when("clicking the button", async () => {
|
|
65
|
+
await page().click("button#submit");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// ❌ WRONG: page() at module scope — browser not launched yet
|
|
69
|
+
const p = page(); // Will throw or return undefined
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Headed Mode (Debugging)
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
const { page } = useBrowser({ headless: false });
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The browser window stays visible for debugging. Combine with `scenario.only()` to focus on a single test.
|
|
79
|
+
|
|
80
|
+
## screenshot(page, ctx, options?)
|
|
81
|
+
|
|
82
|
+
Captures a screenshot and attaches it to the current step.
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
when("viewing the dashboard", async (ctx) => {
|
|
86
|
+
await screenshot(page(), ctx);
|
|
87
|
+
// Auto-named: "viewing-the-dashboard-0.png"
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Parameters
|
|
92
|
+
|
|
93
|
+
- `page` — Playwright Page instance (use `page()` getter)
|
|
94
|
+
- `ctx` — Step context from the step callback
|
|
95
|
+
- `options.name` — Custom screenshot name (optional; auto-generated from step title if omitted)
|
|
96
|
+
- `options.fullPage` — Capture full page vs viewport only (optional)
|
|
97
|
+
|
|
98
|
+
### Custom Named Screenshots
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
when("viewing the dashboard", async (ctx) => {
|
|
102
|
+
await screenshot(page(), ctx, { name: "dashboard-initial-load" });
|
|
103
|
+
// ... interact with page ...
|
|
104
|
+
await screenshot(page(), ctx, { name: "dashboard-after-filter" });
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Global Setup for Dev Server
|
|
109
|
+
|
|
110
|
+
When testing against a local dev server, use Vitest's `globalSetup` to start it:
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
// vitest.config.ts
|
|
114
|
+
export default defineConfig({
|
|
115
|
+
test: {
|
|
116
|
+
globalSetup: './global-setup.ts',
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// global-setup.ts
|
|
121
|
+
export async function setup() {
|
|
122
|
+
// Start your dev server, wait for it to be ready
|
|
123
|
+
}
|
|
124
|
+
export async function teardown() {
|
|
125
|
+
// Stop the server
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## CI Configuration
|
|
130
|
+
|
|
131
|
+
```yaml
|
|
132
|
+
# .github/workflows/test.yml
|
|
133
|
+
- name: Install Playwright
|
|
134
|
+
run: npx playwright install --with-deps chromium
|
|
135
|
+
- name: Run tests
|
|
136
|
+
run: npx vitest run
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Troubleshooting
|
|
140
|
+
|
|
141
|
+
| Problem | Cause | Solution |
|
|
142
|
+
| --- | --- | --- |
|
|
143
|
+
| `Cannot find module 'playwright'` | Not installed | `npm install -D playwright` |
|
|
144
|
+
| `Browser not found` | Binaries not installed | `npx playwright install chromium` |
|
|
145
|
+
| `page() returns undefined` | Called at module scope | Call `page()` inside step callbacks only |
|
|
146
|
+
| `useBrowser is not a function` | Wrong import path | Use `@swedevtools/livedoc-vitest/playwright` |
|
|
147
|
+
| Tests timeout | Slow network/server | Increase vitest timeout, ensure server is running |
|
|
148
|
+
| Screenshots are blank | Page not loaded | Add `await page().waitForLoadState()` before screenshot |
|
|
@@ -1,163 +1,213 @@
|
|
|
1
|
-
# Reporter Configuration — Full Reference
|
|
2
|
-
|
|
3
|
-
Configure LiveDoc reporters for console output, real-time viewer streaming, JSON export, and static HTML reports.
|
|
4
|
-
|
|
5
|
-
## Available Reporters
|
|
6
|
-
|
|
7
|
-
| Reporter | Purpose | Import |
|
|
8
|
-
| --- | --- | --- |
|
|
9
|
-
| `LiveDocSpecReporter` | Console output + auto-discover viewer | `@swedevtools/livedoc-vitest/reporter` |
|
|
10
|
-
| `LiveDocViewerReporter` | Stream to viewer only (no console) | `@swedevtools/livedoc-vitest/reporter` |
|
|
11
|
-
| `JsonReporter` | Write JSON file for static export | `@swedevtools/livedoc-vitest/reporter` |
|
|
12
|
-
| `SilentReporter` | Suppress all output | `@swedevtools/livedoc-vitest/reporter` |
|
|
13
|
-
|
|
14
|
-
## LiveDocSpecReporter
|
|
15
|
-
|
|
16
|
-
The primary reporter. Produces structured Gherkin-style console output and auto-discovers a running LiveDoc Viewer server.
|
|
17
|
-
|
|
18
|
-
### Simplest Config
|
|
19
|
-
|
|
20
|
-
```typescript
|
|
21
|
-
import { defineConfig } from "vitest/config";
|
|
22
|
-
|
|
23
|
-
export default defineConfig({
|
|
24
|
-
test: {
|
|
25
|
-
reporters: [
|
|
26
|
-
["@swedevtools/livedoc-vitest/reporter", { detailLevel: "spec+summary+headers" }],
|
|
27
|
-
],
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
### Detail Levels
|
|
33
|
-
|
|
34
|
-
Combinable with `+`:
|
|
35
|
-
|
|
36
|
-
| Level | Output |
|
|
37
|
-
| --- | --- |
|
|
38
|
-
| `spec` | Full step-by-step output |
|
|
39
|
-
| `summary` | Pass/fail/skip counts |
|
|
40
|
-
| `headers` | Feature and scenario titles |
|
|
41
|
-
| `list` | One-line-per-test list |
|
|
42
|
-
| `silent` | No output |
|
|
43
|
-
|
|
44
|
-
Examples: `"spec+summary+headers"`, `"list+headers"`, `"summary"`
|
|
45
|
-
|
|
46
|
-
### Explicit Publish Config
|
|
47
|
-
|
|
48
|
-
```typescript
|
|
49
|
-
import { LiveDocSpecReporter } from "@swedevtools/livedoc-vitest/reporter";
|
|
50
|
-
|
|
51
|
-
export default defineConfig({
|
|
52
|
-
test: {
|
|
53
|
-
reporters: [
|
|
54
|
-
new LiveDocSpecReporter({
|
|
55
|
-
detailLevel: "spec+summary+headers",
|
|
56
|
-
publish: {
|
|
57
|
-
enabled: true,
|
|
58
|
-
server: "http://localhost:
|
|
59
|
-
project: "my-project",
|
|
60
|
-
environment: "local",
|
|
61
|
-
},
|
|
62
|
-
}),
|
|
63
|
-
],
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
### Auto-Discovery Priority
|
|
69
|
-
|
|
70
|
-
The reporter automatically finds the viewer server:
|
|
71
|
-
|
|
72
|
-
1. **Environment variables**: `LIVEDOC_SERVER_URL` or `LIVEDOC_PUBLISH_SERVER`
|
|
73
|
-
2. **Explicit config**: `publish.server` in reporter options
|
|
74
|
-
3. **Discovery**: `discoverServer()` fallback from `@swedevtools/livedoc-server`
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
1
|
+
# Reporter Configuration — Full Reference
|
|
2
|
+
|
|
3
|
+
Configure LiveDoc reporters for console output, real-time viewer streaming, JSON export, and static HTML reports.
|
|
4
|
+
|
|
5
|
+
## Available Reporters
|
|
6
|
+
|
|
7
|
+
| Reporter | Purpose | Import |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `LiveDocSpecReporter` | Console output + auto-discover viewer | `@swedevtools/livedoc-vitest/reporter` |
|
|
10
|
+
| `LiveDocViewerReporter` | Stream to viewer only (no console) | `@swedevtools/livedoc-vitest/reporter` |
|
|
11
|
+
| `JsonReporter` | Write JSON file for static export | `@swedevtools/livedoc-vitest/reporter` |
|
|
12
|
+
| `SilentReporter` | Suppress all output | `@swedevtools/livedoc-vitest/reporter` |
|
|
13
|
+
|
|
14
|
+
## LiveDocSpecReporter
|
|
15
|
+
|
|
16
|
+
The primary reporter. Produces structured Gherkin-style console output and auto-discovers a running LiveDoc Viewer server.
|
|
17
|
+
|
|
18
|
+
### Simplest Config
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { defineConfig } from "vitest/config";
|
|
22
|
+
|
|
23
|
+
export default defineConfig({
|
|
24
|
+
test: {
|
|
25
|
+
reporters: [
|
|
26
|
+
["@swedevtools/livedoc-vitest/reporter", { detailLevel: "spec+summary+headers" }],
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Detail Levels
|
|
33
|
+
|
|
34
|
+
Combinable with `+`:
|
|
35
|
+
|
|
36
|
+
| Level | Output |
|
|
37
|
+
| --- | --- |
|
|
38
|
+
| `spec` | Full step-by-step output |
|
|
39
|
+
| `summary` | Pass/fail/skip counts |
|
|
40
|
+
| `headers` | Feature and scenario titles |
|
|
41
|
+
| `list` | One-line-per-test list |
|
|
42
|
+
| `silent` | No output |
|
|
43
|
+
|
|
44
|
+
Examples: `"spec+summary+headers"`, `"list+headers"`, `"summary"`
|
|
45
|
+
|
|
46
|
+
### Explicit Publish Config
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { LiveDocSpecReporter } from "@swedevtools/livedoc-vitest/reporter";
|
|
50
|
+
|
|
51
|
+
export default defineConfig({
|
|
52
|
+
test: {
|
|
53
|
+
reporters: [
|
|
54
|
+
new LiveDocSpecReporter({
|
|
55
|
+
detailLevel: "spec+summary+headers",
|
|
56
|
+
publish: {
|
|
57
|
+
enabled: true,
|
|
58
|
+
server: "http://localhost:3100",
|
|
59
|
+
project: "my-project",
|
|
60
|
+
environment: "local",
|
|
61
|
+
},
|
|
62
|
+
}),
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Auto-Discovery Priority
|
|
69
|
+
|
|
70
|
+
The reporter automatically finds the viewer server:
|
|
71
|
+
|
|
72
|
+
1. **Environment variables**: `LIVEDOC_SERVER_URL` or `LIVEDOC_PUBLISH_SERVER`
|
|
73
|
+
2. **Explicit config**: `publish.server` in reporter options
|
|
74
|
+
3. **Discovery**: `discoverServer()` fallback from `@swedevtools/livedoc-server`
|
|
75
|
+
4. **Default local viewer**: health check on `http://localhost:3100`
|
|
76
|
+
|
|
77
|
+
Project and environment can also be set with `LIVEDOC_PROJECT` and `LIVEDOC_ENVIRONMENT`.
|
|
78
|
+
|
|
79
|
+
### Coverage Evidence
|
|
80
|
+
|
|
81
|
+
LiveDoc can attach coverage artifacts to the completed `TestRunV1` as supporting evidence. Coverage never changes the run pass/fail status; threshold misses are reported as warnings.
|
|
82
|
+
|
|
83
|
+
Install the provider that matches the Vitest version:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
npm install --save-dev @vitest/coverage-v8
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { LiveDocSpecReporter } from "@swedevtools/livedoc-vitest/reporter";
|
|
91
|
+
|
|
92
|
+
export default defineConfig({
|
|
93
|
+
test: {
|
|
94
|
+
reporters: [
|
|
95
|
+
new LiveDocSpecReporter({
|
|
96
|
+
detailLevel: "spec+summary+headers",
|
|
97
|
+
coverage: {
|
|
98
|
+
enabled: true,
|
|
99
|
+
thresholds: { lines: 80, branches: 70 },
|
|
100
|
+
},
|
|
101
|
+
}),
|
|
102
|
+
],
|
|
103
|
+
coverage: {
|
|
104
|
+
enabled: true,
|
|
105
|
+
provider: "v8",
|
|
106
|
+
reporter: ["text", "html", "json-summary"],
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Run `npx vitest run --coverage`. LiveDoc consumes Vitest's in-memory coverage map during the reporter lifecycle. File reporters are optional fallbacks for static export and external coverage tooling.
|
|
113
|
+
|
|
114
|
+
Supported fallback artifacts:
|
|
115
|
+
|
|
116
|
+
| Artifact | Auto-detected path | Notes |
|
|
117
|
+
| --- | --- | --- |
|
|
118
|
+
| Istanbul summary JSON | `coverage/coverage-summary.json` | Preferred for run and file summaries |
|
|
119
|
+
| LCOV | `coverage/lcov.info` | Useful when summary JSON is not available |
|
|
120
|
+
|
|
121
|
+
Use `coverage.artifactPath` or `LIVEDOC_COVERAGE_PATH` when the artifact is outside the standard coverage directory. Use `LIVEDOC_COVERAGE=true` to request diagnostics when coverage is expected but no supported artifact is found.
|
|
122
|
+
|
|
123
|
+
### Additional Options
|
|
124
|
+
|
|
125
|
+
| Option | Type | Description |
|
|
126
|
+
| --- | --- | --- |
|
|
127
|
+
| `detailLevel` | string | Output detail level (see above) |
|
|
128
|
+
| `output` | string | Write output to file |
|
|
129
|
+
| `removeHeaderText` | string | Strip text from headers (monorepo prefix) |
|
|
130
|
+
| `colors` | boolean | Enable/disable ANSI colors |
|
|
131
|
+
| `postReporters` | `IPostReporter[]` | Chain additional reporters after this one |
|
|
132
|
+
|
|
133
|
+
## LiveDocViewerReporter
|
|
134
|
+
|
|
135
|
+
Streams results to the LiveDoc Viewer in real-time without console output. Use when you want viewer integration only.
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import { LiveDocViewerReporter } from "@swedevtools/livedoc-vitest/reporter";
|
|
139
|
+
|
|
140
|
+
export default defineConfig({
|
|
141
|
+
test: {
|
|
142
|
+
reporters: [
|
|
143
|
+
new LiveDocViewerReporter({
|
|
144
|
+
server: "http://localhost:3100",
|
|
145
|
+
project: "my-project",
|
|
146
|
+
environment: "local",
|
|
147
|
+
runType: "full",
|
|
148
|
+
}),
|
|
149
|
+
],
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Set `runType: "partial"` or `LIVEDOC_RUN_TYPE=partial` for an isolated development run after a full baseline has been published. The Viewer preserves the baseline and lets users switch between the combined snapshot and only that partial invocation. Partial runs require server history and cannot be written directly as static JSON.
|
|
155
|
+
|
|
156
|
+
## JsonReporter
|
|
157
|
+
|
|
158
|
+
Writes test results to a JSON file. Used for CI/CD static report generation.
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import { JsonReporter } from "@swedevtools/livedoc-vitest/reporter";
|
|
162
|
+
|
|
163
|
+
export default defineConfig({
|
|
164
|
+
test: {
|
|
165
|
+
reporters: [
|
|
166
|
+
new JsonReporter({ outputFile: "test-results.json" }),
|
|
167
|
+
],
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Static HTML Export
|
|
173
|
+
|
|
174
|
+
Generate a self-contained HTML report from a JSON results file:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
npx livedoc-viewer export -i test-results.json -o report.html
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### CI/CD Pipeline
|
|
181
|
+
|
|
182
|
+
```yaml
|
|
183
|
+
steps:
|
|
184
|
+
- name: Run tests with JSON output
|
|
185
|
+
run: npx vitest run --config vitest.config.json.ts
|
|
186
|
+
|
|
187
|
+
- name: Generate HTML report
|
|
188
|
+
run: npx livedoc-viewer export -i test-results.json -o report.html
|
|
189
|
+
|
|
190
|
+
- name: Upload report
|
|
191
|
+
uses: actions/upload-artifact@v4
|
|
192
|
+
with:
|
|
193
|
+
name: test-report
|
|
194
|
+
path: report.html
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Environment-Driven Config
|
|
198
|
+
|
|
199
|
+
Use environment variables for flexible CI configurations:
|
|
200
|
+
|
|
201
|
+
```json
|
|
202
|
+
{
|
|
203
|
+
"scripts": {
|
|
204
|
+
"test:spec": "cross-env LIVEDOC_DETAIL_LEVEL=spec+headers vitest run",
|
|
205
|
+
"test:list": "cross-env LIVEDOC_DETAIL_LEVEL=list+headers vitest run",
|
|
206
|
+
"test:summary": "cross-env LIVEDOC_DETAIL_LEVEL=summary+headers vitest run"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Backward Compatibility
|
|
212
|
+
|
|
213
|
+
`LiveDocServerReporter` is a deprecated re-export of `LiveDocSpecReporter`. Old configs still work.
|