-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmod.js
36 lines (34 loc) · 1.19 KB
/
mod.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { doc } from "https://deno.land/x/[email protected]/mod.ts";
import { resolve, toFileUrl } from "https://deno.land/[email protected]/path/mod.ts";
import { getTests, runExample } from "./lib.js";
/**
* The main entry point. Call it with the path to the file to test, and run it
* using Deno.test().
*
* @param {string} file
* @returns {(t: Deno.TestContext) => Promise<void>}
* @example Deno.test("doctest", doctest("lib.js");
* //=> undefined
*/
export const doctest = (file) => async (t) => {
const url = toFileUrl(resolve(Deno.cwd(), file));
const nodes = await doc(url.href);
await t.step(file, (t) =>
// @ts-ignore that getTests promises resolve with a boolean
Promise.all(
getTests(nodes).map(({ functionName, examples }) =>
// @ts-ignore that t.step promises resolve with a boolean
t.step({
name: functionName,
fn: (t) =>
// @ts-ignore that the runExample promises resolve with a boolean
Promise.all(
examples.map((example) => runExample(t, example, url.href)),
),
sanitizeOps: false,
sanitizeResources: false,
sanitizeExit: false,
})
),
));
};