@ai-ecoverse/slicc-shared-web 1.23.3 → 1.24.1
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 +2 -2
- package/bin/slicc-diff-cover.sh +2 -1
- package/bin/slicc-unit-cover.mjs +32 -9
- package/harness/recorder.mjs +3 -1
- package/mcr.config.mjs +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -144,7 +144,7 @@ The diff-coverage hook, `slicc-unit-cover`, runs only the unit tests that cover
|
|
|
144
144
|
- **A staged file no unit test reaches:** no tests run, its lines show as uncovered, and diff coverage fails as before.
|
|
145
145
|
- **A file that won't parse:** one warning line, then every unit test.
|
|
146
146
|
|
|
147
|
-
The hook passes the list to the repo's own `test:unit` in `SLICC_UNIT_TESTS` (one path per line). A `--require` preload, which `slicc-unit-cover` and the shared `mcr.config.mjs` add to `NODE_OPTIONS`, makes the `node --test` process run the files on that list that its own patterns match, and none when the list is empty. Without the variable, `npm run test:unit` runs everything as before. To force a full run in the hook:
|
|
147
|
+
The hook passes the list to the repo's own `test:unit` in `SLICC_UNIT_TESTS` (one path per line). A selection of more than `SLICC_UNIT_BATCH` files (60 by default) runs in batches of that size, one `test:unit` run each with its own coverage in `coverage/unit/batch-N/` (the shared `mcr.config.mjs` writes to `SLICC_UNIT_COVERAGE_DIR` when it's set), and `slicc-diff-cover` gets every batch's `lcov.info`; diff-cover counts a line covered when any batch covered it. The hook ends with one verdict line over all batches, `slicc-unit-cover: PASS …` or `slicc-unit-cover: FAIL …` (the first failing batch stops the run and fails it; diff coverage then doesn't run). That keeps the coverage merge, which grows with the number of test files, small enough for a memory-capped hook on a widely imported file. A `--require` preload, which `slicc-unit-cover` and the shared `mcr.config.mjs` add to `NODE_OPTIONS`, makes the `node --test` process run the files on that list that its own patterns match, and none when the list is empty. Without the variable, `npm run test:unit` runs everything as before. To force a full run in the hook:
|
|
148
148
|
|
|
149
149
|
```sh
|
|
150
150
|
SLICC_UNIT_ALL=1 git commit
|
|
@@ -157,7 +157,7 @@ SLICC_UNIT_ALL=1 git commit
|
|
|
157
157
|
|
|
158
158
|
CPU profiling is off by default. V8's sampler interrupts each page and worker thread every 100 µs with a signal, and the renderer SIGSEGVs in slicc-bios#114 all fault inside a signal handler walking the interrupted thread's frames, which points at it. Turn it on with `profile: true` or `SLICC_PROFILE=1` to get one CPU profile per target and snapshot in the test's artifact directory, and the 15 frames with the most self time in the repo's own scripts in `hotspots.md`. Without it, `hotspots.md` says that profiling is off.
|
|
159
159
|
|
|
160
|
-
`monocart-coverage-reports` is a peer dependency; pin it in the repo's `devDependencies`. The browser is the first of these:
|
|
160
|
+
`monocart-coverage-reports` is a peer dependency (2.13 or later, 3.x included); pin it in the repo's `devDependencies`. The harness works with both majors: 3.x's `/util` entry has only a named `Util` export and 2.x's a default one, and CI runs the recorder and the unit-cover hook on 2.13.2 and the latest 3.x. The browser is the first of these:
|
|
161
161
|
- `launch({ executable })`;
|
|
162
162
|
- `$CHROME_PATH`;
|
|
163
163
|
- `findBrowser()` from `@ai-ecoverse/slicc-cdp`. It finds a Chrome for Testing that `npx slicc-cdp install-browser --version <x.y.z.w>` installed, or a system Chrome;
|
package/bin/slicc-diff-cover.sh
CHANGED
|
@@ -4,4 +4,5 @@ if ! command -v uvx > /dev/null 2>&1; then
|
|
|
4
4
|
printf 'slicc-diff-cover runs diff-cover through uvx; install uv first: https://docs.astral.sh/uv/getting-started/installation/\n' >&2
|
|
5
5
|
exit 1
|
|
6
6
|
fi
|
|
7
|
-
|
|
7
|
+
[ "$#" -gt 0 ] || set -- coverage/unit/lcov.info
|
|
8
|
+
exec uvx diff-cover@10.6.0 "$@" --compare-branch HEAD --ignore-unstaged --fail-under 100
|
package/bin/slicc-unit-cover.mjs
CHANGED
|
@@ -8,6 +8,10 @@ import { inject } from '../unit/inject.mjs';
|
|
|
8
8
|
|
|
9
9
|
const root = process.cwd();
|
|
10
10
|
const say = (line) => process.stderr.write(`slicc-unit-cover: ${line}\n`);
|
|
11
|
+
const verdict = (ok, line) => {
|
|
12
|
+
process.stdout.write(`slicc-unit-cover: ${ok ? 'PASS' : 'FAIL'} ${line}\n`);
|
|
13
|
+
process.exit(ok ? 0 : 1);
|
|
14
|
+
};
|
|
11
15
|
|
|
12
16
|
function git(...args) {
|
|
13
17
|
const run = spawnSync('git', args, { cwd: root, encoding: 'utf8' });
|
|
@@ -45,20 +49,39 @@ const staged = (git('diff', '--cached', '--name-only', '--relative', '--no-renam
|
|
|
45
49
|
.filter(Boolean);
|
|
46
50
|
if (process.env.SLICC_UNIT_ALL !== '1' && !staged.some((file) => code.test(file))) {
|
|
47
51
|
say('no code staged, skipping unit tests and diff coverage');
|
|
48
|
-
|
|
52
|
+
verdict(true, 'no code staged');
|
|
49
53
|
}
|
|
50
54
|
|
|
51
|
-
const
|
|
55
|
+
const size = Number(process.env.SLICC_UNIT_BATCH ?? 60);
|
|
52
56
|
const tests = selection(staged);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
const batches = [];
|
|
58
|
+
if (tests === undefined || !(size > 0) || tests.length <= size) batches.push(tests);
|
|
59
|
+
else for (let at = 0; at < tests.length; at += size) batches.push(tests.slice(at, at + size));
|
|
60
|
+
const reports = [];
|
|
61
|
+
for (const [index, batch] of batches.entries()) {
|
|
62
|
+
const env = { ...process.env };
|
|
63
|
+
if (batch === undefined) delete env.SLICC_UNIT_TESTS;
|
|
64
|
+
else {
|
|
65
|
+
env.SLICC_UNIT_TESTS = batch.join('\n');
|
|
66
|
+
env.NODE_OPTIONS = inject(env.NODE_OPTIONS ?? '');
|
|
67
|
+
}
|
|
68
|
+
if (batches.length > 1) {
|
|
69
|
+
env.SLICC_UNIT_COVERAGE_DIR = join('coverage', 'unit', `batch-${index + 1}`);
|
|
70
|
+
reports.push(join(env.SLICC_UNIT_COVERAGE_DIR, 'lcov.info'));
|
|
71
|
+
say(`batch ${index + 1} of ${batches.length}: ${batch.length} files`);
|
|
72
|
+
}
|
|
73
|
+
const status = run('npm', ['run', '--silent', 'test:unit'], env);
|
|
74
|
+
if (status !== 0) {
|
|
75
|
+
const which = batches.length > 1 ? `batch ${index + 1} of ${batches.length}` : 'the unit tests';
|
|
76
|
+
verdict(false, `${which} failed (status ${status})`);
|
|
77
|
+
}
|
|
57
78
|
}
|
|
58
|
-
const status = run('npm', ['run', '--silent', 'test:unit'], env);
|
|
59
|
-
if (status !== 0) process.exit(status);
|
|
60
79
|
const local = join(root, 'node_modules', '.bin', 'slicc-diff-cover');
|
|
61
80
|
const cover = existsSync(local)
|
|
62
81
|
? local
|
|
63
82
|
: fileURLToPath(new URL('slicc-diff-cover.sh', import.meta.url));
|
|
64
|
-
|
|
83
|
+
const files = tests === undefined ? 'every unit test file' : `${tests.length} unit test files`;
|
|
84
|
+
const counted = `${batches.length} ${batches.length === 1 ? 'batch' : 'batches'}`;
|
|
85
|
+
const covered = run(cover, reports, process.env);
|
|
86
|
+
if (covered !== 0) verdict(false, `diff coverage is not 100% (${files} in ${counted})`);
|
|
87
|
+
verdict(true, `${files} in ${counted}, diff coverage 100%`);
|
package/harness/recorder.mjs
CHANGED
|
@@ -2,11 +2,13 @@ import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
|
2
2
|
import { basename, relative } from 'node:path';
|
|
3
3
|
import { cwd } from 'node:process';
|
|
4
4
|
import { pathToFileURL } from 'node:url';
|
|
5
|
-
import
|
|
5
|
+
import * as mcrUtil from 'monocart-coverage-reports/util';
|
|
6
6
|
import { CRASHED } from './cdp.mjs';
|
|
7
7
|
import { trace } from './trace.mjs';
|
|
8
8
|
import { bounded, ignore, raw, samples, sleep, TIMED_OUT } from './util.mjs';
|
|
9
9
|
|
|
10
|
+
const Util = mcrUtil.Util ?? mcrUtil.default;
|
|
11
|
+
|
|
10
12
|
const profiled = new Set(['page', 'worker', 'service_worker', 'shared_worker']);
|
|
11
13
|
const sampling = [['Profiler.setSamplingInterval', { interval: 100 }], ['Profiler.start']];
|
|
12
14
|
const unload = "addEventListener('beforeunload', () => { debugger; })";
|
package/mcr.config.mjs
CHANGED
|
@@ -12,7 +12,7 @@ const ours = (url) =>
|
|
|
12
12
|
|
|
13
13
|
export default {
|
|
14
14
|
name: process.env.npm_package_name ?? 'unit',
|
|
15
|
-
outputDir: 'coverage/unit',
|
|
15
|
+
outputDir: process.env.SLICC_UNIT_COVERAGE_DIR ?? 'coverage/unit',
|
|
16
16
|
reports: ['lcovonly', 'console-details'],
|
|
17
17
|
all: { dir: 'src', filter: '**/*.{js,mjs,ts}', transformer: strip },
|
|
18
18
|
entryFilter: (entry) => ours(entry.url),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-ecoverse/slicc-shared-web",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.24.1",
|
|
4
4
|
"description": "Shared Renovate, Biome, TypeScript, lefthook and GitHub Actions configuration, plus the CDP integration-test harness, for SLICC's web repos",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -62,16 +62,16 @@
|
|
|
62
62
|
"release": "semantic-release"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@ai-ecoverse/slicc-browsers": "1.
|
|
65
|
+
"@ai-ecoverse/slicc-browsers": "1.8.4",
|
|
66
66
|
"@biomejs/biome": "2.5.15",
|
|
67
67
|
"monocart-coverage-reports": "2.13.2",
|
|
68
68
|
"playwright-core": "1.64.0",
|
|
69
|
-
"pnpm": "12.
|
|
69
|
+
"pnpm": "12.12.0",
|
|
70
70
|
"semantic-release": "25.0.9"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
73
|
"@ai-ecoverse/slicc-cdp": "*",
|
|
74
|
-
"monocart-coverage-reports": ">=2.13.0",
|
|
74
|
+
"monocart-coverage-reports": ">=2.13.0 <4",
|
|
75
75
|
"playwright-core": ">=1.50.0"
|
|
76
76
|
},
|
|
77
77
|
"peerDependenciesMeta": {
|