-
Notifications
You must be signed in to change notification settings - Fork 679
/
converter.test.ts
104 lines (94 loc) · 3.13 KB
/
converter.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
import {
Application,
resetReflectionID,
normalizePath,
ProjectReflection,
} from "..";
import * as FS from "fs";
import * as Path from "path";
import { deepStrictEqual as equal, ok } from "assert";
import * as ts from "typescript";
import { TSConfigReader } from "../lib/utils/options";
describe("Converter", function () {
const base = Path.join(__dirname, "converter");
const app = new Application();
app.options.addReader(new TSConfigReader());
app.bootstrap({
logger: "none",
name: "typedoc",
excludeExternals: true,
disableSources: true,
tsconfig: Path.join(base, "tsconfig.json"),
externalPattern: ["**/node_modules/**"],
plugin: [],
});
let program: ts.Program;
it("Compiles", () => {
program = ts.createProgram(app.options.getFileNames(), {
...app.options.getCompilerOptions(),
noEmit: true,
});
const errors = ts.getPreEmitDiagnostics(program);
equal(errors, []);
});
const checks: [string, () => void, () => void][] = [
[
"specs",
() => {
// nop
},
() => {
// nop
},
],
[
"specs-with-lump-categories",
() => app.options.setValue("categorizeByGroup", false),
() => app.options.setValue("categorizeByGroup", true),
],
[
"specs.nodoc",
() => app.options.setValue("excludeNotDocumented", true),
() => app.options.setValue("excludeNotDocumented", false),
],
];
FS.readdirSync(base).forEach(function (directory) {
const path = Path.join(base, directory);
if (!FS.lstatSync(path).isDirectory()) {
return;
}
describe(directory, function () {
for (const [file, before, after] of checks) {
const specsFile = Path.join(path, `${file}.json`);
if (!FS.existsSync(specsFile)) {
continue;
}
let result: ProjectReflection | undefined;
it(`[${file}] converts fixtures`, function () {
before();
resetReflectionID();
result = app.converter.convert(
app.getEntryPointsForPaths([path], [program])
);
after();
ok(
result instanceof ProjectReflection,
"No reflection returned"
);
});
it(`[${file}] matches specs`, function () {
const specs = JSON.parse(
FS.readFileSync(specsFile, "utf-8")
);
let data = JSON.stringify(
app.serializer.toObject(result),
null,
" "
);
data = data.split(normalizePath(base)).join("%BASE%");
equal(JSON.parse(data), specs);
});
}
});
});
});