-
Notifications
You must be signed in to change notification settings - Fork 678
/
converter.test.ts
81 lines (71 loc) · 2.8 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
import { Application, resetReflectionID, normalizePath, ProjectReflection } from '..';
import * as FS from 'fs';
import * as Path from 'path';
import { deepStrictEqual as equal, ok } from 'assert';
import { ScriptTarget, ModuleKind, JsxEmit } from 'typescript';
import json = require('./converter/class/specs.json');
import { JSONOutput } from '../lib/serialization';
describe('Converter', function() {
const base = Path.join(__dirname, 'converter');
const app = new Application();
app.bootstrap({
mode: 'modules',
logger: 'none',
target: ScriptTarget.ES5,
module: ModuleKind.CommonJS,
experimentalDecorators: true,
jsx: JsxEmit.React,
name: 'typedoc',
ignoreCompilerErrors: true,
excludeExternals: true
});
const checks: [string, () => void, () => void][] = [
['specs', () => { }, () => { }],
['specs.d',
() => app.options.setValue('includeDeclarations', true),
() => app.options.setValue('includeDeclarations', false)
],
['specs-without-exported',
() => app.options.setValue('excludeNotExported', true),
() => app.options.setValue('excludeNotExported', false)
],
['specs-with-lump-categories',
() => app.options.setValue('categorizeByGroup', false),
() => app.options.setValue('categorizeByGroup', true)
]
];
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.convert(app.expandInputFiles([path]));
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);
});
}
});
});
});
describe('Serializer', () => {
it('Type checks', () => {
const typed: JSONOutput.ProjectReflection = json;
equal(json, typed);
});
});