-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.ts
78 lines (70 loc) · 1.93 KB
/
tests.ts
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import {
assertEquals,
assertObjectMatch,
} from "https://deno.land/[email protected]/testing/asserts.ts";
import { fromFileUrl } from "https://deno.land/[email protected]/path/mod.ts";
import init, { getDocAst } from "../generated/esmdoc.js";
const wasmPath = fromFileUrl(
new URL("../generated/esmdoc_bg.wasm", import.meta.url).href,
);
const wasm = Deno.readFile(wasmPath);
const loadStart = performance.now();
await init(wasm);
console.log("wasm loading time - %dms", performance.now() - loadStart);
function urlSpecifierResolver(specifier: string, referrer: string): string {
return new URL(specifier, referrer).href;
}
async function urlSourceCodeLoader(specifier: string): Promise<string> {
return Deno.readTextFile(fromFileUrl(specifier));
}
Deno.test("typescript no imports", async () => {
const ast = await getDocAst(
new URL("../test_fixtures/javascript/no_imports.js", import.meta.url).href,
urlSpecifierResolver,
urlSourceCodeLoader,
);
assertEquals(ast.length, 1);
assertObjectMatch(ast[0], {
jsDoc: "This is an exported variable.\n@type {number}",
kind: "variable",
location: {
col: 0,
line: 5,
},
name: "foo",
variableDef: {
kind: "const",
tsType: {
kind: "literal",
repr: "42",
},
},
});
});
// Deno.test("typescript with imports", async () => {
// const ast = await getDocAst(
// new URL("../test_fixtures/javascript/with_imports.js", import.meta.url)
// .href,
// urlSpecifierResolver,
// urlSourceCodeLoader,
// );
//
// assertEquals(ast.length, 1);
// assertObjectMatch(ast[0], {
// jsDoc: "This is an exported variable.",
// kind: "variable",
// location: {
// col: 0,
// line: 4,
// },
// name: "foo",
// variableDef: {
// kind: "const",
// tsType: {
// keyword: "number",
// kind: "keyword",
// repr: "number",
// },
// },
// });
// });