mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-21 05:50:55 +08:00
33 lines
1.3 KiB
JavaScript
33 lines
1.3 KiB
JavaScript
// Exercises the island's os and diagnostics_channel shims differentially:
|
|
// every line must match real Node byte-for-byte. os values bridge to the
|
|
// same runtime answers as the static lowerings; diagnostics_channel is
|
|
// real pub/sub (publish with no subscribers is a no-op, like Node).
|
|
import os, { EOL } from "node:os";
|
|
import dc from "diagnostics_channel";
|
|
|
|
export function report() {
|
|
const lines = [];
|
|
lines.push(`platform=${os.platform()}`);
|
|
lines.push(`arch=${os.arch()}`);
|
|
lines.push(`home=${os.homedir()}`);
|
|
lines.push(`tmp=${os.tmpdir()}`);
|
|
lines.push(`eol=${JSON.stringify(os.EOL)} named=${EOL === os.EOL}`);
|
|
lines.push(`host-ok=${os.hostname().length > 0}`);
|
|
const got = [];
|
|
dc.subscribe("demo", (msg, name) => got.push(`${name}:${msg.n}`));
|
|
const ch = dc.channel("demo");
|
|
lines.push(`has=${ch.hasSubscribers}`);
|
|
ch.publish({ n: 1 });
|
|
dc.channel("demo").publish({ n: 2 });
|
|
lines.push(...got);
|
|
const silent = dc.channel("nobody");
|
|
silent.publish({ n: 3 });
|
|
lines.push(`silent=${silent.hasSubscribers} ${dc.hasSubscribers("nobody")}`);
|
|
const fn = () => {};
|
|
dc.subscribe("once", fn);
|
|
lines.push(`unsub=${dc.unsubscribe("once", fn)} ${dc.unsubscribe("once", fn)}`);
|
|
const tc = dc.tracingChannel("op");
|
|
lines.push(`tc=${tc.hasSubscribers === false}`);
|
|
return lines.join("\n");
|
|
}
|