aboutsummaryrefslogtreecommitdiff
path: root/test-suite/_lib.js
diff options
context:
space:
mode:
authorTianren Dong <tianrendong.dtr@gmail.com>2026-05-13 07:29:41 -0400
committerTianren Dong <tianrendong.dtr@gmail.com>2026-05-13 07:29:41 -0400
commit4c54b05dc15b81e449dc8ac53da8bae536fa2798 (patch)
treef81c5e627dcc4dd81d2fe2fd3b2b584e72a73eca /test-suite/_lib.js
parent5951b3fb04aaf53b875afe265a57a944d6fce641 (diff)
pi-chrome: snapshot pre-migration state
Diffstat (limited to 'test-suite/_lib.js')
-rw-r--r--test-suite/_lib.js35
1 files changed, 33 insertions, 2 deletions
diff --git a/test-suite/_lib.js b/test-suite/_lib.js
index 95d6393..f3845e5 100644
--- a/test-suite/_lib.js
+++ b/test-suite/_lib.js
@@ -8,6 +8,8 @@
verdict: "PENDING",
reason: [],
events,
+ details: [],
+ thresholds: {},
};
function render() {
@@ -31,8 +33,9 @@
}
const Challenge = {
- init({ id, instructions }) {
+ init({ id, instructions, thresholds = {} }) {
state.id = id;
+ state.thresholds = parseThresholds(thresholds);
document.title = `[${state.verdict}] ${id}`;
const root = document.body;
const bar = document.createElement("div");
@@ -82,6 +85,20 @@
document.title = `[WARN] ${state.id}`;
persist(); render();
},
+ partial({ name, pass, reason, data }) {
+ state.details.push({ name, pass: !!pass, reason: reason || "", data });
+ log("partial", { name, pass: !!pass, reason, data });
+ persist(); render();
+ return !!pass;
+ },
+ finishPartials() {
+ const failed = state.details.filter(d => !d.pass);
+ if (failed.length) Challenge.fail(...failed.map(d => `${d.name}: ${d.reason || "failed"}`));
+ else Challenge.pass(...state.details.map(d => `${d.name}: ok`));
+ },
+ getThreshold(name, fallback) {
+ return Object.prototype.hasOwnProperty.call(state.thresholds, name) ? state.thresholds[name] : fallback;
+ },
log,
state,
};
@@ -90,10 +107,24 @@
try {
localStorage.setItem(
"pi-chrome-suite:" + state.id,
- JSON.stringify({ id: state.id, verdict: state.verdict, reason: state.reason, events: state.events.slice(-50), ts: Date.now() })
+ JSON.stringify({ id: state.id, verdict: state.verdict, reason: state.reason, details: state.details, thresholds: state.thresholds, events: state.events.slice(-50), ts: Date.now() })
);
} catch {}
}
+ function parseThresholds(defaults) {
+ const out = { ...defaults };
+ try {
+ const qs = new URLSearchParams(location.search);
+ for (const [k, v] of qs) {
+ if (!k.startsWith("threshold.")) continue;
+ const key = k.slice("threshold.".length);
+ const num = Number(v);
+ out[key] = Number.isFinite(num) ? num : v;
+ }
+ } catch {}
+ return out;
+ }
+
window.Challenge = Challenge;
})();