parseTestDeclarations(source: string,filePath: string): Promise<DeclarationScan | null>
Finds every test(...) / module(...) declaration in a test file, with the source line range
each one spans — enough to answer "which test is at line 34?".
The file is run through esbuild.transform first and the output is lexed, then mapped back
through the transform's source map. That removes TS and JSX syntax before lexing, which matters:
JSX text is not JS, so an apostrophe in <p>it's fine</p> would open a string literal in a
source-level lexer and corrupt every brace depth after it. What is left to lex is comments,
strings, template literals and the regex-vs-divide ambiguity.
Returns null when the file cannot be parsed — callers fall back to running the whole file.
// Defined, not invoked: transform spawns esbuild's service, which the doc sandbox cannot run. async function scanFile(source: string) { const scan = await parseTestDeclarations(source, '/proj/cart-test.ts'); return scan?.declarations ?? []; // null degrades to "run the whole file" }
Promise<DeclarationScan | null>