-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtasksfile.ts
815 lines (752 loc) · 24.5 KB
/
tasksfile.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
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/camelcase */
import { cli, help, sh } from "tasksfile";
import { dedent } from "ts-dedent";
import compareVersions from "compare-versions";
import { ICLIOptions } from "@pawelgalazka/cli";
// Place to store the messages for different commands.
const MESSAGE = {
checkVersion: {
valid: (version: string): string => {
return `Version ${version} in the package.json looks good!"`;
},
error: (localVersion: string, npmVersion: string): string => {
return dedent`
Version ${localVersion} in package.json is not newer than npm
version of ${npmVersion} and will cause Publish job to fail.
You should update version ${localVersion} in package.json
to a version greater than ${npmVersion}
`;
},
},
testChrome: {
error:
"Missing driver path. To set path, run:\n'npx task installTestTools -c'",
},
testFirefox: {
error:
"Missing driver path. To set path, run:\n'npx task installTestTools -f'",
error2:
"Missing binary path. To set path, run:\n'npx task installTestTools -f'",
},
};
// Which selenium tests there are to run
// Note: FIRST ELEMENT in dictionary is the CLASS NAME containing the tests
const TESTS: { [name: string]: string[] } = {
test_about_page: ["TestAboutPage", "test_about_modal"],
test_main_page: [
"TestMainPage",
"test_create_notebook",
"test_left_tabs",
"test_sub_menu",
"test_top_menu",
"test_tutorials",
],
// These tests can be activated once vcs is updated in master
/* test_export_html: [
"TestExportHTML",
"test_export_plot_html_via_button",
"test_export_plot_html_via_nbconvert",
"test_export_plot_html_via_nbconvert_execute"
],*/
// These tests were OBSOLETE and removed, but should be re-implemented
// View previous commits to master if you need to reference them.
/*
test_edit_axis_locators:[],
test_load_a_variable:[],
test_load_variables_popup:[],
test_plots:[]
*/
test_vcdat_panel: [
"TestVcdatPanel",
"test_top_level",
"test_graphics_options",
"test_colormap_options",
"test_template_options",
],
};
const TASK_DATA_PATH = ".taskData";
enum TaskData {
tasksReady,
chromeDriver,
geckoDriver,
firefoxBinary,
condaInstalled,
LENGTH, // Length must be last element in enum
}
enum OSTypes {
Linux,
MacOs,
}
/**
* Returns true if the file exists
* @param fileName The file name to check
*/
async function checkFileExists(fileName: string): Promise<boolean> {
try {
await run(`test -f ${fileName} && echo "TRUE"`);
} catch (error) {
return false;
}
return true;
}
async function getEnvironmentVariable(variableName: string): Promise<string> {
const result: string = await run(`echo $${variableName}`);
return result;
}
/**
* Gets the package.json version number in the local project directory.
*/
async function getLocalPackageVersion(): Promise<string> {
return run(`node -pe "require('./package.json').version"`);
}
/**
* Given a list of options, if all options are undefined, returns undefined
* If ANY option is not undefined, it will return that option's value,
* or a default value if the value of the option is a boolean value.
* @param value The default value to pass if option without value was found.
* @param options The options passed to the shell function.
*/
function getOptionsValue(value: any, ...options: any[]): any {
let option: any;
options.some((opt: any) => {
option = opt;
return opt !== undefined; // Exit loop soon as an option is found
});
if (option) {
return getOptionValue(value, option);
}
return undefined;
}
/**
* Returns the parameter value, providing a default value if parameter was
* undefined or if the parameter was boolean (no value assigned to it).
* @param value The default value to return if parameter has no value.
* @param option The option to check.
*/
function getOptionValue(value: any, option: any): any {
if (option && typeof option !== "boolean") {
return option;
}
return value;
}
async function getOS(): Promise<OSTypes> {
const OS: string = await run("echo $OSTYPE");
switch (OS) {
case "linux-gnu":
return OSTypes.Linux;
}
return OSTypes.MacOs;
}
/**
* Gets the latest published version number of the specified tag
* @param tag The tag to look for. Ex: 'nightly' will return latest nightly
* version number that is published on npm.
*/
async function getPublishedVersion(tag?: string): Promise<string> {
return run(`npm view jupyter-vcdat${tag ? `@${tag}` : ""} version`);
}
/**
* Will get the specified task data value
* @param taskData The data to get
*/
async function getTaskData(taskData: TaskData): Promise<string> {
const idx: number = taskData + 1;
try {
return await run(`sed "${idx}q;d" ${TASK_DATA_PATH}`);
} catch (error) {
return "";
}
}
/**
* Prompts user for input and returns the result as a string.
* @param prompt The message to show user for input.
*/
async function getUserInput(
prompt: string,
charLimit?: number
): Promise<string> {
console.log(prompt);
if (charLimit) {
return run(
`read -e -n ${charLimit} _user_response && echo $_user_response`,
false
);
}
return run(`read -e _user_response && echo $_user_response`, false);
}
/**
* Prompts user for a file path, and will continue until user
* provides a valid path or the user quits.
* @param prompt The prompt to show when requesting path.
* @param quitMsg The message to show if user quits.
* @returns A valid file path, or if user quit, undefined.
*/
async function getValidPath(prompt: string, quitMsg: string): Promise<string> {
let path: string = await getUserInput(`${prompt} ('q' to quit): `);
if (path.toLowerCase() === "q") {
console.log(quitMsg);
return;
}
let valid: boolean = await checkFileExists(path);
while (!valid) {
path = await getUserInput(
`The path was not valid. ${prompt}\n('q' to quit): `
);
if (path.toLowerCase() === "q") {
console.log(quitMsg);
return;
}
valid = await checkFileExists(path);
}
return path;
}
// Template function to convert string array to format with line breaks
function printArrayVertically(strings: any, array: string[]): string {
let result = ``;
array.forEach((element: any) => {
result += `\n${strings[0]}${element}${strings[1]}`;
});
return result.slice(1);
}
/**
* Will run shell command asynchronously, returns trimmed output string.
* @param code The shell command to run
* @param silent Whether the shell output should be silent. Default true.
*/
async function run(code: string, silent = true): Promise<string> {
let output = "";
try {
output = await sh(code, { async: true, silent });
} catch (error) {
throw error;
}
return output ? output.trimRight() : "";
}
/**
* Will set the specified task data equal to a value.
* @param taskData The data to set
* @param value The value to set for the data
*/
async function setTaskData(taskData: TaskData, value: string): Promise<void> {
const idx: number = taskData + 1;
// Run command based on current OS
const OS: OSTypes = await getOS();
if (OS === OSTypes.Linux) {
await run(`sed -i -e '${idx}s#.*#${value}#' ${TASK_DATA_PATH}`);
} else {
await run(`sed -i '' -e '${idx}s#.*#${value}#' ${TASK_DATA_PATH}`);
}
}
/**
* Will run shell command and allow it's output to print to console.
* @param code The shell command to run
* @param silent Whether the shell output should be silent. Default false.
*/
async function shell(code: string, silent = false): Promise<void> {
await sh(code, { async: true, nopipe: true, silent });
}
/**
* Runs the specified selenium tests using the chrome browser and driver
* @param testsToRun An array with the names of the tests to run.
*/
async function testChrome(
tests: {
[groupName: string]: string[];
},
verbose = false,
envReady = false
): Promise<boolean> {
console.log("===============CHROME TESTS BEGIN===============");
let driver = "";
let envSetup: string = dedent`echo $BROWSER_TYPE
echo $BROWSER_MODE`;
if (envReady) {
driver = await getEnvironmentVariable("BROWSER_DRIVER");
console.log(`Driver: ${driver}`);
} else {
driver = await getTaskData(TaskData.chromeDriver);
if (!driver) {
console.error(MESSAGE.testChrome.error);
return false;
}
envSetup = dedent`
export BROWSER_TYPE=chrome
export BROWSER_MODE='--foreground'
export BROWSER_DRIVER=${driver}
`;
}
let testCmds = "";
let testClass = "";
let testNames: string[] = [];
const testGroups: string[] = [];
Object.keys(tests).forEach((testGroup: string) => {
if (tests[testGroup].length > 0) {
testClass = TESTS[testGroup][0];
testNames = tests[testGroup];
testCmds = testCmds.concat(
...testNames.map((testName: string) => {
return ` && nosetests ${
verbose ? "" : "--nologcapture"
} -s tests/${testGroup}.py:${testClass}.${testName}`;
})
);
} else {
testGroups.push(testGroup);
}
});
testCmds = testCmds.concat(
...testGroups.map((testName: string) => {
return ` && python scripts/run_tests.py -H -v 2 tests/${testName}.py`;
})
);
await shell(`${envSetup}${testCmds}`);
return true;
}
/**
* Runs the specified selenium tests using the firefox browser and drivers
* @param testsToRun An array with the names of the tests to run.
*/
async function testFirefox(
tests: {
[groupName: string]: string[];
},
verbose = false,
envReady = false
): Promise<boolean> {
console.log("=============FIREFOX TESTS BEGIN=============");
let driver = "";
let binary = "";
let envSetup: string = dedent`echo $BROWSER_TYPE
echo $BROWSER_MODE`;
if (envReady) {
driver = await getEnvironmentVariable("BROWSER_DRIVER");
console.log(`Driver: ${driver}`);
binary = await getEnvironmentVariable("BROWSER_BINARY");
console.log(`Binary: ${binary}`);
} else {
// If environment is not set, prepare it
driver = await getTaskData(TaskData.geckoDriver);
binary = await getTaskData(TaskData.firefoxBinary);
if (!driver || driver === "undefined") {
console.error(MESSAGE.testFirefox.error);
return false;
}
if (!binary || binary === "undefined") {
console.error(MESSAGE.testFirefox.error2);
return false;
}
envSetup = dedent`
export BROWSER_TYPE=firefox
export BROWSER_MODE='--foreground'
export BROWSER_BINARY=${binary}
export BROWSER_DRIVER=${driver}
`;
}
let testCmds = "";
let testClass = "";
let testNames: string[] = [];
const testGroups: string[] = [];
Object.keys(tests).forEach((testGroup: string) => {
if (tests[testGroup].length > 0) {
testClass = TESTS[testGroup][0];
testNames = tests[testGroup];
testCmds = testCmds.concat(
...testNames.map((testName: string) => {
return ` && nosetests ${
verbose ? "" : "--nologcapture"
} -s tests/${testGroup}.py:${testClass}.${testName}`;
})
);
} else {
testGroups.push(testGroup);
}
});
testCmds = testCmds.concat(
...testGroups.map((testName: string) => {
return ` && python scripts/run_tests.py -H -v 2 tests/${testName}.py`;
})
);
await shell(`${envSetup}${testCmds}`);
return true;
}
/**
* ========================= Exported Tasks =============================
*/
// Task: build
async function build(): Promise<void> {
shell("python scripts/deploy_update.py && npm run build && jlpm run build");
}
// Task: checkVersion
async function checkVersion(): Promise<void> {
try {
const LOCAL_VCDAT_VERSION: string = await getLocalPackageVersion();
const NPM_VCDAT_VERSION: string = await getPublishedVersion("nightly");
if (compareVersions(LOCAL_VCDAT_VERSION, NPM_VCDAT_VERSION) > 0) {
console.log(MESSAGE.checkVersion.valid(LOCAL_VCDAT_VERSION));
} else {
console.error(
MESSAGE.checkVersion.error(LOCAL_VCDAT_VERSION, NPM_VCDAT_VERSION)
);
sh(`exit 1`);
}
} catch (error) {
console.error(error);
}
}
help(
checkVersion,
`Compares package.json version with the version published \
on npm and exits with error if the published version is newer.`,
{
params: [],
}
);
// Task: format
async function format(options: ICLIOptions, arg: string): Promise<void> {
try {
if (!arg) {
await shell("npx prettier --write --check 'src/**/*.{js,ts,tsx}'");
} else {
await shell(`npx prettier --write --check ${arg}`);
}
} catch (error) {
console.error(error);
}
}
help(format, "Format source files using prettier-tslint", {
params: [],
});
// Task : installTestTools
async function installTestTools(options: ICLIOptions): Promise<void> {
const firefox: any = options.f || options.firefox;
const chrome: any = options.c || options.chrome;
const CONDA_ENV: string = await run(`echo $CONDA_DEFAULT_ENV`);
const CANCEL_PROMPT = "Installation cancelled.";
const CHROME_DRIVER = "Please enter path to Chrome selenium driver";
const GECKO_DRIVER = "Please enter path to Firefox selenium driver";
const GECKO_EXE = "Please enter path to the Firefox executable";
if (CONDA_ENV) {
if (chrome || firefox) {
if (chrome) {
const chrmPath: string = await getValidPath(
CHROME_DRIVER,
CANCEL_PROMPT
);
if (chrmPath) {
await setTaskData(TaskData.chromeDriver, chrmPath);
} else {
return;
}
}
if (firefox) {
const geckoPath: string = await getValidPath(
GECKO_DRIVER,
CANCEL_PROMPT
);
if (geckoPath) {
await setTaskData(TaskData.geckoDriver, geckoPath);
} else {
return;
}
const firefoxBin: string = await getValidPath(GECKO_EXE, CANCEL_PROMPT);
if (firefoxBin) {
await setTaskData(TaskData.firefoxBinary, firefoxBin);
} else {
return;
}
}
const condaInstalled: boolean =
(await getTaskData(TaskData.condaInstalled)) === "true";
if (!condaInstalled) {
console.log("Installing conda dependencies...");
await shell(
`conda install -c cdat/label/v82 -c cdat/label/nightly testsrunner cdat_info <<< 'yes' && \
pip install selenium && pip install pyvirtualdisplay`
);
await setTaskData(TaskData.condaInstalled, "true");
} else {
console.log("Conda dependencies already installed.");
}
} else {
console.log("Installing conda dependencies...");
await shell(
`conda install -c cdat/label/v82 -c cdat/label/nightly testsrunner cdat_info <<< 'yes' && \
pip install selenium && pip install pyvirtualdisplay`
);
await setTaskData(TaskData.condaInstalled, "true");
}
} else {
console.error(
"No conda environment active. \
Activate conda environment containing the jupyter-vcdat installation to test."
);
return;
}
}
help(
installTestTools,
dedent`Installs dependencies and sets driver for running Selenium tests locally.
Note: If no browser is specified (see below), only conda packages will be installed.`,
{
options: {
firefox: "<optional> Set firefox driver for tests.",
f: "<optional> Same as above.",
chrome: "<optional> Set chrome driver for tests.",
c: "<optional> Same as above.",
},
examples: dedent`
Full install including chrome and firefox settings:
npx task installTestTools -c -f
Install with just chrome settings:
npx task installTestTools -c
Install or update conda dependencies only:
npx task installTestTools
`,
}
);
// Task: lint
async function lint(options: ICLIOptions): Promise<void> {
try {
let command = "";
const tsOpts: string = options.fix ? "--fix" : "";
const pyOpts = `--show-source --statistics \
--ignore=F999,F405,E121,E123,E126,E226,E24,E402,E704,W504 \
--max-line-length=120`;
const tsFile: string = getOptionsValue(
"'src/**/*.{ts,tsx}'",
options.t,
options.tsfile
);
const pyFile: string = getOptionsValue("*.py", options.p, options.pyfile);
await checkVersion();
if (tsFile && pyFile) {
console.log(`Linting Typescript files and Python files...`);
command = `npx eslint ${tsOpts} ${tsFile}\nflake8 ${pyOpts} ${pyFile}`;
} else if (tsFile) {
console.log("Linting Typescript files...");
command = `npx eslint ${tsOpts} ${tsFile}`;
} else if (pyFile) {
console.log("Linting Python files...");
command = `flake8 ${pyOpts} ${pyFile}`;
} else {
console.log("Linting all Typescript and Python source files...");
command = `npx eslint ${tsOpts} 'src/**/*.{ts,tsx}'\nflake8 ${pyOpts} *.py`;
}
await shell(`${command}`);
console.log("Done!");
} catch (error) {
console.error(error);
}
}
help(lint, `Performs linting operations on source files.`, {
params: [],
options: {
fix: "<optional> Apply automatic fixes when possible during linting.",
tsfile: "<optional> Specific file to lint. Default: All source files.",
t: "<optional> Same as above.",
pyfile: "<optional> Perform linting of Python source files with flake8.",
p: "<optional> Same as above.",
},
examples: dedent`
To lint and fix specific typescript file:
npx task lint --fix -t=myfile.ts
To run linting on all python project files:
npx task lint -p
To run linting on specific python file:
npx task lint -p=my_script.py
To run linting and fixing on all typescript and python files (default):
npx task lint --fix -p -t OR npx task lint
To run lint on specific typescript and specific python file:
npx task lint -t=myFile.ts -p=anotherFile.py
`,
});
// Task: test
async function test(options: ICLIOptions, ...tests: string[]): Promise<void> {
const firefox: string = getOptionsValue(true, options.f, options.firefox);
const chrome: string = getOptionsValue(true, options.c, options.chrome);
const verbose: any = options.v || options.verbose;
const envReady: any = options.r || options.ready;
const mainTests: string[] = Object.keys(TESTS);
const testsToRun: string[] = tests.length > 0 ? tests : mainTests;
let error = false;
// Print out list of tests if list option set
if (options.l || options.list) {
if (tests.length < 1) {
console.log(
`Available Tests:\n\n${printArrayVertically` ${mainTests}`}\n`
);
} else {
testsToRun.forEach((testName: string) => {
if (TESTS[testName]) {
console.log(
`${TESTS[testName][0]}:\n\n${printArrayVertically` ${TESTS[
testName
].slice(1)}`}\n`
);
} else {
console.error(`\nError: ${testName} is not a test group.`);
}
});
}
return;
}
const testData: { [testGroup: string]: string[] } = {};
testsToRun.forEach((testName: string) => {
if (TESTS[testName]) {
// Test is a testGroup, process based on whether verbose or not
if (verbose) {
// This calls a one line command for the group
testData[testName] = [];
} else {
// This will call a nosetest command for each test in the group
// that way the --nologcapture option can be used to ignore log output
testData[testName] = TESTS[testName].slice(1);
}
} else {
let testFound = false;
let testNames: string[] = [];
Object.keys(TESTS).forEach((testGroup: string) => {
testNames = TESTS[testGroup].slice(1);
if (testNames.includes(testName)) {
testFound = true;
if (testData[testGroup]) {
testData[testGroup].push(testName);
} else {
testData[testGroup] = [testName];
}
}
});
if (!testFound) {
// Return error if test not found
console.error(`ARGUMENT ERROR: Unrecognized test: ${testName}.`);
error = true;
}
}
});
if (error) {
return;
}
if (chrome !== firefox) {
if (firefox) {
console.log("Running tests for Firefox...");
if (await testFirefox(testData, verbose, envReady)) {
console.log("FIREFOX TESTS COMPLETE!!");
}
}
if (chrome) {
console.log("Running tests for Chrome...");
if (await testChrome(testData, verbose, envReady)) {
console.log("CHROME TESTS COMPLETE!!");
}
}
} else {
console.log("Running tests for Chrome and Firefox...");
if (
(await testFirefox(testData, verbose, envReady)) &&
(await testChrome(testData, verbose, envReady))
) {
console.log("FIREFOX AND CHROME TESTS COMPLETE!!");
}
}
}
help(
test,
`Runs Selenium automated tests locally. \
If no tests are specified, all available tests will be run. \
If no browser options are specified, both browsers will be used. \
NOTE: You need to have a JupyterLab instance running with no open notebooks \
or running kernels before you start the tests. Otherwise tests may fail.`,
{
params: ["tests"],
"Available tests": printArrayVertically` ${Object.keys(TESTS)}`,
options: {
firefox: "<optional> Run tests using firefox browser.",
f: "<optional> Same as above.",
chrome: "<optional> Run tests using chrome browser.",
c: "<optional> Same as above.",
list: "<optional> Prints list of available test groups or sub tests.",
l: "<optional> Same as above.",
verbose: "<optional> Run nose tests with logging enabled.",
v: "<optional> Same as above.",
ready:
"<optional> This indicates that installation and environment \
variables are ready to go. Use when running tests in an environment that \
is already set, such as in circleci.",
r: "<optional> Same as above",
},
examples: dedent`
This will print out all available test groups:
npx task test -l
This will print out available tests for 'test_locators' test group
npx task test -l test_locators
This will print out available tests for 'test_locators' and 'test_plot_locators' test groups
npx task test -l test_locators test_plot_locators
This will run all test groups in both chrome and firefox:
npx task test
--OR--
npx task test -f -c
This will run specific test group(s) in chrome and firefox:
npx task test <test_group> <test_group2> ...
--OR--
npx task test -c -f <test_group> <test_group2> ...
This will run all test groups in chrome only:
npx task test -c
This will run specific test group in firefox only:
npx task test -f <specific_test_group>
This will run specific test and test group in chrome only:
npx task test -c <specific_test> <specific_test_group>
`,
}
);
// Task: updateTags
function updateTags(options: ICLIOptions): void {
const log = getOptionValue("tests/component_tags.txt", options.log);
const source = getOptionValue("src/**/*.tsx", options.source);
const suffix = getOptionValue("vcdat", options.suffix);
try {
sh(
`python scripts/update_tags.py --log ${log} --source ${source} --suffix ${suffix}`,
{
silent: true,
async: false,
}
);
} catch (error) {
console.error(error);
}
}
help(updateTags, "Will find and update all className tags in source files.", {
options: {
log: `Specify the path where to save the log containing tag names,
values and thier locations. Default: "tests/component_tags.txt"`,
source: `The path of the file or files to update. Default: "src/**/*.tsx"`,
suffix: dedent`The string value to attach to the end of the tags.
Ex: --suffix='-1234' changes 'tagName' to 'tagName_1234'. Default: "vcdat"
Note: If you change this, make sure all classNames are updated in test suite.`,
},
examples: dedent`
Use the following example for adding and updating tags to components:
Tag used in file:
<component id={/* tag<component>*/ "oldComponentID" } />
Command to update:
npx task updateTags --suffix=1234
result:
<component id={/* tag<component>*/ "component_1234"
Examples that show the syntax for tags (id or class) to components:
<component id={/* tag<nameForTag>*/ "oldID" } />
---> <component id={/* tag<nameForTag>*/ "nameForTag_suffix" }
<component className={/* tag<newNameForTag> */ "oldClassName" } />
---> <component className={/* tag<newNameForTag> */ "newNameForTag_suffix" } />
<component className={/* tag<otherClass newInsertClass>*/ "otherClass oldClass" } />
---> <component className={/* tag<otherClass newInsertClass>*/ "otherClass newInsertClass" } />`,
});
cli({
build,
checkVersion,
format,
installTestTools,
lint,
test,
updateTags,
});