mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-10 06:23:43 +08:00
fab3ec9aeb
Add Galaxy web assets and client settings interfaces with their bundled vendor notices. Co-authored-by: Danny <dannyirwin31@yahoo.com> Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu> Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com> Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com> Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com> Co-authored-by: prabhaavp <prabhaav@msu.edu>
56 lines
1.8 KiB
JavaScript
56 lines
1.8 KiB
JavaScript
import assert from "node:assert/strict"
|
|
import { DeviceRestartWatch } from "../web/js/device-restart.js"
|
|
|
|
const flush = async () => { for (let i = 0; i < 12; i++) await Promise.resolve() }
|
|
function fixture({ paused = false } = {}) {
|
|
const timers = new Map(), requests = []
|
|
let nextTimer = 0, reloads = 0
|
|
const watch = new DeviceRestartWatch({ hidden: () => false, paused: () => paused,
|
|
request: () => new Promise((resolve, reject) => requests.push({ resolve, reject })),
|
|
later: fn => { const id = ++nextTimer; timers.set(id, fn); return id },
|
|
cancel: id => timers.delete(id), reload: () => reloads++ })
|
|
return { watch, timers, requests, tick() { const [id, fn] = timers.entries().next().value; timers.delete(id); fn() }, get reloads() { return reloads } }
|
|
}
|
|
|
|
const preview = fixture()
|
|
preview.watch.track(null)
|
|
assert.equal(preview.timers.size, 0)
|
|
|
|
const blip = fixture()
|
|
blip.watch.track("one")
|
|
blip.tick()
|
|
blip.requests[0].reject(new TypeError("offline"))
|
|
await flush()
|
|
blip.tick()
|
|
blip.requests[1].resolve({ schemaVersion: 1, monitor: "local", instance: "one" })
|
|
await flush()
|
|
assert.equal(blip.reloads, 0)
|
|
assert.equal(blip.timers.size, 1)
|
|
|
|
const reboot = fixture()
|
|
reboot.watch.track("one")
|
|
reboot.tick()
|
|
reboot.requests[0].reject(new TypeError("offline"))
|
|
await flush()
|
|
reboot.tick()
|
|
reboot.requests[1].resolve({ schemaVersion: 1, monitor: "local", instance: "two" })
|
|
await flush()
|
|
assert.equal(reboot.reloads, 1)
|
|
assert.equal(reboot.timers.size, 0)
|
|
|
|
const startup = fixture()
|
|
startup.watch.track("one")
|
|
startup.watch.track("two")
|
|
assert.equal(startup.reloads, 1)
|
|
|
|
const woken = fixture()
|
|
woken.watch.track("one")
|
|
woken.watch.wake()
|
|
assert.equal(woken.requests.length, 1)
|
|
assert.equal(woken.timers.size, 0)
|
|
|
|
const updating = fixture({ paused: true })
|
|
updating.watch.track("one")
|
|
updating.watch.track("two")
|
|
assert.equal(updating.reloads, 0)
|