pub const PIN_JS: &str = r#"
const pinCase = (() => {
const now = process.env.RUST_ANYTHING_NOW_MS
if (now === undefined) return () => {}
const nowMs = Number(now)
const seed = Number(process.env.RUST_ANYTHING_SEED ?? 0) >>> 0
let state = seed
const RealDate = Date
class PinnedDate extends RealDate {
constructor(...args) { super(...(args.length === 0 ? [nowMs] : args)) }
static now() { return nowMs }
static [Symbol.hasInstance](v) { return v instanceof RealDate }
}
globalThis.Date = new Proxy(PinnedDate, { apply: () => new RealDate(nowMs).toString() })
Math.random = () => {
state = (state + 0x6D2B79F5) >>> 0
let t = state
t = Math.imul(t ^ (t >>> 15), t | 1)
t ^= t + Math.imul(t ^ (t >>> 7), t | 61)
return ((t ^ (t >>> 14)) >>> 0) / 4294967296
}
return (index) => {
state = seed
process.env.RUST_ANYTHING_CASE = String(index)
}
})()
"#;Expand description
Installed in the Node record and diff scripts after the codec: a fixed Date and a seeded
Math.random when RUST_ANYTHING_NOW_MS is set, and pinCase(index) to call before each case.