@ai-ecoverse/slicc-shared-web 1.12.3 → 1.13.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 +1 -0
- package/harness/chrome.mjs +30 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,6 +63,7 @@ test('boots', async (t) => {
|
|
|
63
63
|
| `exits` | `{ urlPath: [regex, ...] }`: a breakpoint on the first line matching each pattern in that worker script, where the harness takes the worker's coverage and profile before it closes itself | none |
|
|
64
64
|
| `intercept` | Remote URL prefixes answered from a disk cache in `node_modules/.cache/`. Registry documents (anything on a `registry.*` host but a `/-/….tgz` tarball: packuments, abbreviated or full, and dist-tags) are fetched fresh once per test process and only served from the disk cache when the registry can't be reached (a `4xx` is passed on) | none |
|
|
65
65
|
| `extensions` | Unpacked extension directories to load. They are loaded with `Extensions.loadUnpacked` (behind `--enable-unsafe-extension-debugging`) once the harness is attached, so their service workers start paused like every other target. Their scripts are covered and profiled like the repo's own, and tests then run in the default browser context, closing their tabs when they end, because Chrome does not run extensions in the per-test contexts | none |
|
|
66
|
+
| `persistent` | Run every test in the default browser context, on the launch's on-disk `slicc-harness-*` profile, instead of a fresh off-the-record context per test. Off-the-record contexts keep OPFS in memory, with a far smaller real budget than `navigator.storage.estimate()` reports, so a suite that stores hundreds of MB there needs this. When a test ends, its tabs are closed and `Storage.clearDataForOrigin` (`storageTypes: 'all'`) clears the server's origin, every origin a page in the context showed (popups the app opened included) and every origin the harness's tabs got a response from, so nothing leaks into the next test. If clearing fails, the test fails | `false` |
|
|
66
67
|
| `args` | Extra Chromium flags, such as `--host-resolver-rules` or `--ignore-certificate-errors` | none |
|
|
67
68
|
| `timeout` | How long `page.until` polls and `page.evaluate` waits, in ms | `30000` |
|
|
68
69
|
| `stallAfter` | How long one evaluation may run before the harness probes the test's targets, in ms | `30000` |
|
package/harness/chrome.mjs
CHANGED
|
@@ -237,6 +237,7 @@ export async function launch({
|
|
|
237
237
|
stallAfter,
|
|
238
238
|
profile = inherited.SLICC_PROFILE === '1',
|
|
239
239
|
realistic = false,
|
|
240
|
+
persistent = false,
|
|
240
241
|
} = {}) {
|
|
241
242
|
pruning ??= prune();
|
|
242
243
|
await pruning;
|
|
@@ -244,7 +245,7 @@ export async function launch({
|
|
|
244
245
|
const found = await unpacked(extensions);
|
|
245
246
|
const fromExtension = extensionSource(found);
|
|
246
247
|
const files = { ...server, source: (href) => server.source(href) ?? fromExtension(href) };
|
|
247
|
-
const shared = extensions.length > 0;
|
|
248
|
+
const shared = persistent || extensions.length > 0;
|
|
248
249
|
const userData = await mkdtemp(join(tmpdir(), PREFIX));
|
|
249
250
|
const loaded = [...found.values()].map((root) => root.slice(0, -1));
|
|
250
251
|
const dumps = await crashpad();
|
|
@@ -262,8 +263,12 @@ export async function launch({
|
|
|
262
263
|
let crashes = 0;
|
|
263
264
|
let open = 0;
|
|
264
265
|
let closed = false;
|
|
265
|
-
|
|
266
|
+
const visited = new Set();
|
|
267
|
+
cdp.on(({ method, params }) => {
|
|
266
268
|
if (method === CRASHED || method === 'Target.targetCrashed') crashes += 1;
|
|
269
|
+
if (method === 'Target.targetCreated' || method === 'Target.targetInfoChanged') {
|
|
270
|
+
visited.add(params.targetInfo.url);
|
|
271
|
+
}
|
|
267
272
|
});
|
|
268
273
|
const record = recorder(cdp, files, {
|
|
269
274
|
coverage,
|
|
@@ -290,6 +295,27 @@ export async function launch({
|
|
|
290
295
|
await Promise.all(closing.map((sent) => sent.catch(ignore)));
|
|
291
296
|
}
|
|
292
297
|
|
|
298
|
+
async function wipe(pages) {
|
|
299
|
+
const urls = [
|
|
300
|
+
server.url,
|
|
301
|
+
...visited,
|
|
302
|
+
...pages.flatMap(({ responses }) => responses.map(({ url }) => url)),
|
|
303
|
+
];
|
|
304
|
+
const origins = new Set(
|
|
305
|
+
urls
|
|
306
|
+
.map((url) => URL.parse(url))
|
|
307
|
+
.filter((url) => url?.protocol === 'http:' || url?.protocol === 'https:')
|
|
308
|
+
.map(({ origin }) => origin)
|
|
309
|
+
);
|
|
310
|
+
const { sessionId, targetId } = await record.open();
|
|
311
|
+
const clearing = [...origins].map((origin) =>
|
|
312
|
+
cdp.send('Storage.clearDataForOrigin', { origin, storageTypes: 'all' }, sessionId, 120000)
|
|
313
|
+
);
|
|
314
|
+
await Promise.all(clearing).finally(() =>
|
|
315
|
+
cdp.send('Target.closeTarget', { targetId }).catch(ignore)
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
|
|
293
319
|
async function finish(pages, browserContextId, dir, before, mark, seen) {
|
|
294
320
|
const log = stderr.since(mark).map((line) => `${line}\n`);
|
|
295
321
|
await writeFile(new URL('chrome-stderr.log', dir), log.join(''));
|
|
@@ -308,6 +334,7 @@ export async function launch({
|
|
|
308
334
|
? sweep(before)
|
|
309
335
|
: cdp.send('Target.disposeBrowserContext', { browserContextId });
|
|
310
336
|
await bounded(closing.catch(ignore), 'dispose');
|
|
337
|
+
if (persistent) await wipe(pages);
|
|
311
338
|
}
|
|
312
339
|
|
|
313
340
|
return {
|
|
@@ -325,6 +352,7 @@ export async function launch({
|
|
|
325
352
|
const before = new Set(shared ? await tabs() : []);
|
|
326
353
|
record.begin(browserContextId, dir, `${suite}-${slug(t.name)}`);
|
|
327
354
|
server.requests.length = 0;
|
|
355
|
+
visited.clear();
|
|
328
356
|
server.overrides.clear();
|
|
329
357
|
server.overridden.clear();
|
|
330
358
|
const pages = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-ecoverse/slicc-shared-web",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
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",
|