/
typedoc.test.ts
62 lines (52 loc) · 2.24 KB
/
typedoc.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
import { join } from 'path';
import { deepStrictEqual as equal } from 'assert';
import { TypeDocReader } from '../../../../lib/utils/options/readers';
import { Logger, Options, ConsoleLogger } from '../../../../lib/utils';
describe('Options - TypeDocReader', () => {
const options = new Options(new Logger());
options.addDefaultDeclarations();
options.addReader(new TypeDocReader());
function test(name: string, input: string, cb: () => void) {
it(name, () => {
options.reset();
options.setValue('options', input).unwrap();
options.read(new ConsoleLogger());
cb();
});
}
test('Converts src to inputFiles', join(__dirname, 'data/src.json'), () => {
equal(options.getValue('inputFiles'), ['a']);
});
test('Preserves splitting behavior', join(__dirname, 'data/src2.json'), () => {
equal(options.getValue('inputFiles'), ['a']);
});
test('Supports extends', join(__dirname, 'data/extends.json'), () => {
equal(options.getValue('name'), 'extends');
equal(options.getValue('inputFiles'), ['a']);
});
function testError(name: string, file: string) {
it(name, () => {
options.reset();
options.setValue('options', file).unwrap();
const logger = new Logger();
options.read(logger);
equal(logger.hasErrors(), true, 'No error was logged');
});
}
testError('Errors if the file cannot be found', join(__dirname, 'data/non-existent-file.json'));
testError('Errors if the data is invalid', join(__dirname, 'data/invalid.json'));
testError('Errors if any set option errors', join(__dirname, 'data/unknown.json'));
testError('Errors if extends results in a loop', join(__dirname, 'data/circular-extends.json'));
it('Does not error if the option file cannot be found but was not set.', () => {
const options = new class LyingOptions extends Options {
isDefault() {
return true;
}
}(new Logger());
options.addDefaultDeclarations();
options.addReader(new TypeDocReader());
const logger = new Logger();
options.read(logger);
equal(logger.hasErrors(), false);
});
});