/
converter2.test.ts
113 lines (98 loc) · 3.15 KB
/
converter2.test.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { ok } from "assert";
import { existsSync } from "fs";
import { join } from "path";
import type { Application } from "../lib/application";
import type { ProjectReflection } from "../lib/models";
import { behaviorTests } from "./behaviorTests";
import { issueTests } from "./issueTests";
import {
getConverter2App,
getConverter2Base,
getConverter2Program,
} from "./programs";
import { TestLogger } from "./TestLogger";
const base = getConverter2Base();
const app = getConverter2App();
function runTest(
title: string,
pre: ((app: Application) => void) | undefined,
entry: string,
check: (project: ProjectReflection, logger: TestLogger) => void
) {
it(title, () => {
const program = getConverter2Program();
const entryPoint = [
join(base, `${entry}.ts`),
join(base, `${entry}.d.ts`),
join(base, `${entry}.tsx`),
join(base, `${entry}.js`),
join(base, entry, "index.ts"),
join(base, entry, "index.js"),
].find(existsSync);
ok(entryPoint, `No entry point found for ${entry}`);
const sourceFile = program.getSourceFile(entryPoint);
ok(sourceFile, `No source file found for ${entryPoint}`);
const snap = app.options.snapshot();
const logger = new TestLogger();
app.logger = logger;
pre?.(app);
app.options.setValue("entryPoints", [entryPoint]);
const project = app.converter.convert([
{
displayName: entry,
program,
sourceFile,
},
]);
app.options.restore(snap);
check(project, logger);
});
}
describe("Converter2", () => {
it("Compiles", () => {
getConverter2Program();
});
for (const [entry, check] of Object.entries(issueTests)) {
if (entry.startsWith("pre")) continue;
const link = `https://github.com/TypeStrong/typedoc/issues/${entry.replace(
/[^\d]/g,
""
)}`;
const name = `Issue ${entry
.replace("_skip", "")
.substring(2)
.padEnd(4)} (${link})`;
if (entry.endsWith("_skip")) {
it.skip(name);
} else {
runTest(
name,
issueTests[`pre${entry.slice(2)}`],
join("issues", entry),
check as (
project: ProjectReflection,
logger: TestLogger
) => void
);
}
}
for (const [entry, check] of Object.entries(behaviorTests)) {
const title = `Handles ${entry
.replace(/([a-z][A-Z])/g, (x) => `${x[0]} ${x[1].toLowerCase()}`)
.replace("_skip", "")}`;
if (entry.startsWith("_")) continue;
if (entry.endsWith("_skip")) {
it.skip(entry);
} else {
runTest(
title,
behaviorTests[`_${entry}`],
join("behavior", entry),
check as (
project: ProjectReflection,
logger: TestLogger
) => void
);
}
}
});