Skip to content

Commit 66a42ed

Browse files
committed
use tap instead of tape
Also, coverage! Not very good right now, but could be improved over time.
1 parent 5ff8896 commit 66a42ed

File tree

6 files changed

+65
-73
lines changed

6 files changed

+65
-73
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ nwsnapshot
44
node-webkit*.zip
55
credits.html
66
node-webkit.app
7-
npm-debug.log
7+
npm-debug.log
8+
/.nyc_output
9+
/coverage

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "node-pre-gyp",
33
"description": "Node.js native addon binary install tool",
4-
"version" : "0.6.37",
4+
"version": "0.6.37",
55
"keywords": [
66
"native",
77
"addon",
@@ -32,9 +32,9 @@
3232
},
3333
"devDependencies": {
3434
"aws-sdk": "^2.28.0",
35-
"retire": "^1.2.12",
3635
"jshint": "^2.9.4",
37-
"tape": "^4.6.3"
36+
"retire": "^1.2.12",
37+
"tap": "^10.7.2"
3838
},
3939
"jshintConfig": {
4040
"node": true,
@@ -44,8 +44,8 @@
4444
"noarg": true
4545
},
4646
"scripts": {
47-
"pretest": "jshint test/build.test.js test/s3_setup.test.js test/versioning.test.js",
47+
"pretest": "jshint test/build.test.js test/s3_setup.test.js test/versioning.test.js lib lib/util scripts bin/node-pre-gyp",
4848
"update-crosswalk": "node scripts/abi_crosswalk.js",
49-
"test": "jshint lib lib/util scripts bin/node-pre-gyp && tape test/*test.js"
49+
"test": "tap test/*test.js -t0 --cov"
5050
}
5151
}

test/build.test.js

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
var test = require('tape');
3+
var t = require('tap');
44
var run = require('./run.util.js');
55
var existsSync = require('fs').existsSync || require('path').existsSync;
66
var fs = require('fs');
@@ -32,69 +32,58 @@ var apps = [
3232
}
3333
];
3434

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-
4635
// Because the below tests only ensure that flags can be correctly passed to node-gyp is it not
4736
// likely they will behave differently for different apps. So we save time by avoiding running these for each app.
4837
var app = apps[0];
4938

5039
// make sure node-gyp options are passed by passing invalid values
5140
// 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) {
5342
run('node-pre-gyp', 'configure', '--nodedir=invalid-value', app, {}, function(err,stdout,stderr) {
5443
t.ok(err,'Expected command to fail');
55-
t.stringContains(stderr,"common.gypi not found");
44+
t.match(stderr,"common.gypi not found");
5645
t.end();
5746
});
5847
});
5948

6049
// 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) {
6251
run('npm', 'install', '--build-from-source --nodedir=invalid-value', app, {}, function(err,stdout,stderr) {
6352
t.ok(err, 'Expected command to fail');
64-
t.stringContains(stderr,"common.gypi not found");
53+
t.match(stderr,"common.gypi not found");
6554
t.end();
6655
});
6756
});
6857

