Skip to content

Port to node-tap #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ nwsnapshot
node-webkit*.zip
credits.html
node-webkit.app
npm-debug.log
npm-debug.log
/.nyc_output
/coverage
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "node-pre-gyp",
"description": "Node.js native addon binary install tool",
"version" : "0.6.37",
"version": "0.6.37",
"keywords": [
"native",
"addon",
Expand Down Expand Up @@ -34,7 +34,8 @@
"devDependencies": {
"aws-sdk": "^2.28.0",
"retire": "^1.2.12",
"jshint": "^2.9.4"
"jshint": "^2.9.4",
"tap": "^10.7.2"
},
"jshintConfig": {
"node": true,
Expand All @@ -44,8 +45,8 @@
"noarg": true
},
"scripts": {
"pretest": "jshint test/build.test.js test/s3_setup.test.js test/versioning.test.js",
"pretest": "jshint test/build.test.js test/s3_setup.test.js test/versioning.test.js lib lib/util scripts bin/node-pre-gyp",
"update-crosswalk": "node scripts/abi_crosswalk.js",
"test": "jshint lib lib/util scripts bin/node-pre-gyp && tape test/*test.js"
"test": "tap test/*test.js -t0 --cov"
}
}
90 changes: 40 additions & 50 deletions test/build.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

var test = require('tape');
var t = require('tap');
var run = require('./run.util.js');
var existsSync = require('fs').existsSync || require('path').existsSync;
var fs = require('fs');
Expand Down Expand Up @@ -32,69 +32,58 @@ var apps = [
}
];


// https://stackoverflow.com/questions/38599457/how-to-write-a-custom-assertion-for-testing-node-or-javascript-with-tape-or-che
test.Test.prototype.stringContains = function(actual, contents, message) {
this._assert(actual.indexOf(contents) > -1, {
message: message || 'should contain '+contents,
operator: 'stringContains',
actual: actual,
expected: contents
});
};

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

