monocart-coverage-reports 3.0.0 → 3.1.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/README.md +47 -2
- package/README.zh-Hans.md +47 -2
- package/lib/converter/ast.js +23 -2
- package/lib/converter/collect-source-maps.js +33 -12
- package/lib/converter/converter.js +84 -15
- package/lib/converter/css-coverage.js +76 -0
- package/lib/converter/find-original-range.js +211 -3
- package/lib/converter/untested.js +4 -6
- package/lib/packages/monocart-coverage-assets.js +1 -1
- package/lib/packages/monocart-coverage-converter.js +11 -11
- package/lib/packages/monocart-coverage-vendor.js +1 -1
- package/lib/packages/monocart-coverage-vendor.js.LICENSE +3 -3
- package/lib/platform/share.js +7 -0
- package/lib/utils/source-path.js +21 -6
- package/lib/utils/util.js +6 -1
- package/package.json +161 -153
- package/skills/monocart-coverage-reports/SKILL.md +2 -2
- package/skills/monocart-coverage-reports/references/best-practices.md +218 -0
- package/skills/monocart-coverage-reports/references/collection.md +2 -0
- package/skills/monocart-coverage-reports/references/repository-map.md +7 -3
- package/lib/packages/chunks/chunk-RVOSNMVU.js +0 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: monocart-coverage-reports
|
|
3
|
-
description: Collect, generate, merge, and debug JavaScript, TypeScript, and CSS code coverage with monocart-coverage-reports (MCR) 3.x. Use for Node.js tests and mcr test, native V8 or Istanbul coverage, Playwright/Puppeteer Chromium coverage, CLI/configuration, sourcemaps, filters, untested files, CI reports and thresholds, and
|
|
3
|
+
description: Collect, generate, merge, and debug JavaScript, TypeScript, and CSS code coverage with monocart-coverage-reports (MCR) 3.x. Use for Node.js tests and mcr test, native V8 or Istanbul coverage, Playwright/Puppeteer Chromium coverage, CLI/configuration, sourcemaps, filters, untested files, CI reports and thresholds, shard merging, and testing best practices. Also applies to Chinese requests about Monocart、MCR 最佳实践、代码覆盖率、覆盖率报告、覆盖率合并、覆盖率过滤和源码映射.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Coverage with Monocart Coverage Reports 3.x
|
|
@@ -23,7 +23,7 @@ Read the manifest for version, engines, exports, and types. Resolve bundled link
|
|
|
23
23
|
## Workflow and reference routing
|
|
24
24
|
|
|
25
25
|
1. Inspect the host's scripts, runtime, MCR version, module format, and CI. Identify the desired source scope, reports, and parallel/sharded runs.
|
|
26
|
-
2. Choose **one collection path**. Reuse
|
|
26
|
+
2. Choose **one collection path**. For a new Node.js test setup, prefer **`node:test` + `mcr test`**; for browser tests, prefer **Playwright Test + MCR**, or **Playwright Test + monocart-reporter** (already integrates MCR). Read [MCR best practices](references/best-practices.md) when choosing a setup or implementing browser test fixtures. Reuse an existing runner (`mcr -c mcr.config.mjs -- npm run test:unit`) rather than forcing migration. Read [collection.md](references/collection.md) for browser/CDP, manual Node capture, or Istanbul data.
|
|
27
27
|
3. Confirm sources/maps match the **exact tested build**. Choose input filtering (`entryFilter` + `sourceFilter`, or `filter`) for early exclusion/performance, or `outputFilter` for simpler final-path selection at the cost of processing unwanted inputs. Do not stack strategies automatically; output filtering cannot restore discarded inputs. Read [filtering-and-sourcemaps.md](references/filtering-and-sourcemaps.md) for examples, untested files, ignores, and debugging.
|
|
28
28
|
4. Read [cli.md](references/cli.md) for config, argument boundaries, Node runner options, and hooks.
|
|
29
29
|
5. Read [reports-and-ci.md](references/reports-and-ci.md) for thresholds, stale-result prevention, raw exports, validated shard merging, and snapshots.
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# MCR best practices: test code and get useful coverage
|
|
2
|
+
|
|
3
|
+
Use this module to choose a test setup and implement coverage collection. These recipes target **MCR 3.x and Node.js >= 22.15.0**. Reuse the host package manager, module format, test server, and installed tools. Do not upgrade dependencies or migrate an existing runner without approval.
|
|
4
|
+
|
|
5
|
+
## 1. Choose the simplest collection path
|
|
6
|
+
|
|
7
|
+
| Target | Default recommendation | Why |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| New Node.js tests | **Node.js native test runner + `mcr test`** | Built-in assertions/tests, automatic native V8 JS coverage, no instrumentation or custom collector. |
|
|
10
|
+
| Browser tests | **Playwright Test + MCR** | Runner-managed lifecycle and assertions; direct control over JS/CSS coverage reports. |
|
|
11
|
+
| Browser tests with integrated reporting | **Playwright Test + monocart-reporter** | Already integrates MCR; combines test results and coverage reporting. |
|
|
12
|
+
| Existing Jest/Vitest/Mocha/etc. | Keep the existing runner and its compatible collection integration | Adding coverage should not require rewriting working tests. |
|
|
13
|
+
|
|
14
|
+
MCR collects/processes coverage and generates reports; the test runner executes assertions. Prefer native V8 collection where supported. Choose **one owner** for collection and final generation, rather than collecting the same execution through multiple integrations.
|
|
15
|
+
|
|
16
|
+
## 2. Node.js: prefer `mcr test <targets>`
|
|
17
|
+
|
|
18
|
+
Write tests with `node:test` and `node:assert/strict`. Cover meaningful outputs, errors, boundaries, and asynchronous behavior; use the real module rather than duplicating its implementation in a test. See the [complete module and test example](../SKILL.md#quick-start-test-your-code-and-get-coverage-3x).
|
|
19
|
+
|
|
20
|
+
Install only if needed, using the host package manager:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
npm install --save-dev monocart-coverage-reports@^3
|
|
24
|
+
npx mcr test "./test/**/*.test.mjs" -r v8,console-summary
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Replace the glob with actual test targets. For a repeatable project command, put `mcr test -c mcr.config.mjs` in an npm script such as `test:coverage`, with this config:
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
// mcr.config.mjs
|
|
31
|
+
export default {
|
|
32
|
+
test: ['./test/**/*.test.mjs'],
|
|
33
|
+
outputDir: './coverage-reports/node',
|
|
34
|
+
reports: ['v8', 'console-summary'],
|
|
35
|
+
outputFilter: {
|
|
36
|
+
'**/node_modules/**': false,
|
|
37
|
+
'**/src/**': true
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
This example selects final `src/` paths. Adapt it to the host's real source layout and verify the resulting file list; do not copy a filter that excludes the code under test. See [filtering and sourcemaps](filtering-and-sourcemaps.md) for early input filtering, transpiled sources, and `all` for files never loaded by tests.
|
|
43
|
+
|
|
44
|
+
- `mcr test` invokes Node's native `--test`, automatically collects V8 JS coverage, and generates the selected reports. No manual `NODE_V8_COVERAGE`, coverage instrumentation, or API collector is needed.
|
|
45
|
+
- Quote target globs. Forward Node runner flags after `--`, for example `npx mcr test "./test/**/*.test.mjs" -- --test-reporter=spec`.
|
|
46
|
+
- Supply actual targets or config `test`; an empty target list skips testing and reporting.
|
|
47
|
+
- Open `coverage-reports/index.html` for the first command, or `coverage-reports/node/index.html` for the config above. Verify expected sources and use uncovered branches to choose the next tests.
|
|
48
|
+
- Failed tests still attempt report generation and remain failures. Do not suppress the exit status because an HTML file exists.
|
|
49
|
+
- Existing runners may use `mcr -c mcr.config.mjs -- npm run test:unit` for Node V8 collection where compatible; avoid duplicate coverage providers. TypeScript needs the host's supported loader/build and matching sourcemaps, not an assumption that every TS syntax runs directly.
|
|
50
|
+
|
|
51
|
+
See [CLI details](cli.md) for target overrides, configuration discovery, and argument boundaries.
|
|
52
|
+
|
|
53
|
+
## 3. Browser: Playwright Test + MCR
|
|
54
|
+
|
|
55
|
+
Run tests with **`playwright test`**, not `mcr test`. Wrapping Playwright's Node runner with the MCR CLI does **not** collect JavaScript executing inside browser pages.
|
|
56
|
+
|
|
57
|
+
Use an automatic test-scoped fixture: start coverage before navigation, run real assertions, then stop and persist coverage before Playwright closes the page. This includes normal assertion failures. Generate once in the coordinator after every worker has finished writing.
|
|
58
|
+
|
|
59
|
+
### Complete project example
|
|
60
|
+
|
|
61
|
+
[playwright-coverage](https://github.com/cenfun/playwright-coverage) is a minimal **Playwright Test + MCR 3.x** example using plain JavaScript ESM. It tests browser-side application code, not the Playwright test scripts or a Node.js backend. Its [quick start](https://github.com/cenfun/playwright-coverage#quick-start-for-your-own-project) explains how to adapt these five files to your application:
|
|
62
|
+
|
|
63
|
+
| File | Purpose |
|
|
64
|
+
| --- | --- |
|
|
65
|
+
| [fixtures.js](https://github.com/cenfun/playwright-coverage/blob/main/fixtures.js) | Automatically start/stop page JS/CSS coverage and persist it with `add()`, including ordinary assertion failures. |
|
|
66
|
+
| [mcr.config.js](https://github.com/cenfun/playwright-coverage/blob/main/mcr.config.js) | Share output/report options and keep `cleanCache: false` for workers. |
|
|
67
|
+
| [global.setup.js](https://github.com/cenfun/playwright-coverage/blob/main/global.setup.js) | Clear the dedicated output directory before workers start. |
|
|
68
|
+
| [global-teardown.js](https://github.com/cenfun/playwright-coverage/blob/main/global-teardown.js) | Generate once after all workers finish; reject missing/empty results. |
|
|
69
|
+
| [playwright.config.js](https://github.com/cenfun/playwright-coverage/blob/main/playwright.config.js) | Select Chromium, register hooks, and configure the test runner. |
|
|
70
|
+
|
|
71
|
+
For an existing application, merge these settings, configure its actual `baseURL` and server lifecycle, and import the extended `test` from the fixture. Do not change the application's module system just for coverage; use `.mjs` as below when appropriate. Browser dependencies and binaries must already be installed or their installation approved.
|
|
72
|
+
|
|
73
|
+
The example's [Todo tests](https://github.com/cenfun/playwright-coverage/blob/main/tests/demo-todo-app.spec.js) serve real local HTML/JS/CSS through Playwright routes so the tests need no server or external website. They assert item creation, input clearing, whitespace handling, and text rendering. The routes and Todo assets are only an offline demo, not extra infrastructure to copy into your application.
|
|
74
|
+
|
|
75
|
+
Run `npm test` in the example project. Inspect `coverage-reports/index.html` for code coverage, `coverage-reports/lcov.info` for CI, and `playwright-report/index.html` for test results. These are different artifacts: a passing test report alone does not validate coverage. For JS-only coverage, omit CSS collection; retain sourcemaps and select your real application source scope for bundled code.
|
|
76
|
+
|
|
77
|
+
### Minimal parallel-safe integration
|
|
78
|
+
|
|
79
|
+
This example assumes `@playwright/test` and MCR 3.x are installed, an approved Chromium binary is available, and the application server is already running. Reuse the host's server lifecycle/readiness checks (such as Playwright `webServer`); do not silently download browsers. Save these files at the host project root except the spec under `e2e/`. Merge the settings into an existing Playwright config rather than replacing its projects or hooks.
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
// coverage-options.mjs
|
|
83
|
+
export default {
|
|
84
|
+
outputDir: './coverage-reports/browser',
|
|
85
|
+
reports: ['v8', 'console-summary'],
|
|
86
|
+
// Workers share this cache. Only the coordinator may clean it.
|
|
87
|
+
cleanCache: false
|
|
88
|
+
};
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
// coverage-setup.mjs
|
|
93
|
+
import fs from 'node:fs';
|
|
94
|
+
import options from './coverage-options.mjs';
|
|
95
|
+
|
|
96
|
+
export default function globalSetup() {
|
|
97
|
+
// Dedicated to this run: never share with another active Playwright invocation.
|
|
98
|
+
// Remove old reports as well as cache, so missing collection cannot leave stale artifacts.
|
|
99
|
+
fs.rmSync(options.outputDir, { recursive: true, force: true });
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
// coverage-fixtures.mjs
|
|
105
|
+
import { test as base, expect } from '@playwright/test';
|
|
106
|
+
import { MCR } from 'monocart-coverage-reports';
|
|
107
|
+
import options from './coverage-options.mjs';
|
|
108
|
+
|
|
109
|
+
export const test = base.extend({
|
|
110
|
+
coverage: [async ({ page, browserName }, use) => {
|
|
111
|
+
if (browserName !== 'chromium') {
|
|
112
|
+
// Other browser projects still run tests, but do not provide native coverage.
|
|
113
|
+
await use();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
await Promise.all([
|
|
117
|
+
page.coverage.startJSCoverage({ resetOnNavigation: false }),
|
|
118
|
+
page.coverage.startCSSCoverage({ resetOnNavigation: false })
|
|
119
|
+
]);
|
|
120
|
+
try {
|
|
121
|
+
await use();
|
|
122
|
+
} finally {
|
|
123
|
+
const [js, css] = await Promise.all([
|
|
124
|
+
page.coverage.stopJSCoverage(),
|
|
125
|
+
page.coverage.stopCSSCoverage()
|
|
126
|
+
]);
|
|
127
|
+
await MCR(options).add([...js, ...css]);
|
|
128
|
+
}
|
|
129
|
+
}, { auto: true }]
|
|
130
|
+
});
|
|
131
|
+
export { expect };
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
```js
|
|
135
|
+
// coverage-teardown.mjs
|
|
136
|
+
import { MCR } from 'monocart-coverage-reports';
|
|
137
|
+
import options from './coverage-options.mjs';
|
|
138
|
+
|
|
139
|
+
export default async function globalTeardown() {
|
|
140
|
+
const results = await MCR(options).generate();
|
|
141
|
+
if (!results || !results.files.length) {
|
|
142
|
+
throw new Error('No browser coverage generated: check fixtures and source scope');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
```js
|
|
148
|
+
// playwright.config.mjs
|
|
149
|
+
import { defineConfig } from '@playwright/test';
|
|
150
|
+
|
|
151
|
+
export default defineConfig({
|
|
152
|
+
testDir: './e2e',
|
|
153
|
+
globalSetup: './coverage-setup.mjs',
|
|
154
|
+
globalTeardown: './coverage-teardown.mjs',
|
|
155
|
+
use: {
|
|
156
|
+
browserName: 'chromium',
|
|
157
|
+
baseURL: process.env.APP_URL || 'http://localhost:3000'
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
```js
|
|
163
|
+
// e2e/counter.spec.mjs
|
|
164
|
+
import { test, expect } from '../coverage-fixtures.mjs';
|
|
165
|
+
|
|
166
|
+
// Assumes a counter starting at 0; replace with your application's actual behavior.
|
|
167
|
+
test('increments the counter when clicked', async ({ page }) => {
|
|
168
|
+
await page.goto('/');
|
|
169
|
+
const counter = page.getByTestId('counter');
|
|
170
|
+
await expect(counter).toHaveText('0');
|
|
171
|
+
await page.getByRole('button', { name: 'Increment', exact: true }).click();
|
|
172
|
+
await expect(counter).toHaveText('1');
|
|
173
|
+
});
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
```sh
|
|
177
|
+
npx playwright test
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
All covered specs must import the extended `test` from the fixture, not directly from `@playwright/test`. Inspect `coverage-reports/browser/index.html`. The example deliberately starts without a source filter: inspect actual bundle URLs and mapped paths, then select application sources using [filtering and sourcemaps](filtering-and-sourcemaps.md). Leaving vendor/runtime code in the report is not an accurate application coverage scope.
|
|
181
|
+
|
|
182
|
+
### Lifecycle and scope limitations
|
|
183
|
+
|
|
184
|
+
- Native `page.coverage` JS/CSS collection is **Chromium-only**. Firefox/WebKit require a separate instrumentation-based approach, such as collecting an Istanbul map; changing the reporter does not remove this limitation.
|
|
185
|
+
- `resetOnNavigation: false` preserves coverage across navigations in the same page. The fixture covers only its `page`; extra pages/popups, workers, and the Node.js backend require explicit collection strategies. Tests must not close the covered page before fixture teardown.
|
|
186
|
+
- Assertion failures normally run fixture teardown; crashes, forced termination, or timeouts may prevent collection. Retain the original failure and report collection failures rather than claiming coverage is complete.
|
|
187
|
+
- Only the coordinator removes the dedicated output directory before workers start. Clearing only `.cache` would leave old HTML reports available for upload if collection fails. Never point `outputDir` at source code, merge inputs, or another run's output.
|
|
188
|
+
- Do not call `generate()` or `cleanCache()` in each test/worker. `add()` persists data; the coordinator merges it during final generation. `cleanCache: true` in a shared worker would erase other tests' inputs.
|
|
189
|
+
- Give independent CI runs/shards separate output directories. Export `raw` per shard and merge only after validating every expected shard; do not let independent global teardowns race on shared cache. See [reports and CI](reports-and-ci.md).
|
|
190
|
+
|
|
191
|
+
## 4. Browser alternative: Playwright Test + monocart-reporter
|
|
192
|
+
|
|
193
|
+
Choose this when you also want Monocart's Playwright test report, rather than maintaining a separate MCR reporting lifecycle. **monocart-reporter already integrates MCR**; do not add another MCR generator for the same data.
|
|
194
|
+
|
|
195
|
+
1. Check the installed reporter's version, runtime requirements, bundled MCR version, and [official code coverage integration](https://github.com/cenfun/monocart-reporter#code-coverage-report). Do not assume its bundled MCR major matches a separate top-level installation or pass unsupported MCR 3.x options.
|
|
196
|
+
2. Add `monocart-reporter` to the host's Playwright `reporter` configuration and configure its `coverage` options according to that release's documentation.
|
|
197
|
+
3. Use an automatic Playwright fixture to start/stop page coverage around each test, as above, but submit the data through the reporter's documented coverage API with the current `testInfo`, instead of `MCR(options).add()`.
|
|
198
|
+
4. Let the reporter own aggregation, cleanup, and final report generation. Do **not** also install the direct-MCR global setup/teardown above. Follow the reporter's own merge workflow for parallel jobs/shards.
|
|
199
|
+
5. Run `npx playwright test` and verify both the test report and its coverage report contain current, intended data. Enabling a reporter alone does not start browser coverage collection.
|
|
200
|
+
|
|
201
|
+
Use the version-matched official fixture rather than guessing reporter API signatures. Direct MCR is preferable when you need independent coverage lifecycle/options; the reporter is preferable when you want unified test and coverage reporting. Both use the same browser coverage limitations.
|
|
202
|
+
|
|
203
|
+
## 5. Make coverage trustworthy
|
|
204
|
+
|
|
205
|
+
- **Test behavior, not a percentage.** Add assertions for normal, boundary, error, and async paths. Use uncovered branches to find missing cases; do not weaken assertions or add unjustified ignores to satisfy a threshold.
|
|
206
|
+
- **Match the exact build.** Keep tested source, bundle, and sourcemaps together. For TS/bundlers, verify mapped source and line positions; do not rebuild different artifacts before generating/merging coverage.
|
|
207
|
+
- **Define the denominator.** Exclude only justified out-of-scope dependencies/generated assets, and use `all` when untouched application files must count as uncovered. A high percentage of loaded files alone does not prove the whole application is tested.
|
|
208
|
+
- **Choose useful artifacts.** Start with `v8` and `console-summary`; add `lcovonly` for compatible CI services, `v8-json` for machine validation, or `raw` for later merging. Do not merge HTML, summaries, or percentages.
|
|
209
|
+
- **Fail honestly.** Test, collection, report, and threshold failures must remain nonzero. `watermarks` only colors results; enforce thresholds explicitly. API callers must reject missing/empty results; CI must reject stale artifacts, not just check whether an old HTML file exists. See [strict CI and threshold recipes](reports-and-ci.md).
|
|
210
|
+
- **Keep artifacts safe.** Use dedicated per-run output directories and retain useful reports on failures without masking status. Reports and raw/debug data may contain source code, private paths, and URLs; publish only with approval.
|
|
211
|
+
|
|
212
|
+
### Delivery checklist
|
|
213
|
+
|
|
214
|
+
- [ ] The chosen runner executes real assertions; collection starts before application execution/navigation.
|
|
215
|
+
- [ ] The report contains the intended current sources, accurate mappings, and any required untested files.
|
|
216
|
+
- [ ] Parallel tests do not clear one another's data; every required shard contributes to the merge.
|
|
217
|
+
- [ ] Reports are fresh and nonempty, and test/report/threshold failure paths fail CI.
|
|
218
|
+
- [ ] The user receives the run command, report location, source scope, and any collection limitations.
|
|
@@ -15,6 +15,8 @@ Examples use ESM (`.mjs`, or `.js` under `"type": "module"`) and the MCR 3.x run
|
|
|
15
15
|
|
|
16
16
|
Do not assume Chromium V8 coverage works in Firefox/WebKit or that it automatically covers every browser context, page, worker, or remote backend. Explicitly collect the runtimes/targets the task requires.
|
|
17
17
|
|
|
18
|
+
For test suites, prefer the [Playwright Test fixture and lifecycle in MCR best practices](best-practices.md#3-browser-playwright-test--mcr), or its `monocart-reporter` alternative. The standalone script below is for custom collection outside a runner.
|
|
19
|
+
|
|
18
20
|
## Playwright Chromium: complete standalone script
|
|
19
21
|
|
|
20
22
|
Assumes the application's test server is already running at `APP_URL` (or the local default). Prefer the host's existing server lifecycle and readiness checks.
|
|
@@ -17,7 +17,7 @@ Current exports: main API, `/register` source-capture preload, `/converter` and
|
|
|
17
17
|
|
|
18
18
|
## Checkout navigation
|
|
19
19
|
|
|
20
|
-
Paths below are relative to the repository root and are generally **not shipped in npm** except `lib/`.
|
|
20
|
+
Paths below are relative to the repository root and are generally **not shipped in npm** except `lib/`. When working in a source checkout, read its root `AGENTS.md` first for shared development rules and command side effects. That file is checkout-only; do not require it when using the installed skill.
|
|
21
21
|
|
|
22
22
|
| Task | Read first | Related validation / examples |
|
|
23
23
|
| --- | --- | --- |
|
|
@@ -33,7 +33,7 @@ Paths below are relative to the repository root and are generally **not shipped
|
|
|
33
33
|
| Filters and normalized paths | `lib/utils/util.js`, `lib/utils/source-path.js`, `lib/generate.js` | `test/unit/output-filter.test.js`, `test/unit/source-path.test.js` |
|
|
34
34
|
| Native V8/Istanbul generation | `lib/v8/v8.js`, `lib/istanbul/istanbul.js`, `lib/reports/` | `test/test-v8-and-istanbul.js`, custom reporter examples under `test/` |
|
|
35
35
|
| Snapshots | `lib/utils/snapshot.js` | `test/check-snapshot.js`, `test/snapshot/` |
|
|
36
|
-
|
|
|
36
|
+
| HTML assets and report UI | `lib/assets.js`, `lib/default/template.html`, `src/app/`, `src/vendor/`, `vite.config.mjs` | `npm run dev`, `npm run build`, `npm run test-runtime` |
|
|
37
37
|
| Runtime compatibility / upgrade | `migrate-to-3.md`, `scripts/test-runtime.js` | `test/unit/node-version.test.js` |
|
|
38
38
|
|
|
39
39
|
## Development validation
|
|
@@ -48,7 +48,11 @@ npm run test-runtime
|
|
|
48
48
|
|
|
49
49
|
Unit tests run directly with `node:test`, independently of the MCR CLI and coverage pipeline. For a focused test: `node --test test/unit/config.test.js`. Run `npm run test-unit-coverage` separately to collect coverage through `mcr test`; reports are written to `.temp/coverage-unit/`. For focused coverage: `node ./lib/cli.js test -c test/mcr.config.unit.js test/unit/config.test.js`. Browser/integration scripts may require downloaded browsers, built fixtures, local servers, and more time; inspect the relevant script before running it. `npm run build` invokes `postbuild` and builds test fixtures. `npm test` also runs integration/report generation and documentation generation; it is not a lightweight unit-only check.
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
A fresh checkout needs `npm run build` to generate `lib/packages/` before tests that import these bundles. Rebuild after changing UI, template, or vendor-entry source.
|
|
52
|
+
|
|
53
|
+
Avoid unrelated generated changes. `npm run lint` currently includes `--fix`; inspect its scope before invoking it. Use `npx --no-install eslint src/ test/unit/` for the usual scope without fixes, and explicit paths for other changed source. Do not hand-edit generated `lib/packages/*`, `dist/`, `docs/`, or `test/mock/*/dist/`; use the build/generation workflow. `lib/assets.js` is handwritten runtime source, not generated output. Snapshot baseline changes must be intentional and reviewed, never a way to hide a defect.
|
|
54
|
+
|
|
55
|
+
Do not use `npm run eol` for validation: it removes the index and runs a hard reset. `npm run test:snap` overwrites baselines. `npm run publish` prepares a release through `npm version`, including its build hook and commit/tag creation; obtain explicit approval before release preparation or external writes.
|
|
52
56
|
|
|
53
57
|
When changing public behavior, align implementation, `lib/index.d.ts`, default options, English/Chinese docs, migration notes where applicable, and focused tests. This skill supports MCR 3.x only. Validate the installed package separately when release compatibility matters; do not infer support for other major versions from these recipes.
|
|
54
58
|
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
var g=Object.create;var f=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var m=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(b,c)=>(typeof require<"u"?require:b)[c]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var n=(a,b)=>()=>{try{return b||a((b={exports:{}}).exports,b),b.exports}catch(c){throw b=0,c}};var l=(a,b,c,e)=>{if(b&&typeof b=="object"||typeof b=="function")for(let d of i(b))!k.call(a,d)&&d!==c&&f(a,d,{get:()=>b[d],enumerable:!(e=h(b,d))||e.enumerable});return a};var o=(a,b,c)=>(c=a!=null?g(j(a)):{},l(b||!a||!a.__esModule?f(c,"default",{value:a,enumerable:!0}):c,a));export{m as a,n as b,o as c};
|