import { ReflectOwnKeys, String, TypeError, uncurryThis } from "ext:core/primordials"; import type { TestContext } from "./main.js"; import { dictionary } from "ext:web/idl.js"; export type ParsedStep = { name: string } & ( { ignore: true; fn: ((context: TestContext) => unknown) | undefined } | { ignore: false; fn: (context: TestContext) => unknown } ); export type Definition = ParsedStep & { only: boolean; timeout: number }; export const registry: { definitions: Definition[]; sealed: boolean } = { definitions: [], sealed: false, }; const arrayIncludes = uncurryThis(Array.prototype.includes); export function optionsOf(value: unknown, allowed: string[], kind: string): Record { const options = dictionary(value); for (const key of ReflectOwnKeys(options)) { if (!arrayIncludes(allowed, key)) { throw new TypeError(`Unknown ${kind} option: ${String(key)}`); } } return options; } export function flag(options: Record, name: string, Kind: string): boolean { const value = options[name]; if (value === undefined) return false; if (typeof value !== "boolean") { throw new TypeError(`${Kind} option ${name} must be a boolean`); } return value; }