// make sure node-gyp options are passed by passing invalid values
// and ensuring the expected errors are returned from node-gyp
test(app.name + ' passes --nodedir down to node-gyp via node-pre-gyp ' + app.args, function(t) {
t.test(app.name + ' passes --nodedir down to node-gyp via node-pre-gyp ' + app.args, function(t) {
run('node-pre-gyp', 'configure', '--nodedir=invalid-value', app, {}, function(err,stdout,stderr) {
t.ok(err,'Expected command to fail');
t.stringContains(stderr,"common.gypi not found");
t.match(stderr,"common.gypi not found");
t.end();
});
});

// NOTE: currently fails with npm v3.x on windows (hench downgrade in appveyor.yml)
test(app.name + ' passes --nodedir down to node-gyp via npm' + app.args, function(t) {
t.test(app.name + ' passes --nodedir down to node-gyp via npm' + app.args, function(t) {
run('npm', 'install', '--build-from-source --nodedir=invalid-value', app, {}, function(err,stdout,stderr) {
t.ok(err, 'Expected command to fail');
t.stringContains(stderr,"common.gypi not found");
t.match(stderr,"common.gypi not found");
t.end();
});
});

// these will not fail on windows because node-gyp falls back to the python launcher instead of erroring out:
// https://github.com/nodejs/node-gyp/blob/c84a54194781410743efe353d18ca7d20fc9d3a3/lib/configure.js#L396-L397
if (process.platform !== 'win32') {
test(app.name + ' passes --python down to node-gyp via node-pre-gyp ' + app.args, function(t) {
t.test(app.name + ' passes --python down to node-gyp via node-pre-gyp ' + app.args, function(t) {
run('node-pre-gyp', 'configure', '--python=invalid-value', app, {}, function(err,stdout,stderr) {
t.ok(err, 'Expected command to fail');
t.stringContains(stderr,"Can't find Python executable");
t.match(stderr,"Can't find Python executable");
t.end();
});
});

test(app.name + ' passes --python down to node-gyp via npm ' + app.args, function(t) {
t.test(app.name + ' passes --python down to node-gyp via npm ' + app.args, function(t) {
run('node-pre-gyp', 'configure', '--build-from-source --python=invalid-value', app, {}, function(err,stdout,stderr) {
t.ok(err, 'Expected command to fail');
t.stringContains(stderr,"Can't find Python executable");
t.match(stderr,"Can't find Python executable");
t.end();
});
});
}
// note: --ensure=false tells node-gyp to attempt to re-download the node headers
// even if they already exist on disk at ~/.node-gyp/{version}
test(app.name + ' passes --dist-url down to node-gyp via node-pre-gyp ' + app.args, function(t) {
t.test(app.name + ' passes --dist-url down to node-gyp via node-pre-gyp ' + app.args, function(t) {
run('node-pre-gyp', 'configure', '--ensure=false --dist-url=invalid-value', app, {}, function(err,stdout,stderr) {
t.ok(err, 'Expected command to fail');
t.end();
});
});

test(app.name + ' passes --dist-url down to node-gyp via npm ' + app.args, function(t) {
t.test(app.name + ' passes --dist-url down to node-gyp via npm ' + app.args, function(t) {
run('npm', 'install', '--build-from-source --ensure=false --dist-url=invalid-value', app, {}, function(err,stdout,stderr) {
t.ok(err, 'Expected command to fail');
t.end();
Expand All @@ -110,30 +99,30 @@ apps.forEach(function(app) {
// to ensure no stale builds. This is needed
// because "node-pre-gyp clean" only removes
// the current target and not alternative builds
test('cleanup of app', function(t) {
t.test('cleanup of app', function(t) {
var binding_directory = path.join(__dirname,app.name,'lib/binding');
if (fs.existsSync(binding_directory)) {
rm.sync(binding_directory);
}
t.end();
});

test(app.name + ' configures ' + app.args, function(t) {
t.test(app.name + ' configures ' + app.args, function(t) {
run('node-pre-gyp', 'configure', '--loglevel=error', app, {}, function(err,stdout,stderr) {
t.ifError(err);
t.end();
});
});

test(app.name + ' configures with unparsed options ' + app.args, function(t) {
t.test(app.name + ' configures with unparsed options ' + app.args, function(t) {
run('node-pre-gyp', 'configure', '--loglevel=info -- -Dfoo=bar', app, {}, function(err,stdout,stderr) {
t.ifError(err);
t.ok(stderr.search(/(gyp info spawn args).*(-Dfoo=bar)/) > -1);
t.end();
});
});

test(app.name + ' builds with unparsed options ' + app.args, function(t) {
t.test(app.name + ' builds with unparsed options ' + app.args, function(t) {
// clean and build as separate steps here because configure only works with -Dfoo=bar
// and build only works with FOO=bar
run('node-pre-gyp', 'clean', '', app, {}, function(err) {
Expand All @@ -144,51 +133,51 @@ apps.forEach(function(app) {
t.ok(stderr.search(/(gyp info spawn args).*(FOO=bar)/) > -1);
if (process.platform !== 'win32') {
if (app.args.indexOf('--debug') > -1) {
t.stringContains(stdout,'Debug/'+app.name+'.node');
t.match(stdout,'Debug/'+app.name+'.node');
} else {
t.stringContains(stdout,'Release/'+app.name+'.node');
t.match(stdout,'Release/'+app.name+'.node');
}
}
t.end();
});
});
});

test(app.name + ' builds ' + app.args, function(t) {
t.test(app.name + ' builds ' + app.args, function(t) {
run('node-pre-gyp', 'rebuild', '--fallback-to-build --loglevel=error', app, {}, function(err,stdout,stderr) {
t.ifError(err);
if (process.platform !== 'win32') {
if (app.args.indexOf('--debug') > -1) {
t.stringContains(stdout,'Debug/'+app.name+'.node');
t.match(stdout,'Debug/'+app.name+'.node');
} else {
t.stringContains(stdout,'Release/'+app.name+'.node');
t.match(stdout,'Release/'+app.name+'.node');
}
}
t.end();
});
});

test(app.name + ' is found ' + app.args, function(t) {
t.test(app.name + ' is found ' + app.args, function(t) {
run('node-pre-gyp', 'reveal', 'module_path --silent', app, {}, function(err,stdout,stderr) {
t.ifError(err);
var module_path = stdout.trim();
t.stringContains(module_path,app.name);
t.match(module_path,app.name);
t.ok(existsSync(module_path),'is valid path to existing binary: '+ module_path);
var module_binary = path.join(module_path,app.name+'.node');
t.ok(existsSync(module_binary));
t.end();
});
});

test(app.name + ' passes tests ' + app.args, function(t) {
t.test(app.name + ' passes tests ' + app.args, function(t) {
run('npm','test','', app, {cwd: path.join(__dirname,app.name)}, function(err,stdout,stderr) {
t.ifError(err);
// we expect app2 to console.log on success
if (app.name == 'app2') {
if (app.args.indexOf('--debug') > -1) {
t.stringContains(stdout,'Loaded Debug build');
t.match(stdout,'Loaded Debug build');
} else {
t.stringContains(stdout,'Loaded Release build');
t.match(stdout,'Loaded Release build');
}
} else {
// we expect some npm output
Expand All @@ -198,81 +187,82 @@ apps.forEach(function(app) {
});
});

test(app.name + ' packages ' + app.args, function(t) {
t.test(app.name + ' packages ' + app.args, function(t) {
run('node-pre-gyp', 'package', '', app, {}, function(err,stdout,stderr) {
t.ifError(err);
t.end();
});
});

test(app.name + ' package is valid ' + app.args, function(t) {
t.test(app.name + ' package is valid ' + app.args, function(t) {
run('node-pre-gyp', 'testpackage', '', app, {}, function(err,stdout,stderr) {
t.ifError(err);
t.end();
});
});

if (process.env.AWS_ACCESS_KEY_ID || process.env.node_pre_gyp_accessKeyId) {
var dopublish = process.env.AWS_ACCESS_KEY_ID || process.env.node_pre_gyp_accessKeyId;
var publishSkip = dopublish ? false : 'no publish access key';
t.test('publishing', { skip: publishSkip }, function(t) {

test(app.name + ' publishes ' + app.args, function(t) {
t.test(app.name + ' publishes ' + app.args, function(t) {
run('node-pre-gyp', 'unpublish publish', '', app, {}, function(err,stdout,stderr) {
t.ifError(err);
t.notEqual(stdout,'');
t.end();
});
});

test(app.name + ' info shows it ' + app.args, function(t) {
t.test(app.name + ' info shows it ' + app.args, function(t) {
run('node-pre-gyp', 'reveal', 'package_name', app, {}, function(err,stdout,stderr) {
t.ifError(err);
var package_name = stdout.trim();
run('node-pre-gyp', 'info', '', app, {}, function(err,stdout,stderr) {
t.ifError(err);
t.stringContains(stdout,package_name);
t.match(stdout,package_name);
t.end();
});
});
});

test(app.name + ' can be uninstalled ' + app.args, function(t) {
t.test(app.name + ' can be uninstalled ' + app.args, function(t) {
run('node-pre-gyp', 'clean', '', app, {}, function(err,stdout,stderr) {
t.ifError(err);
t.notEqual(stdout,'');
t.end();
});
});

test(app.name + ' can be installed via remote ' + app.args, function(t) {
t.test(app.name + ' can be installed via remote ' + app.args, function(t) {
run('npm', 'install', '--fallback-to-build=false', app, {cwd: path.join(__dirname,app.name)}, function(err,stdout,stderr) {
t.ifError(err);
t.notEqual(stdout,'');
t.end();
});
});

test(app.name + ' can be reinstalled via remote ' + app.args, function(t) {
t.test(app.name + ' can be reinstalled via remote ' + app.args, function(t) {
run('npm', 'install', '--update-binary --fallback-to-build=false', app, {cwd: path.join(__dirname,app.name)}, function(err,stdout,stderr) {
t.ifError(err);
t.notEqual(stdout,'');
t.end();
});
});

test(app.name + ' via remote passes tests ' + app.args, function(t) {
t.test(app.name + ' via remote passes tests ' + app.args, function(t) {
run('npm', 'install', '', app, {cwd: path.join(__dirname,app.name)}, function(err,stdout,stderr) {
t.ifError(err);
t.notEqual(stdout,'');
t.end();
});
});

} else {
test.skip(app.name + ' publishes ' + app.args, function() {});
}
t.end();
});

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

test(app.name + ' builds with custom --target ' + app.args, function(t) {
t.test(app.name + ' builds with custom --target ' + app.args, function(t) {
run('node-pre-gyp', 'rebuild', '--loglevel=error --fallback-to-build --target='+process.versions.node, app, {}, function(err,stdout,stderr) {
t.ifError(err);
t.end();
Expand Down
6 changes: 3 additions & 3 deletions test/s3_setup.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use strict";

var s3_setup = require('../lib/util/s3_setup.js');
var test = require('tape');
var t = require('tap');

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

test('should propertly detect s3 bucket and prefix with dots', function(t) {
t.test('should propertly detect s3 bucket and prefix with dots', function(t) {
var url = "https://bucket.with.dots.s3.amazonaws.com/prefix";
var result = {};
s3_setup.detect(url, result);
Expand Down
10 changes: 5 additions & 5 deletions test/target_version.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ var abi_crosswalk = require('../lib/util/abi_crosswalk.json');
var os = require('os');
var fs = require('fs');
var path = require('path');
var test = require('tape');
var t = require('tap');

test('should properly calculate previous version', function(t) {
t.test('should properly calculate previous version', function(t) {
t.equal(getPrevious('1.0.0',abi_crosswalk),undefined);
t.equal(getPrevious('1.0.1',abi_crosswalk),'1.0.0');
t.equal(getPrevious('1.0.2',abi_crosswalk),'1.0.1');
Expand Down Expand Up @@ -38,7 +38,7 @@ Object.keys(abi_crosswalk).forEach(function(v) {
}
});

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

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

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

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