| import { describe, expect, test } from "bun:test" |
| import { join, dirname, resolve } from "node:path" |
| import { existsSync } from "node:fs" |
| import { fileURLToPath } from "node:url" |
|
|
| const dir = dirname(fileURLToPath(import.meta.url)) |
| const root = resolve(dir, "../..") |
|
|
| const html = async (name: string) => Bun.file(join(dir, name)).text() |
|
|
| |
| |
| |
| |
| |
| |
| |
| describe("electron renderer html", () => { |
| for (const name of ["index.html"]) { |
| describe(name, () => { |
| test("script src attributes use relative paths", async () => { |
| const content = await html(name) |
| const srcs = [...content.matchAll(/\bsrc=["']([^"']+)["']/g)].map((m) => m[1]) |
| for (const src of srcs) { |
| expect(src).not.toMatch(/^\/[^/]/) |
| } |
| }) |
|
|
| test("link href attributes use relative paths", async () => { |
| const content = await html(name) |
| const hrefs = [...content.matchAll(/<link[^>]+href=["']([^"']+)["']/g)].map((m) => m[1]) |
| for (const href of hrefs) { |
| expect(href).not.toMatch(/^\/[^/]/) |
| } |
| }) |
|
|
| test("no web manifest link (not applicable in Electron)", async () => { |
| const content = await html(name) |
| expect(content).not.toContain('rel="manifest"') |
| }) |
| }) |
| } |
| }) |
|
|
| |
| |
| |
| |
| |
| |
| describe("electron vite publicDir", () => { |
| test("configured publicDir resolves to a directory with oc-theme-preload.js", async () => { |
| const config = await Bun.file(join(root, "electron.vite.config.ts")).text() |
| const pub = config.match(/publicDir:\s*["']([^"']+)["']/) |
| const rendererRoot = config.match(/root:\s*["']([^"']+)["']/) |
| expect(pub).not.toBeNull() |
| expect(rendererRoot).not.toBeNull() |
| const resolved = resolve(root, rendererRoot![1], pub![1]) |
| expect(existsSync(resolved)).toBe(true) |
| expect(existsSync(join(resolved, "oc-theme-preload.js"))).toBe(true) |
| }) |
| }) |
|
|