@@ -13,69 +13,69 @@ function testHeadlampPlugin() {
13
13
cleanup ( ) ;
14
14
15
15
// Make a package file of headlamp-plugin we can test
16
- run ( 'npm install' ) ;
17
- run ( 'npm run build' ) ;
18
- run ( 'npm pack' ) ;
16
+ run ( 'npm' , [ ' install'] ) ;
17
+ run ( 'npm' , [ ' run' , ' build'] ) ;
18
+ run ( 'npm' , [ ' pack'] ) ;
19
19
20
20
const packedFile = fs
21
21
. readdirSync ( '.' )
22
22
. filter ( file => file . match ( 'kinvolk-headlamp-plugin-.*gz' ) ) [ 0 ] ;
23
23
console . log ( 'Packed headlamp-plugin package file:' , packedFile ) ;
24
24
25
25
// Use "link" to test the repo version of the headlamp-plugin tool.
26
- run ( 'npm link' ) ;
27
- run ( ` node bin/headlamp-plugin.js create ${ PACKAGE_NAME } --link` ) ;
26
+ run ( 'npm' , [ ' link'] ) ;
27
+ run ( ' node' , [ ' bin/headlamp-plugin.js' , ' create' , PACKAGE_NAME , ' --link' ] ) ;
28
28
curDir = join ( '.' , PACKAGE_NAME ) ;
29
- run ( ` npm install ${ join ( '..' , packedFile ) } ` ) ;
29
+ run ( ' npm' , [ ' install' , join ( '..' , packedFile ) ] ) ;
30
30
31
31
// test headlamp-plugin build
32
- run ( ` node ${ join ( '..' , 'bin' , 'headlamp-plugin.js' ) } build` ) ;
32
+ run ( ' node' , [ join ( '..' , 'bin' , 'headlamp-plugin.js' ) , ' build' ] ) ;
33
33
checkFileExists ( join ( PACKAGE_NAME , 'dist' , 'main.js' ) ) ;
34
34
35
35
// test headlamp-plugin build folder
36
36
curDir = '.' ;
37
37
fs . rmSync ( PACKAGE_NAME , { recursive : true } ) ;
38
- run ( ` node bin/headlamp-plugin.js create ${ PACKAGE_NAME } --link` ) ;
38
+ run ( ' node' , [ ' bin/headlamp-plugin.js' , ' create' , PACKAGE_NAME , ' --link' ] ) ;
39
39
curDir = PACKAGE_NAME ;
40
- run ( ` npm install ${ join ( '..' , packedFile ) } ` ) ;
40
+ run ( ' npm' , [ ' install' , join ( '..' , packedFile ) ] ) ;
41
41
curDir = '.' ;
42
- run ( ` node bin/headlamp-plugin.js build ${ PACKAGE_NAME } ` ) ;
42
+ run ( ' node' , [ ' bin/headlamp-plugin.js' , ' build' , PACKAGE_NAME ] ) ;
43
43
checkFileExists ( join ( PACKAGE_NAME , 'dist' , 'main.js' ) ) ;
44
44
45
45
fs . writeFileSync ( join ( PACKAGE_NAME , 'dist' , 'extra.txt' ) , 'All dist/ files will be copied.' ) ;
46
46
47
47
// test extraction works
48
- run ( ` node bin/headlamp-plugin.js extract . .plugins` ) ;
48
+ run ( ' node' , [ ' bin/headlamp-plugin.js' , ' extract' , '.' , ' .plugins' ] ) ;
49
49
checkFileExists ( join ( '.plugins' , PACKAGE_NAME , 'main.js' ) ) ;
50
50
checkFileExists ( join ( '.plugins' , PACKAGE_NAME , 'package.json' ) ) ;
51
51
// make sure extra files in dist/ folder are copied too
52
52
checkFileExists ( join ( '.plugins' , PACKAGE_NAME , 'extra.txt' ) ) ;
53
53
54
54
// test packing works
55
55
const tmpDir = fs . mkdtempSync ( 'headlamp-plugin-test-' ) ;
56
- run ( ` node bin/headlamp-plugin.js package ${ PACKAGE_NAME } ${ tmpDir } ` ) ;
56
+ run ( ' node' , [ ' bin/headlamp-plugin.js' , ' package' , PACKAGE_NAME , tmpDir ] ) ;
57
57
checkFileExists ( join ( tmpDir , `${ PACKAGE_NAME } -0.1.0.tar.gz` ) ) ;
58
58
// extract archive and check files
59
59
const extractionFolder = join ( tmpDir , 'dst' ) ;
60
60
fs . mkdirSync ( extractionFolder , { recursive : true } ) ;
61
- run ( ` tar -xzf ${ join ( tmpDir , `${ PACKAGE_NAME } -0.1.0.tar.gz` ) } -C ${ extractionFolder } ` ) ;
61
+ run ( ' tar' , [ ' -xzf' , join ( tmpDir , `${ PACKAGE_NAME } -0.1.0.tar.gz` ) , '-C' , extractionFolder ] ) ;
62
62
checkFileExists ( join ( extractionFolder , `${ PACKAGE_NAME } ` , 'main.js' ) ) ;
63
63
checkFileExists ( join ( extractionFolder , `${ PACKAGE_NAME } ` , 'package.json' ) ) ;
64
64
fs . rmSync ( tmpDir , { recursive : true } ) ;
65
65
66
66
// test format command and that default code is formatted correctly
67
67
fs . rmSync ( PACKAGE_NAME , { recursive : true } ) ;
68
- run ( ` node bin/headlamp-plugin.js create ${ PACKAGE_NAME } --link` ) ;
68
+ run ( ' node' , [ ' bin/headlamp-plugin.js' , ' create' , PACKAGE_NAME , ' --link' ] ) ;
69
69
curDir = PACKAGE_NAME ;
70
- run ( ` npm install ${ join ( '..' , packedFile ) } ` ) ;
71
- run ( 'npm run format' ) ;
70
+ run ( ' npm' , [ ' install' , join ( '..' , packedFile ) ] ) ;
71
+ run ( 'npm' , [ ' run' , ' format'] ) ;
72
72
73
73
// test lint command and default code is lint free
74
- run ( 'npm run lint' ) ;
75
- run ( 'npm run lint-fix' ) ;
74
+ run ( 'npm' , [ ' run' , ' lint'] ) ;
75
+ run ( 'npm' , [ ' run' , ' lint-fix'] ) ;
76
76
77
77
// test type script error checks
78
- run ( 'npm run tsc' ) ;
78
+ run ( 'npm' , [ ' run' , ' tsc'] ) ;
79
79
80
80
// test the storybook builds
81
81
// TODO: Reenable after storybook is fixed
@@ -90,7 +90,7 @@ function testHeadlampPlugin() {
90
90
filesToRemove . forEach ( file => {
91
91
fs . rmSync ( join ( curDir , file ) , { recursive : true } ) ;
92
92
} ) ;
93
- run ( ` node ${ join ( '..' , 'bin' , 'headlamp-plugin.js' ) } upgrade --skip-package-updates` ) ;
93
+ run ( ' node' , [ join ( '..' , 'bin' , 'headlamp-plugin.js' ) , ' upgrade' , ' --skip-package-updates' ] ) ;
94
94
checkFileExists ( join ( curDir , 'tsconfig.json' ) ) ;
95
95
checkFileExists ( join ( curDir , 'src' , 'headlamp-plugin.d.ts' ) ) ;
96
96
checkFileExists ( join ( curDir , '.vscode' , 'extensions.json' ) ) ;
@@ -110,7 +110,7 @@ function testHeadlampPlugin() {
110
110
fs . writeFileSync ( packageJsonPath , changedJson ) ;
111
111
112
112
// test upgrade updates the package line, and the old version is not in there
113
- run ( ` node ${ join ( '..' , 'bin' , 'headlamp-plugin.js' ) } upgrade` ) ;
113
+ run ( ' node' , [ join ( '..' , 'bin' , 'headlamp-plugin.js' ) , ' upgrade' ] ) ;
114
114
const oldVersion = '0.4.9' ;
115
115
if ( fs . readFileSync ( packageJsonPath , 'utf8' ) . includes ( oldVersion ) ) {
116
116
exit ( `Error: old version still in ${ packageJsonPath } ` ) ;
@@ -143,18 +143,26 @@ function cleanup() {
143
143
. forEach ( folder => fs . rmSync ( folder , { recursive : true } ) ) ;
144
144
}
145
145
146
- function run ( cmd ) {
146
+ function run ( cmd , args ) {
147
147
console . log ( '' ) ;
148
- console . log ( `Running cmd:${ cmd } inside of cwd:${ curDir } abs: "${ resolve ( curDir ) } "` ) ;
148
+ console . log (
149
+ `Running cmd:${ cmd } with args:${ args . join ( ' ' ) } inside of cwd:${ curDir } abs: "${ resolve (
150
+ curDir
151
+ ) } "`
152
+ ) ;
149
153
console . log ( '' ) ;
150
154
try {
151
- child_process . execSync ( cmd , {
155
+ child_process . execFileSync ( cmd , args , {
152
156
stdio : 'inherit' ,
153
157
cwd : curDir ,
154
158
encoding : 'utf8' ,
155
159
} ) ;
156
160
} catch ( e ) {
157
- exit ( `Error: Problem running "${ cmd } " inside of "${ curDir } " abs: "${ resolve ( curDir ) } "` ) ;
161
+ exit (
162
+ `Error: Problem running "${ cmd } ${ args . join ( ' ' ) } " inside of "${ curDir } " abs: "${ resolve (
163
+ curDir
164
+ ) } "`
165
+ ) ;
158
166
}
159
167
}
160
168
function checkFileExists ( fname ) {
0 commit comments