-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Expand file tree
/
Copy pathhelp-output.ts
More file actions
122 lines (119 loc) · 3.31 KB
/
help-output.ts
File metadata and controls
122 lines (119 loc) · 3.31 KB
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
118
119
120
121
122
import assert from 'node:assert/strict';
import { join } from 'node:path';
import { createDir, writeMultipleFiles } from '../../utils/fs';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
export default function () {
// setup temp collection
const genRoot = join('node_modules/fake-schematics/');
return (
Promise.resolve()
.then(() => createDir(genRoot))
.then(() =>
writeMultipleFiles({
[join(genRoot, 'package.json')]: `
{
"schematics": "./collection.json"
}`,
[join(genRoot, 'collection.json')]: `
{
"schematics": {
"fake": {
"factory": "./fake",
"description": "Fake schematic",
"schema": "./fake-schema.json"
},
}
}`,
[join(genRoot, 'fake-schema.json')]: `
{
"$id": "FakeSchema",
"title": "Fake Schema",
"type": "object",
"required": ["a"],
"properties": {
"b": {
"type": "string",
"description": "b.",
"$default": {
"$source": "argv",
"index": 1
}
},
"a": {
"type": "string",
"description": "a.",
"$default": {
"$source": "argv",
"index": 0
}
},
"optC": {
"type": "string",
"description": "optC"
},
"optA": {
"type": "string",
"description": "optA"
},
"optB": {
"type": "string",
"description": "optB"
}
}
}`,
[join(genRoot, 'fake.js')]: `
function def(options) {
return (host, context) => {
return host;
};
}
exports.default = def;
`,
}),
)
.then(() => ng('generate', 'fake-schematics:fake', '--help'))
.then(({ stdout }) => {
assert.match(stdout, /ng generate fake-schematics:fake <a> \[b\]/);
assert.match(stdout, /opt-a[\s\S]*opt-b[\s\S]*opt-c/);
})
// set up default collection.
.then(() =>
updateJsonFile('angular.json', (json) => {
json.cli = json.cli || ({} as any);
json.cli.schematicCollections = ['fake-schematics'];
}),
)
.then(() => ng('generate', 'fake', '--help'))
// verify same output
.then(({ stdout }) => {
assert.match(stdout, /ng generate fake <a> \[b\]/);
assert.match(stdout, /opt-a[\s\S]*opt-b[\s\S]*opt-c/);
})
// should print all the available schematics in a collection
// when a collection has more than 1 schematic
.then(() =>
writeMultipleFiles({
[join(genRoot, 'collection.json')]: `
{
"schematics": {
"fake": {
"factory": "./fake",
"description": "Fake schematic",
"schema": "./fake-schema.json"
},
"fake-two": {
"factory": "./fake",
"description": "Fake schematic",
"schema": "./fake-schema.json"
},
}
}`,
}),
)
.then(() => ng('generate', '--help'))
.then(({ stdout }) => {
assert.match(stdout, /fake[\s\S]*fake-two/);
})
);
}