diff --git a/test/docs/library-examples.test.ts b/test/docs/library-examples.test.ts index 2955d73a..b3a4c483 100644 --- a/test/docs/library-examples.test.ts +++ b/test/docs/library-examples.test.ts @@ -8,10 +8,10 @@ import { describe, expect, test } from "bun:test"; import { spawnSync } from "node:child_process"; -import { existsSync, readFileSync, symlinkSync, writeFileSync } from "node:fs"; +import { readFileSync, symlinkSync, writeFileSync } from "node:fs"; import { join, resolve } from "node:path"; import { ROOT } from "../root.js"; -import { SETTINGS_SCHEMA_PATH, schemaNotBuilt } from "../settings-schema.js"; +import { SETTINGS_SCHEMA_PATH } from "../settings-schema.js"; import { withTempDir } from "../temp-dir.js"; const PAGE = "docs/reference/library.md"; @@ -55,13 +55,9 @@ export function tsFences(markdown: string): Fence[] { * The fences as one module: only the two package paths are rewritten, on the * lines they already occupy, so a program line is a page line by offset alone * and nothing else about a fence is repaired before tsc sees it. The page - * imports each name once, in the first example that uses it. `schema` is where - * the package's schema subpath lands. + * imports each name once, in the first example that uses it. */ -export function examplesProgram( - fences: readonly Fence[], - schema: string, -): { +export function examplesProgram(fences: readonly Fence[]): { text: string; pageLine: (programLine: number) => number; } { @@ -71,7 +67,7 @@ export function examplesProgram( for (const fence of fences) { starts.push(line); const body = fence.body - .replaceAll(`"${PACKAGE}/settings.schema.json"`, JSON.stringify(schema)) + .replaceAll(`"${PACKAGE}/settings.schema.json"`, JSON.stringify(SETTINGS_SCHEMA_PATH)) .replaceAll(`"${PACKAGE}"`, JSON.stringify(ENTRY)); parts.push(body); line += body.split("\n").length; @@ -96,39 +92,15 @@ export function examplesProgram( /** `tsc --pretty false` prints `(,): error TS: `, continuation lines indented. */ const DIAGNOSTIC = /^(.+?)\((\d+),(\d+)\): error (TS\d+): (.*)$/; -/** - * Whether the program imports `module` (a static import, a re-export, a dynamic import, each spelled as the page - * spells it: `from`, or `import` and an optional parenthesis, then the quoted path); a string value naming the path - * is not a dependency. - */ -function importsModule(program: string, module: string): boolean { - const quoted = JSON.stringify(module); - for (let at = program.indexOf(quoted); at !== -1; at = program.indexOf(quoted, at + 1)) { - if (/\b(?:from|import)\s*\(?\s*$/.test(program.slice(0, at))) { - return true; - } - } - return false; -} - /** * Every diagnostic tsc reports for the page's fences, as `