6958
// these will not fail on windows because node-gyp falls back to the python launcher instead of erroring out:
7059
// https://github.com/nodejs/node-gyp/blob/c84a54194781410743efe353d18ca7d20fc9d3a3/lib/configure.js#L396-L397
7160
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) {
7362
run('node-pre-gyp', 'configure', '--python=invalid-value', app, {}, function(err,stdout,stderr) {
7463
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");
7665
t.end();
7766
});
7867
});
7968

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) {
8170
run('node-pre-gyp', 'configure', '--build-from-source --python=invalid-value', app, {}, function(err,stdout,stderr) {
8271
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");
8473
t.end();
8574
});
8675
});
8776
}
8877
// note: --ensure=false tells node-gyp to attempt to re-download the node headers
8978
// 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) {
9180
run('node-pre-gyp', 'configure', '--ensure=false --dist-url=invalid-value', app, {}, function(err,stdout,stderr) {
9281
t.ok(err, 'Expected command to fail');
9382
t.end();
9483
});
9584
});
9685

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) {
9887
run('npm', 'install', '--build-from-source --ensure=false --dist-url=invalid-value', app, {}, function(err,stdout,stderr) {
9988
t.ok(err, 'Expected command to fail');
10089
t.end();
@@ -110,30 +99,30 @@ apps.forEach(function(app) {
11099
// to ensure no stale builds. This is needed
111100
// because "node-pre-gyp clean" only removes
112101
// the current target and not alternative builds
113-
test('cleanup of app', function(t) {
102+
t.test('cleanup of app', function(t) {
114103
var binding_directory = path.join(__dirname,app.name,'lib/binding');
115104
if (fs.existsSync(binding_directory)) {
116105
rm.sync(binding_directory);
117106
}
118107
t.end();
119108
});
120109

121-
test(app.name + ' configures ' + app.args, function(t) {
110+
t.test(app.name + ' configures ' + app.args, function(t) {
122111
run('node-pre-gyp', 'configure', '--loglevel=error', app, {}, function(err,stdout,stderr) {
123112
t.ifError(err);
124113
t.end();
125114
});
126115
});
127116

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) {
129118
run('node-pre-gyp', 'configure', '--loglevel=info -- -Dfoo=bar', app, {}, function(err,stdout,stderr) {
130119
t.ifError(err);
131120
t.ok(stderr.search(/(gyp info spawn args).*(-Dfoo=bar)/) > -1);
132121
t.end();
133122
});
134123
});
135124

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) {
137126
// clean and build as separate steps here because configure only works with -Dfoo=bar
138127
// and build only works with FOO=bar
139128
run('node-pre-gyp', 'clean', '', app, {}, function(err) {
@@ -144,51 +133,51 @@ apps.forEach(function(app) {
144133
t.ok(stderr.search(/(gyp info spawn args).*(FOO=bar)/) > -1);
145134
if (process.platform !== 'win32') {
146135
if (app.args.indexOf('--debug') > -1) {
147-
t.stringContains(stdout,'Debug/'+app.name+'.node');
136+
t.match(stdout,'Debug/'+app.name+'.node');
148137
} else {
149-
t.stringContains(stdout,'Release/'+app.name+'.node');
138+
t.match(stdout,'Release/'+app.name+'.node');
150139
}
151140
}
152141
t.end();
153142
});
154143
});
155144
});
156145

157-
test(app.name + ' builds ' + app.args, function(t) {
146+
t.test(app.name + ' builds ' + app.args, function(t) {
158147
run('node-pre-gyp', 'rebuild', '--fallback-to-build --loglevel=error', app, {}, function(err,stdout,stderr) {
159148
t.ifError(err);
160149
if (process.platform !== 'win32') {
161150
if (app.args.indexOf('--debug') > -1) {
162-
t.stringContains(stdout,'Debug/'+app.name+'.node');
151+
t.match(stdout,'Debug/'+app.name+'.node');
163152
} else {
164-
t.stringContains(stdout,'Release/'+app.name+'.node');
153+
t.match(stdout,'Release/'+app.name+'.node');
165154
}
166155
}
167156
t.end();
168157
});
169158
});
170159

171-
test(app.name + ' is found ' + app.args, function(t) {
160+
t.test(app.name + ' is found ' + app.args, function(t) {
172161
run('node-pre-gyp', 'reveal', 'module_path --silent', app, {}, function(err,stdout,stderr) {
173162
t.ifError(err);
174163
var module_path = stdout.trim();
175-
t.stringContains(module_path,app.name);
164+
t.match(module_path,app.name);
176165
t.ok(existsSync(module_path),'is valid path to existing binary: '+ module_path);
177166
var module_binary = path.join(module_path,app.name+'.node');
178167
t.ok(existsSync(module_binary));
179168
t.end();
180169
});
181170
});
182171

183-
test(app.name + ' passes tests ' + app.args, function(t) {
172+
t.test(app.name + ' passes tests ' + app.args, function(t) {
184173
run('npm','test','', app, {cwd: path.join(__dirname,app.name)}, function(err,stdout,stderr) {
185174
t.ifError(err);
186175
// we expect app2 to console.log on success
187176
if (app.name == 'app2') {
188177
if (app.args.indexOf('--debug') > -1) {
189-
t.stringContains(stdout,'Loaded Debug build');
178+
t.match(stdout,'Loaded Debug build');
190179
} else {
191-
t.stringContains(stdout,'Loaded Release build');
180+
t.match(stdout,'Loaded Release build');
192181
}
193182
} else {
194183
// we expect some npm output
@@ -198,81 +187,82 @@ apps.forEach(function(app) {
198187
});
199188
});
200189

201-
test(app.name + ' packages ' + app.args, function(t) {
190+
t.test(app.name + ' packages ' + app.args, function(t) {
202191
run('node-pre-gyp', 'package', '', app, {}, function(err,stdout,stderr) {
203192
t.ifError(err);
204193
t.end();
205194
});
206195
});
207196

208-
test(app.name + ' package is valid ' + app.args, function(t) {
197+
t.test(app.name + ' package is valid ' + app.args, function(t) {
209198
run('node-pre-gyp', 'testpackage', '', app, {}, function(err,stdout,stderr) {
210199
t.ifError(err);
211200
t.end();
212201
});
213202
});
214203

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) {
216207

217-
test(app.name + ' publishes ' + app.args, function(t) {
208+
t.test(app.name + ' publishes ' + app.args, function(t) {
218209
run('node-pre-gyp', 'unpublish publish', '', app, {}, function(err,stdout,stderr) {
219210
t.ifError(err);
220211
t.notEqual(stdout,'');
221212
t.end();
222213
});
223214
});
224215

225-
test(app.name + ' info shows it ' + app.args, function(t) {
216+
t.test(app.name + ' info shows it ' + app.args, function(t) {
226217
run('node-pre-gyp', 'reveal', 'package_name', app, {}, function(err,stdout,stderr) {
227218
t.ifError(err);
228219
var package_name = stdout.trim();
229220
run('node-pre-gyp', 'info', '', app, {}, function(err,stdout,stderr) {
230221
t.ifError(err);
231-
t.stringContains(stdout,package_name);
222+
t.match(stdout,package_name);
232223
t.end();
233224
});
234225
});
235226
});
236227

237-
test(app.name + ' can be uninstalled ' + app.args, function(t) {
228+
t.test(app.name + ' can be uninstalled ' + app.args, function(t) {
238229
run('node-pre-gyp', 'clean', '', app, {}, function(err,stdout,stderr) {
239230
t.ifError(err);
240231
t.notEqual(stdout,'');
241232
t.end();
242233
});
243234
});
244235

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) {
246237
run('npm', 'install', '--fallback-to-build=false', app, {cwd: path.join(__dirname,app.name)}, function(err,stdout,stderr) {
247238
t.ifError(err);
248239
t.notEqual(stdout,'');
249240
t.end();
250241
});
251242
});
252243

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) {
254245
run('npm', 'install', '--update-binary --fallback-to-build=false', app, {cwd: path.join(__dirname,app.name)}, function(err,stdout,stderr) {
255246
t.ifError(err);
256247
t.notEqual(stdout,'');
257248
t.end();
258249
});
259250
});
260251

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) {
262253
run('npm', 'install', '', app, {cwd: path.join(__dirname,app.name)}, function(err,stdout,stderr) {
263254
t.ifError(err);
264255
t.notEqual(stdout,'');
265256
t.end();
266257
});
267258
});
268259

269-
} else {
270-
test.skip(app.name + ' publishes ' + app.args, function() {});
271-
}
260+
t.end();
261+
});
272262

273263
// note: the above test will result in a non-runnable binary, so the below test must succeed otherwise all following tests will fail
274264

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) {
276266
run('node-pre-gyp', 'rebuild', '--loglevel=error --fallback-to-build --target='+process.versions.node, app, {}, function(err,stdout,stderr) {
277267
t.ifError(err);
278268
t.end();

test/s3_setup.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"use strict";
22

33
var s3_setup = require('../lib/util/s3_setup.js');
4-
var test = require('tape');
4+
var t = require('tap');
55

6-
test('should propertly detect s3 bucket and prefix', function(t) {
6+
t.test('should propertly detect s3 bucket and prefix', function(t) {
77
var url = "https://node-pre-gyp-tests.s3-us-west-1.amazonaws.com";
88
var result = {};
99
s3_setup.detect(url, result);
@@ -12,7 +12,7 @@ test('should propertly detect s3 bucket and prefix', function(t) {
1212
t.end();
1313
});
1414

15-
test('should propertly detect s3 bucket and prefix with dots', function(t) {
15+
t.test('should propertly detect s3 bucket and prefix with dots', function(t) {
1616
var url = "https://bucket.with.dots.s3.amazonaws.com/prefix";
1717
var result = {};
1818
s3_setup.detect(url, result);

test/target_version.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ var abi_crosswalk = require('../lib/util/abi_crosswalk.json');
66
var os = require('os');
77
var fs = require('fs');
88
var path = require('path');
9-
var test = require('tape');
9+
var t = require('tap');
1010

11-
test('should properly calculate previous version', function(t) {
11+
t.test('should properly calculate previous version', function(t) {
1212
t.equal(getPrevious('1.0.0',abi_crosswalk),undefined);
1313
t.equal(getPrevious('1.0.1',abi_crosswalk),'1.0.0');
1414
t.equal(getPrevious('1.0.2',abi_crosswalk),'1.0.1');
@@ -38,7 +38,7 @@ Object.keys(abi_crosswalk).forEach(function(v) {
3838
}
3939
});
4040

41-
test('every major version should have a unique ABI that is consistent across all major versions', function(t) {
41+
t.test('every major version should have a unique ABI that is consistent across all major versions', function(t) {
4242
var abis = {};
4343
Object.keys(abi_crosswalk).forEach(function(v) {
4444
var major = +v.split('.')[0];
@@ -58,7 +58,7 @@ var found = false;
5858
var current_version = process.versions.node;
5959
var major = +(current_version.split('.')[0]);
6060

61-
test('ensure crosswalk has major version of current node', function(t) {
61+
t.test('ensure crosswalk has major version of current node', function(t) {
6262
found = versions.indexOf(major) > -1;
6363
t.ok(found);
6464
t.end();
@@ -83,7 +83,7 @@ if (previous_patch_version && previous_patch_version !== current_version) {
8383

8484
var app = {'name': 'app1', 'args': '' };
8585

86-
test(app.name + ' builds with custom --target='+previous_patch_version+' that is greater than known version in ABI crosswalk ' + app.args, function(t) {
86+
t.test(app.name + ' builds with custom --target='+previous_patch_version+' that is greater than known version in ABI crosswalk ' + app.args, function(t) {
8787
if (found) {
8888
// construct a mock abi_crosswalk that contains only the previous node version
8989
// and not the current node version

0 commit comments

Comments
 (0)