-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathhelp.test.js
More file actions
309 lines (275 loc) · 14.2 KB
/
help.test.js
File metadata and controls
309 lines (275 loc) · 14.2 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
const chalk = require('chalk');
const { COMMANDS } = require('../../bin/paragon-scripts');
const { helpCommand, findCommandByName } = require('../help');
/* eslint-disable no-console */
console.log = jest.fn();
console.error = jest.fn();
/* eslint-enable no-console */
describe('helpCommand', () => {
beforeEach(() => {
/* eslint-disable no-console */
console.log.mockClear();
console.error.mockClear();
/* eslint-enable no-console */
});
it('displays all commands when no specific command is provided', () => {
helpCommand(COMMANDS, []);
/* eslint-disable no-console */
expect(console.log).toHaveBeenCalledWith(chalk.yellow.bold('Paragon Help'));
expect(console.log).toHaveBeenCalledWith('Available commands:');
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('install-theme'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('build-tokens'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('help'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('version'));
/* eslint-enable no-console */
});
it('displays specific command details when command name is provided', () => {
helpCommand(COMMANDS, ['install-theme']);
/* eslint-disable no-console */
expect(console.log).toHaveBeenCalledWith(chalk.yellow.bold('Paragon Help'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('install-theme'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('The @edx/brand package to install.'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('Installs the specific @edx/brand package'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('theme'));
/* eslint-enable no-console */
});
it('displays error for unknown command', () => {
helpCommand(COMMANDS, ['unknown']);
expect(console.error).toHaveBeenCalledWith(/* eslint-disable-line no-console */
chalk.red.bold('Unknown command. Usage: paragon help <command>.'),
);
});
it('handles commands without parameters or options', () => {
helpCommand(COMMANDS, ['version']);
/* eslint-disable no-console */
expect(console.log).toHaveBeenCalledWith(chalk.yellow.bold('Paragon Help'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('version'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('Displays the current version of Paragon CLI'));
/* eslint-enable no-console */
});
it('handles parameters with choices', () => {
helpCommand(COMMANDS, ['help']);
expect(console.log).toHaveBeenCalledWith(/* eslint-disable-line no-console */
expect.stringContaining(
`${chalk.yellow.bold('command')} ${chalk.grey('[install-theme|build-tokens|replace-variables|build-scss|serve-theme-css], Default: \'\'')}`,
),
);
});
it('handles options with choices', () => {
helpCommand(COMMANDS, ['replace-variables']);
/* eslint-disable no-console */
expect(console.log).toHaveBeenCalledWith(chalk.yellow.bold('Paragon Help'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('replace-variables'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining(
'CLI to replace SCSS variables usages or definitions to CSS variables and vice versa in .scss files.',
));
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(
`${chalk.yellow.bold('-t, --replacementType')} ${chalk.grey('[usage|definition], Default: definition')}`,
),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(
`${chalk.yellow.bold('-d, --direction')} ${chalk.grey('[scss-to-css|css-to-scss], Default: scss-to-css')}`,
),
);
/* eslint-enable no-console */
});
it('handles commands with both parameters and options with choices', () => {
helpCommand(COMMANDS, ['build-scss']);
/* eslint-disable no-console */
expect(console.log).toHaveBeenCalledWith(chalk.yellow.bold('Paragon Help'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('build-scss'));
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('CLI to compile Paragon\'s core and themes SCSS into CSS.'),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(`${chalk.yellow.bold('--corePath')} ${chalk.grey('Default: styles/scss/core/core.scss')}`),
);
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('Path to the theme\'s core SCSS file'));
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(`${chalk.yellow.bold('--themesPath')} ${chalk.grey('Default: styles/css/themes')}`),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('Path to the directory that contains themes\' files'),
);
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('themes/'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('light/'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('dark/'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('some_other_custom_theme/'));
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('where index.css has imported all other CSS files in the theme\'s subdirectory'),
);
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('The script will output'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('You can provide any amount of themes'));
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('light.css, dark.css and some_other_custom_theme.css files'),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('(together with maps and minified versions).'),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('You can provide any amount of themes. Default to paragon\'s themes.'),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(`${chalk.yellow.bold('--outDir')} ${chalk.grey('Default: ./dist')}`),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('Specifies directory where to out resulting CSS files.'),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(`${chalk.yellow.bold('--defaultThemeVariants')} ${chalk.grey('Default: light')}`),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('Specifies which theme variants are marked as defaults in the generated theme-urls.json.'),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('Consuming applications (Open edX micro-frontends) use theme-urls.json'),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('Variants not listed as defaults are still built and'),
);
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('You can provide multiple default theme variants'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('example: `--defaultThemeVariants light dark`'));
/* eslint-enable no-console */
});
it('handles commands with multiple options including list choices', () => {
helpCommand(COMMANDS, ['build-tokens']);
/* eslint-disable no-console */
expect(console.log).toHaveBeenCalledWith(chalk.yellow.bold('Paragon Help'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('build-tokens'));
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('CLI to build Paragon design tokens.'),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(`${chalk.yellow.bold('-s, --source')} ${chalk.grey('Default: \'\'')}`),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(`${chalk.yellow.bold('-t, --themes')} ${chalk.grey('Default: light')}`),
);
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('Can be provided as a comma-separated list'));
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(`${chalk.yellow.bold('-v, --verbose')} ${chalk.grey('Default: false')}`),
);
/* eslint-enable no-console */
});
it('handles replace-variables command with parameters and options', () => {
helpCommand(COMMANDS, ['replace-variables']);
/* eslint-disable no-console */
expect(console.log).toHaveBeenCalledWith(chalk.yellow.bold('Paragon Help'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('replace-variables'));
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(
'CLI to replace SCSS variables usages or definitions to CSS variables and vice versa in .scss files.',
),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(`${chalk.yellow.bold('-p, --filePath')} ${chalk.grey('Default: \'\'')}`),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('Path to the file or directory where to replace variables.'),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(`${chalk.yellow.bold('-s, --source')} ${chalk.grey('Default: \'\'')}`),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('Type of replacement: usage or definition'),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(
`${chalk.yellow.bold('-t, --replacementType')} ${chalk.grey('[usage|definition], Default: definition')}`,
),
);
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('Type of replacement: usage or definition'));
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(
`${chalk.yellow.bold('-d, --direction')} ${chalk.grey('[scss-to-css|css-to-scss], Default: scss-to-css')}`,
),
);
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('Map direction: css-to-scss or scss-to-css'));
/* eslint-enable no-console */
});
it('handles build-tokens command with options', () => {
helpCommand(COMMANDS, ['build-tokens']);
/* eslint-disable no-console */
expect(console.log).toHaveBeenCalledWith(chalk.yellow.bold('Paragon Help'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('build-tokens'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('CLI to build Paragon design tokens.'));
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(`${chalk.yellow.bold('-s, --source')} ${chalk.grey('Default: \'\'')}`),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('Specify the source directory for design tokens.'),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(`${chalk.yellow.bold('-b, --build-dir')} ${chalk.grey('Default: ./build/')}`),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('Specify the build directory for the generated tokens.'),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(`${chalk.yellow.bold('--source-tokens-only')} ${chalk.grey('Default: false')}`),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('Include only source design tokens in the build.'),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(`${chalk.yellow.bold('--output-token-references')} ${chalk.grey('Default: true')}`),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('Include references for tokens with aliases to other tokens in the build output.'),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(`${chalk.yellow.bold('-t, --themes')} ${chalk.grey('Default: light')}`),
);
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('Specify themes to include in the token build.'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('Can be provided as a comma-separated list'));
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(`${chalk.yellow.bold('-v, --verbose')} ${chalk.grey('Default: false')}`),
);
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('Enable verbose logging.'));
/* eslint-enable no-console */
});
it('handles migrate-to-openedx-scope command with parameters', () => {
helpCommand(COMMANDS, ['migrate-to-openedx-scope']);
/* eslint-disable no-console */
expect(console.log).toHaveBeenCalledWith(chalk.yellow.bold('Paragon Help'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('migrate-to-openedx-scope'));
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('CLI for migrate from "@edx/paragon" to "@openedx/paragon".'),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(`${chalk.yellow.bold('path')} ${chalk.grey('Default: None')}`),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(
'Path to the directory where to replace Paragon package name, default to root of the repository',
),
);
/* eslint-enable no-console */
});
it('handles help command with parameters', () => {
helpCommand(COMMANDS, ['help']);
/* eslint-disable no-console */
expect(console.log).toHaveBeenCalledWith(chalk.yellow.bold('Paragon Help'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('help'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('Displays help for available commands.'));
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(
`${chalk.yellow.bold('command')} ${chalk.grey('[install-theme|build-tokens|replace-variables|build-scss|serve-theme-css], Default: \'\'')}`,
),
);
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('Specifies command name.'));
/* eslint-enable no-console */
});
});
describe('findCommandByName', () => {
it('returns command object when command exists', () => {
const result = findCommandByName('help', COMMANDS);
expect(result).toEqual({ help: COMMANDS.help });
});
it('returns null when command does not exist', () => {
const result = findCommandByName('unknown', COMMANDS);
expect(result).toBeNull();
});
});