/
options.test.ts
64 lines (53 loc) · 2.25 KB
/
options.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
import { Logger, Options, ParameterType, ParameterScope } from '../../../lib/utils';
import { deepStrictEqual as equal, throws } from 'assert';
describe('Options', () => {
const logger = new Logger();
const options = new Options(logger);
options.addDefaultDeclarations();
it('Errors on duplicate declarations', () => {
logger.resetErrors();
options.addDeclaration({
name: 'help',
help: '',
type: ParameterType.Boolean
});
equal(logger.hasErrors(), true);
});
it('Does not error if the same declaration is registered twice', () => {
logger.resetErrors();
const declaration = { name: 'test-declaration', help: '' };
options.addDeclaration(declaration);
options.addDeclaration(declaration);
equal(logger.hasErrors(), false);
options.removeDeclarationByName(declaration.name);
});
it('Supports removing a declaration by name', () => {
options.addDeclaration({ name: 'not-an-option', help: '' });
options.removeDeclarationByName('not-an-option');
equal(options.getDeclaration('not-an-option'), undefined);
});
it('Also removes the declaration under its short name', () => {
options.addDeclaration({ name: 'not-an-option', help: '', short: '#' });
options.removeDeclarationByName('not-an-option');
equal(options.getDeclaration('#'), undefined);
});
it('Ignores removal of non-existent declarations', () => {
options.removeDeclarationByName('not-an-option');
equal(options.getDeclaration('not-an-option'), undefined);
});
it('Throws on attempt to get an undeclared option', () => {
throws(() => options.getValue('does-not-exist'));
});
it('Does not allow fetching compiler options through getValue', () => {
throws(() => options.getValue('target'));
});
it('Errors if converting a set value errors', () => {
throws(() => options.setValue('mode', 'nonsense').unwrap());
});
it('Supports directly getting values', () => {
equal(options.getRawValues().toc, []);
});
it('Supports getting by scope', () => {
equal(options.getDeclarationsByScope(ParameterScope.TypeDoc).length !== 0, true);
});
});