1import { dirname, join } from "@std/path";2import { sourceRoot } from "./paths.ts";34function assertEquals(actual: unknown, expected: unknown): void {5 if (actual !== expected) throw new Error(`expected ${expected}, got ${actual}`);6}78Deno.test("sourceRoot treats a directory and its index.html as one logical source", async () => {9 const root = await Deno.makeTempDir();10 try {11 const index = join(root, "index.html");12 await Deno.writeTextFile(index, "<!doctype html>");1314 assertEquals(sourceRoot(root), Deno.realPathSync(root));15 assertEquals(sourceRoot(index), Deno.realPathSync(root));16 } finally {17 await Deno.remove(root, { recursive: true });18 }19});2021Deno.test("sourceRoot preserves another single-file source identity", async () => {22 const root = await Deno.makeTempDir();23 try {24 const page = join(root, "report.html");25 await Deno.writeTextFile(page, "<!doctype html>");26 assertEquals(sourceRoot(page), Deno.realPathSync(page));27 if (sourceRoot(page) === dirname(Deno.realPathSync(page))) {28 throw new Error("non-index file unexpectedly collapsed to its parent directory");29 }30 } finally {31 await Deno.remove(root, { recursive: true });32 }33});