1
1
"use strict" ;
2
2
3
- var test = require ( 'tape ' ) ;
3
+ var t = require ( 'tap ' ) ;
4
4
var run = require ( './run.util.js' ) ;
5
5
var existsSync = require ( 'fs' ) . existsSync || require ( 'path' ) . existsSync ;
6
6
var fs = require ( 'fs' ) ;
@@ -32,69 +32,58 @@ var apps = [
32
32
}
33
33
] ;
34
34
35
-
36
- // https://stackoverflow.com/questions/38599457/how-to-write-a-custom-assertion-for-testing-node-or-javascript-with-tape-or-che
37
- test . Test . prototype . stringContains = function ( actual , contents , message ) {
38
- this . _assert ( actual . indexOf ( contents ) > - 1 , {
39
- message : message || 'should contain ' + contents ,
40
- operator : 'stringContains' ,
41
- actual : actual ,
42
- expected : contents
43
- } ) ;
44
- } ;
45
-
46
35
// Because the below tests only ensure that flags can be correctly passed to node-gyp is it not
47
36
// likely they will behave differently for different apps. So we save time by avoiding running these for each app.
48
37
var app = apps [ 0 ] ;
49
38
50
39
// make sure node-gyp options are passed by passing invalid values
51
40
// and ensuring the expected errors are returned from node-gyp
52
- test ( app . name + ' passes --nodedir down to node-gyp via node-pre-gyp ' + app . args , function ( t ) {
41
+ t . test ( app . name + ' passes --nodedir down to node-gyp via node-pre-gyp ' + app . args , function ( t ) {
53
42
run ( 'node-pre-gyp' , 'configure' , '--nodedir=invalid-value' , app , { } , function ( err , stdout , stderr ) {
54
43
t . ok ( err , 'Expected command to fail' ) ;
55
- t . stringContains ( stderr , "common.gypi not found" ) ;
44
+ t . match ( stderr , "common.gypi not found" ) ;
56
45
t . end ( ) ;
57
46
} ) ;
58
47
} ) ;
59
48
60
49
// NOTE: currently fails with npm v3.x on windows (hench downgrade in appveyor.yml)
61
- test ( app . name + ' passes --nodedir down to node-gyp via npm' + app . args , function ( t ) {
50
+ t . test ( app . name + ' passes --nodedir down to node-gyp via npm' + app . args , function ( t ) {
62
51
run ( 'npm' , 'install' , '--build-from-source --nodedir=invalid-value' , app , { } , function ( err , stdout , stderr ) {
63
52
t . ok ( err , 'Expected command to fail' ) ;
64
- t . stringContains ( stderr , "common.gypi not found" ) ;
53
+ t . match ( stderr , "common.gypi not found" ) ;
65
54
t . end ( ) ;
66
55
} ) ;
67
56
} ) ;
68
57
69
58
// these will not fail on windows because node-gyp falls back to the python launcher instead of erroring out:
70
59
// https://github.com/nodejs/node-gyp/blob/c84a54194781410743efe353d18ca7d20fc9d3a3/lib/configure.js#L396-L397
71
60
if ( process . platform !== 'win32' ) {
72
- test ( app . name + ' passes --python down to node-gyp via node-pre-gyp ' + app . args , function ( t ) {
61
+ t . test ( app . name + ' passes --python down to node-gyp via node-pre-gyp ' + app . args , function ( t ) {
73
62
run ( 'node-pre-gyp' , 'configure' , '--python=invalid-value' , app , { } , function ( err , stdout , stderr ) {
74
63
t . ok ( err , 'Expected command to fail' ) ;
75
- t . stringContains ( stderr , "Can't find Python executable" ) ;
64
+ t . match ( stderr , "Can't find Python executable" ) ;
76
65
t . end ( ) ;
77
66
} ) ;
78
67
} ) ;
79
68
80
- test ( app . name + ' passes --python down to node-gyp via npm ' + app . args , function ( t ) {
69
+ t . test ( app . name + ' passes --python down to node-gyp via npm ' + app . args , function ( t ) {
81
70
run ( 'node-pre-gyp' , 'configure' , '--build-from-source --python=invalid-value' , app , { } , function ( err , stdout , stderr ) {
82
71
t . ok ( err , 'Expected command to fail' ) ;
83
- t . stringContains ( stderr , "Can't find Python executable" ) ;
72
+ t . match ( stderr , "Can't find Python executable" ) ;
84
73
t . end ( ) ;
85
74
} ) ;
86
75
} ) ;
87
76
}
88
77
// note: --ensure=false tells node-gyp to attempt to re-download the node headers
89
78
// even if they already exist on disk at ~/.node-gyp/{version}
90
- test ( app . name + ' passes --dist-url down to node-gyp via node-pre-gyp ' + app . args , function ( t ) {
79
+ t . test ( app . name + ' passes --dist-url down to node-gyp via node-pre-gyp ' + app . args , function ( t ) {
91
80
run ( 'node-pre-gyp' , 'configure' , '--ensure=false --dist-url=invalid-value' , app , { } , function ( err , stdout , stderr ) {
92
81
t . ok ( err , 'Expected command to fail' ) ;
93
82
t . end ( ) ;
94
83
} ) ;
95
84
} ) ;
96
85
97
- test ( app . name + ' passes --dist-url down to node-gyp via npm ' + app . args , function ( t ) {
86
+ t . test ( app . name + ' passes --dist-url down to node-gyp via npm ' + app . args , function ( t ) {
98
87
run ( 'npm' , 'install' , '--build-from-source --ensure=false --dist-url=invalid-value' , app , { } , function ( err , stdout , stderr ) {
99
88
t . ok ( err , 'Expected command to fail' ) ;
100
89
t . end ( ) ;
@@ -110,30 +99,30 @@ apps.forEach(function(app) {
110
99
// to ensure no stale builds. This is needed
111
100
// because "node-pre-gyp clean" only removes
112
101
// the current target and not alternative builds
113
- test ( 'cleanup of app' , function ( t ) {
102
+ t . test ( 'cleanup of app' , function ( t ) {
114
103
var binding_directory = path . join ( __dirname , app . name , 'lib/binding' ) ;
115
104
if ( fs . existsSync ( binding_directory ) ) {
116
105
rm . sync ( binding_directory ) ;
117
106
}
118
107
t . end ( ) ;
119
108
} ) ;
120
109
121
- test ( app . name + ' configures ' + app . args , function ( t ) {
110
+ t . test ( app . name + ' configures ' + app . args , function ( t ) {
122
111
run ( 'node-pre-gyp' , 'configure' , '--loglevel=error' , app , { } , function ( err , stdout , stderr ) {
123
112
t . ifError ( err ) ;
124
113
t . end ( ) ;
125
114
} ) ;
126
115
} ) ;
127
116
128
- test ( app . name + ' configures with unparsed options ' + app . args , function ( t ) {
117
+ t . test ( app . name + ' configures with unparsed options ' + app . args , function ( t ) {
129
118
run ( 'node-pre-gyp' , 'configure' , '--loglevel=info -- -Dfoo=bar' , app , { } , function ( err , stdout , stderr ) {
130
119
t . ifError ( err ) ;
131
120
t . ok ( stderr . search ( / ( g y p i n f o s p a w n a r g s ) .* ( - D f o o = b a r ) / ) > - 1 ) ;
132
121
t . end ( ) ;
133
122
} ) ;
134
123
} ) ;
135
124
136
- test ( app . name + ' builds with unparsed options ' + app . args , function ( t ) {
125
+ t . test ( app . name + ' builds with unparsed options ' + app . args , function ( t ) {
137
126
// clean and build as separate steps here because configure only works with -Dfoo=bar
138
127
// and build only works with FOO=bar
139
128
run ( 'node-pre-gyp' , 'clean' , '' , app , { } , function ( err ) {
@@ -144,51 +133,51 @@ apps.forEach(function(app) {
144
133
t . ok ( stderr . search ( / ( g y p i n f o s p a w n a r g s ) .* ( F O O = b a r ) / ) > - 1 ) ;
145
134
if ( process . platform !== 'win32' ) {
146
135
if ( app . args . indexOf ( '--debug' ) > - 1 ) {
147
- t . stringContains ( stdout , 'Debug/' + app . name + '.node' ) ;
136
+ t . match ( stdout , 'Debug/' + app . name + '.node' ) ;
148
137
} else {
149
- t . stringContains ( stdout , 'Release/' + app . name + '.node' ) ;
138
+ t . match ( stdout , 'Release/' + app . name + '.node' ) ;
150
139
}
151
140
}
152
141
t . end ( ) ;
153
142
} ) ;
154
143
} ) ;
155
144
} ) ;
156
145
157
- test ( app . name + ' builds ' + app . args , function ( t ) {
146
+ t . test ( app . name + ' builds ' + app . args , function ( t ) {
158
147
run ( 'node-pre-gyp' , 'rebuild' , '--fallback-to-build --loglevel=error' , app , { } , function ( err , stdout , stderr ) {
159
148
t . ifError ( err ) ;
160
149
if ( process . platform !== 'win32' ) {
161
150
if ( app . args . indexOf ( '--debug' ) > - 1 ) {
162
- t . stringContains ( stdout , 'Debug/' + app . name + '.node' ) ;
151
+ t . match ( stdout , 'Debug/' + app . name + '.node' ) ;
163
152
} else {
164
- t . stringContains ( stdout , 'Release/' + app . name + '.node' ) ;
153
+ t . match ( stdout , 'Release/' + app . name + '.node' ) ;
165
154
}
166
155
}
167
156
t . end ( ) ;
168
157
} ) ;
169
158
} ) ;
170
159
171
- test ( app . name + ' is found ' + app . args , function ( t ) {
160
+ t . test ( app . name + ' is found ' + app . args , function ( t ) {
172
161
run ( 'node-pre-gyp' , 'reveal' , 'module_path --silent' , app , { } , function ( err , stdout , stderr ) {
173
162
t . ifError ( err ) ;
174
163
var module_path = stdout . trim ( ) ;
175
- t . stringContains ( module_path , app . name ) ;
164
+ t . match ( module_path , app . name ) ;
176
165
t . ok ( existsSync ( module_path ) , 'is valid path to existing binary: ' + module_path ) ;
177
166
var module_binary = path . join ( module_path , app . name + '.node' ) ;
178
167
t . ok ( existsSync ( module_binary ) ) ;
179
168
t . end ( ) ;
180
169
} ) ;
181
170
} ) ;
182
171
183
- test ( app . name + ' passes tests ' + app . args , function ( t ) {
172
+ t . test ( app . name + ' passes tests ' + app . args , function ( t ) {
184
173
run ( 'npm' , 'test' , '' , app , { cwd : path . join ( __dirname , app . name ) } , function ( err , stdout , stderr ) {
185
174
t . ifError ( err ) ;
186
175
// we expect app2 to console.log on success
187
176
if ( app . name == 'app2' ) {
188
177
if ( app . args . indexOf ( '--debug' ) > - 1 ) {
189
- t . stringContains ( stdout , 'Loaded Debug build' ) ;
178
+ t . match ( stdout , 'Loaded Debug build' ) ;
190
179
} else {
191
- t . stringContains ( stdout , 'Loaded Release build' ) ;
180
+ t . match ( stdout , 'Loaded Release build' ) ;
192
181
}
193
182
} else {
194
183
// we expect some npm output
@@ -198,81 +187,82 @@ apps.forEach(function(app) {
198
187
} ) ;
199
188
} ) ;
200
189
201
- test ( app . name + ' packages ' + app . args , function ( t ) {
190
+ t . test ( app . name + ' packages ' + app . args , function ( t ) {
202
191
run ( 'node-pre-gyp' , 'package' , '' , app , { } , function ( err , stdout , stderr ) {
203
192
t . ifError ( err ) ;
204
193
t . end ( ) ;
205
194
} ) ;
206
195
} ) ;
207
196
208
- test ( app . name + ' package is valid ' + app . args , function ( t ) {
197
+ t . test ( app . name + ' package is valid ' + app . args , function ( t ) {
209
198
run ( 'node-pre-gyp' , 'testpackage' , '' , app , { } , function ( err , stdout , stderr ) {
210
199
t . ifError ( err ) ;
211
200
t . end ( ) ;
212
201
} ) ;
213
202
} ) ;
214
203
215
- if ( process . env . AWS_ACCESS_KEY_ID || process . env . node_pre_gyp_accessKeyId ) {
204
+ var dopublish = process . env . AWS_ACCESS_KEY_ID || process . env . node_pre_gyp_accessKeyId ;
205
+ var publishSkip = dopublish ? false : 'no publish access key' ;
206
+ t . test ( 'publishing' , { skip : publishSkip } , function ( t ) {
216
207
217
- test ( app . name + ' publishes ' + app . args , function ( t ) {
208
+ t . test ( app . name + ' publishes ' + app . args , function ( t ) {
218
209
run ( 'node-pre-gyp' , 'unpublish publish' , '' , app , { } , function ( err , stdout , stderr ) {
219
210
t . ifError ( err ) ;
220
211
t . notEqual ( stdout , '' ) ;
221
212
t . end ( ) ;
222
213
} ) ;
223
214
} ) ;
224
215
225
- test ( app . name + ' info shows it ' + app . args , function ( t ) {
216
+ t . test ( app . name + ' info shows it ' + app . args , function ( t ) {
226
217
run ( 'node-pre-gyp' , 'reveal' , 'package_name' , app , { } , function ( err , stdout , stderr ) {
227
218
t . ifError ( err ) ;
228
219
var package_name = stdout . trim ( ) ;
229
220
run ( 'node-pre-gyp' , 'info' , '' , app , { } , function ( err , stdout , stderr ) {
230
221
t . ifError ( err ) ;
231
- t . stringContains ( stdout , package_name ) ;
222
+ t . match ( stdout , package_name ) ;
232
223
t . end ( ) ;
233
224
} ) ;
234
225
} ) ;
235
226
} ) ;
236
227
237
- test ( app . name + ' can be uninstalled ' + app . args , function ( t ) {
228
+ t . test ( app . name + ' can be uninstalled ' + app . args , function ( t ) {
238
229
run ( 'node-pre-gyp' , 'clean' , '' , app , { } , function ( err , stdout , stderr ) {
239
230
t . ifError ( err ) ;
240
231
t . notEqual ( stdout , '' ) ;
241
232
t . end ( ) ;
242
233
} ) ;
243
234
} ) ;
244
235
245
- test ( app . name + ' can be installed via remote ' + app . args , function ( t ) {
236
+ t . test ( app . name + ' can be installed via remote ' + app . args , function ( t ) {
246
237
run ( 'npm' , 'install' , '--fallback-to-build=false' , app , { cwd : path . join ( __dirname , app . name ) } , function ( err , stdout , stderr ) {
247
238
t . ifError ( err ) ;
248
239
t . notEqual ( stdout , '' ) ;
249
240
t . end ( ) ;
250
241
} ) ;
251
242
} ) ;
252
243
253
- test ( app . name + ' can be reinstalled via remote ' + app . args , function ( t ) {
244
+ t . test ( app . name + ' can be reinstalled via remote ' + app . args , function ( t ) {
254
245
run ( 'npm' , 'install' , '--update-binary --fallback-to-build=false' , app , { cwd : path . join ( __dirname , app . name ) } , function ( err , stdout , stderr ) {
255
246
t . ifError ( err ) ;
256
247
t . notEqual ( stdout , '' ) ;
257
248
t . end ( ) ;
258
249
} ) ;
259
250
} ) ;
260
251
261
- test ( app . name + ' via remote passes tests ' + app . args , function ( t ) {
252
+ t . test ( app . name + ' via remote passes tests ' + app . args , function ( t ) {
262
253
run ( 'npm' , 'install' , '' , app , { cwd : path . join ( __dirname , app . name ) } , function ( err , stdout , stderr ) {
263
254
t . ifError ( err ) ;
264
255
t . notEqual ( stdout , '' ) ;
265
256
t . end ( ) ;
266
257
} ) ;
267
258
} ) ;
268
259
269
- } else {
270
- test . skip ( app . name + ' publishes ' + app . args , function ( ) { } ) ;
271
- }
260
+ t . end ( ) ;
261
+ } ) ;
272
262
273
263
// note: the above test will result in a non-runnable binary, so the below test must succeed otherwise all following tests will fail
274
264
275
- test ( app . name + ' builds with custom --target ' + app . args , function ( t ) {
265
+ t . test ( app . name + ' builds with custom --target ' + app . args , function ( t ) {
276
266
run ( 'node-pre-gyp' , 'rebuild' , '--loglevel=error --fallback-to-build --target=' + process . versions . node , app , { } , function ( err , stdout , stderr ) {
277
267
t . ifError ( err ) ;
278
268
t . end ( ) ;
0 commit comments