Files
faunosteo/packages/anatomy/tests/helpers.ts
T

37 lines
1.1 KiB
TypeScript

import { readFile } from 'node:fs/promises'
import { fileURLToPath } from 'node:url'
import { join } from 'node:path'
import {
EQUINE_SOURCE_PATHS,
importEquineLegacy,
readEquineSources,
type EquineLegacyInput,
type ImportResult,
} from '../src'
import type { LegacyCatalog } from '../src/legacy/catalog'
/** Tests run on the real legacy sources, never on copies. */
export const REPO_ROOT = fileURLToPath(new URL('../../../', import.meta.url))
export function loadInput(): Promise<EquineLegacyInput> {
return readEquineSources(REPO_ROOT)
}
export async function runImport(): Promise<ImportResult> {
return importEquineLegacy(await loadInput())
}
export async function loadCatalog(): Promise<LegacyCatalog> {
const text = await readFile(
join(REPO_ROOT, EQUINE_SOURCE_PATHS.catalog),
'utf8',
)
return JSON.parse(text) as LegacyCatalog
}
export async function legacyAnnoIds(path: string): Promise<string[]> {
const text = await readFile(join(REPO_ROOT, path), 'utf8')
const ids = [...text.matchAll(/data-anno-id="([^"]+)"/g)].map((m) => m[1]!)
return [...new Set(ids)]
}