/
schematic.option.spec.ts
117 lines (109 loc) 路 2.8 KB
/
schematic.option.spec.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
114
115
116
117
import { SchematicOption } from '../../../lib/schematics';
interface TestOption {
input: string;
expected: string;
}
interface TestFlag {
input: boolean;
}
type TestSuite = {
description: string;
option: string;
} & (TestOption | TestFlag);
function isFlagTest(test: any): test is TestFlag {
return typeof test.expected === 'undefined';
}
describe('Schematic Option', () => {
const tests: TestSuite[] = [
{
description: 'should manage string option name',
option: 'name',
input: 'my-app',
expected: 'my-app',
},
{
description: 'should manage spaced string option value name',
option: 'name',
input: 'my app',
expected: 'my-app',
},
{
description: 'should manage camelcased string option value name',
option: 'name',
input: 'myApp',
expected: 'my-app',
},
{
description: 'should manage classified string option value name',
option: 'name',
input: 'MyApp',
expected: 'my-app',
},
{
description: 'should manage parenthesis string option value name',
option: 'name',
input: 'my-(app)',
expected: 'my-\\(app\\)',
},
{
description: 'should manage brackets string option value name',
option: 'name',
input: 'my-[app]',
expected: 'my-\\[app\\]',
},
{
description: 'should manage description',
option: 'description',
input: 'My super app',
expected: '"My super app"',
},
{
description: 'should manage author with special chars',
option: 'author',
input: 'name <name@example.com>',
expected: '"name <name@example.com>"',
},
{
description: 'should use "strict" mode',
option: 'strict',
input: true,
},
{
description: 'should not use "strict" mode',
option: 'strict',
input: false,
},
{
description: 'should manage version',
option: 'version',
input: '1.0.0',
expected: '1.0.0',
},
{
description: 'should manage version',
option: 'path',
input: 'path/to/generate',
expected: 'path/to/generate',
},
];
tests.forEach((test) => {
it(test.description, () => {
const option = new SchematicOption(test.option, test.input);
if (isFlagTest(test)) {
if (test.input) {
expect(option.toCommandString()).toEqual(`--${test.option}`);
} else {
expect(option.toCommandString()).toEqual(`--no-${test.option}`);
}
} else {
expect(option.toCommandString()).toEqual(
`--${test.option}=${test.expected}`,
);
}
});
});
it('should should manage boolean option', () => {
const option = new SchematicOption('dry-run', false);
expect(option.toCommandString()).toEqual('--no-dry-run');
});
});