import { expect, test } from "bun:test"; import { HMR_CLIENT_JS } from "../src/runtime.ts"; test("the HMR client script is syntactically valid JavaScript", () => { // HMR_CLIENT_JS is a TypeScript template literal, so an escape like \t or \n // written unescaped is expanded by TypeScript into a real control character. // Inside a regex literal that produces a raw newline, which is a syntax error // that silently kills the whole HMR client in the browser. expect(() => new Function(HMR_CLIENT_JS)).not.toThrow(); }); test("the HMR client contains no raw control characters inside regex literals", () => { const regexLiterals = HMR_CLIENT_JS.match(/\/(?![/*])(?:\.|\[[^\]]*\]|[^/\n\r])+\//g) ?? []; expect(regexLiterals.length).toBeGreaterThan(0); for (const literal of regexLiterals) { expect(literal).not.toMatch(/[\n\r\t]/); } });