11const fs = require ( 'fs' ) ;
2+ const path = require ( 'path' ) ;
23
34console . log ( 'Switching to smoke test directory' ) ;
45process . chdir ( __dirname ) ;
@@ -13,7 +14,7 @@ function generateScriptHeader(isBash) {
1314
1415 // All scripts should start with the same boilerplate disclaimer.
1516 header += `${ cmt } Auto-generated on ${ new Date ( Date . now ( ) ) . toDateString ( ) }
16- ${ cmt } This script WILL EVENTUALLY run a smoke test of the entire plugin by running a series of commands that collectively
17+ ${ cmt } This script performs a smoke test of the entire plugin by running a series of commands that collectively
1718${ cmt } hit a vertical slice of all major features. If they all succeed, then we can reasonably assume that the plugin is
1819${ cmt } approximately stable.
1920${ cmt } DO NOT EDIT THIS SCRIPT DIRECTLY! INSTEAD, MAKE CHANGES IN ./smoke-tests/smoke-test-generator.js AND RERUN THAT
@@ -31,11 +32,87 @@ ${cmt} SCRIPT FROM THE PROJECT ROOT!\n`;
3132}
3233
3334function generateScriptBody ( isBash , delim ) {
35+ const exeName = isBash ? '$EXE_NAME' : '%EXE_NAME%' ;
36+
37+
3438 const commands = [
35- // Log an explainer that since we're in the Alpha stage, we don't have a fully fleshed out smoke test.
36- `echo "At this point in the alpha, the smoke tests are no-ops and it is fine."`
37- ]
39+ // Log a header.
40+ `echo "====== SETUP FOR SMOKE TESTS ======"` ,
41+ // Delete the smoke test result directory if it already exists
42+ `echo "====== Delete a a pre-existing smoke-test-results directory ======"` ,
43+ isBash ? 'rm -rf smoke-test-results' : 'if exist smoke-test-results rmdir /s /q smoke-test-results || exit /b 1' ,
44+ // Create the output directory
45+ `echo "====== Create smoke-test-results directory ======"` ,
46+ isBash ? 'mkdir -p smoke-test-results' : 'if not exist smoke-test-results mkdir smoke-test-results || exit /b 1' ,
47+ `\n` ,
48+ `echo "====== SMOKE TESTS FOR CONFIG COMMAND ======"` ,
49+ // Show the default configuration for all engines
50+ `echo "====== Show default config for all engines ======"` ,
51+ `${ exeName } code-analyzer config` ,
52+ // Show the default configuration for only one engine
53+ `echo "====== Show default config for PMD only ======"` ,
54+ `${ exeName } code-analyzer config -r pmd` ,
55+ // Write the default config for PMD to a file
56+ `echo "====== Write PMD's default config to a file ======"` ,
57+ `${ exeName } code-analyzer config -r pmd -f ${ path . join ( '.' , 'smoke-test-results' , 'pmd-only-config.yml' ) } ` ,
58+ // Show the configuration from the config file we just created
59+ `echo "====== Show configuration from last step's output file ======"` ,
60+ `${ exeName } code-analyzer config -c ${ path . join ( '.' , 'smoke-test-results' , 'pmd-only-config.yml' ) } ` ,
61+ `echo "====== Show configuration from pre-existing config file ======"` ,
62+ `${ exeName } code-analyzer config -c ${ path . join ( '.' , 'smoke-tests' , 'test-data' , 'config-files' , 'existing-config.yml' ) } ` ,
63+ `\n` ,
64+ `echo "====== SMOKE TESTS FOR RULES COMMAND ======"` ,
65+ // List all rules
66+ `echo "====== List all rules ======"` ,
67+ `${ exeName } code-analyzer rules` ,
68+ // List only rules from ESLint
69+ `echo "====== List ESLint rules only ======"` ,
70+ `${ exeName } code-analyzer rules -r eslint` ,
71+ // List only rules from RetireJS
72+ `echo "====== List RetireJS rules only ======"` ,
73+ `${ exeName } code-analyzer rules -r retire-js` ,
74+ // List only rules that are relevant to a provided workspace
75+ `echo "====== List rules relevant to apex-only workspace ======"` ,
76+ `${ exeName } code-analyzer rules -w ${ path . join ( '.' , 'smoke-tests' , 'test-data' , 'workspace-with-apex-files' ) } ` ,
77+ // List only rules that match nonsensical selector (i.e., list no rules)
78+ `echo "====== List rules matching a nonsensical selector (i.e. list no rules) ======"` ,
79+ `${ exeName } code-analyzer rules -r asdfasdfasdf` ,
80+ // List one rule using a config with overrides
81+ `echo "====== List rule overridden in config file ======"` ,
82+ `${ exeName } code-analyzer rules -r no-unsafe-assignment -c ${ path . join ( '.' , 'smoke-tests' , 'test-data' , 'config-files' , 'existing-config.yml' ) } ` ,
83+ '\n' ,
84+ `echo "====== SMOKE TESTS FOR RUN COMMAND ======"` ,
85+ // Run all rules against a folder
86+ `echo "====== Run all rules against a folder ======"` ,
87+ `${ exeName } code-analyzer run -w ${ path . join ( '.' , 'smoke-tests' , 'test-data' , 'workspace-with-mixed-files' ) } ` ,
88+ // Run all rules against a file
89+ `echo "====== Run all rules against a file ======"` ,
90+ `${ exeName } code-analyzer run -w ${ path . join ( '.' , 'smoke-tests' , 'test-data' , 'workspace-with-mixed-files' , 'my-script.ts' ) } ` ,
91+ // Run all rules against a folder and write the output to some files
92+ `echo "====== Run all rules against a folder and write to outfiles ======"` ,
93+ `${ exeName } code-analyzer run -w ${ path . join ( '.' , 'smoke-tests' , 'test-data' , 'workspace-with-apex-files' ) } -f ${ path . join ( '.' , 'smoke-test-results' , 'outfile.json' ) } -f ${ path . join ( '.' , 'smoke-test-results' , 'outfile.html' ) } ` ,
94+ // Run a selection of rules against a folder
95+ `echo "====== Run a selection of rules against a folder ======"` ,
96+ `${ exeName } code-analyzer run -r regex -w ${ path . join ( '.' , 'smoke-tests' , 'test-data' , 'workspace-with-mixed-files' ) } ` ,
97+ // Run rules using a config file with overrides
98+ `echo "====== Run rules using a config file with overrides ======"` ,
99+ `${ exeName } code-analyzer run -c ${ path . join ( '.' , 'smoke-tests' , 'test-data' , 'config-files' , 'existing-config.yml' ) } -w ${ path . join ( '.' , 'smoke-tests' , 'test-data' , 'workspace-with-mixed-files' ) } ` ,
100+ '\n' ,
101+ `echo "====== CONCLUSION ======"` ,
102+ `echo "If you are seeing this message, the smoke tests ran successfully, and all is (approximately) well"`
103+ ] ;
104+
105+ // In a cmd script, you need to prepend plugin commands with "call" in order to make sure that the script continues,
106+ // and you need to postfix it with another snippet to make it actually exist when an error is encountered.
107+ if ( ! isBash ) {
108+ for ( let i = 0 ; i < commands . length ; i ++ ) {
109+ if ( commands [ i ] . startsWith ( exeName ) ) {
110+ commands [ i ] = `call ${ commands [ i ] } || exit /b 1`
111+ }
112+ }
113+ }
38114
115+ // Combine the commands and return the script body.
39116 return commands . join ( '\n' ) ;
40117}
41118
0 commit comments