diff --git a/package.json b/package.json index a152509862..30e55d6ceb 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,9 @@ "node": ">= 0.8.0" }, "devDependencies": { - "tape": "~4.2.0" + "tape": "~4.2.0", + "bindings": "~1.2.1", + "nan": "^2.0.0" }, "scripts": { "test": "tape test/test-*" diff --git a/test/node_modules/hello_world/binding.gyp b/test/node_modules/hello_world/binding.gyp new file mode 100644 index 0000000000..75ca71e090 --- /dev/null +++ b/test/node_modules/hello_world/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "hello", + "sources": [ "hello.cc" ], + "include_dirs": [ + " + +void Method(const Nan::FunctionCallbackInfo& info) { + info.GetReturnValue().Set(Nan::New("world").ToLocalChecked()); +} + +void Init(v8::Local exports) { + exports->Set(Nan::New("hello").ToLocalChecked(), + Nan::New(Method)->GetFunction()); +} + +NODE_MODULE(hello, Init) diff --git a/test/node_modules/hello_world/hello.js b/test/node_modules/hello_world/hello.js new file mode 100644 index 0000000000..2fd10718db --- /dev/null +++ b/test/node_modules/hello_world/hello.js @@ -0,0 +1,3 @@ +'use strict' +var addon = require('bindings')('hello'); +exports.hello = function() { return addon.hello() } diff --git a/test/node_modules/hello_world/package.json b/test/node_modules/hello_world/package.json new file mode 100644 index 0000000000..b09778c334 --- /dev/null +++ b/test/node_modules/hello_world/package.json @@ -0,0 +1,15 @@ +{ + "name": "hello_world", + "version": "0.0.0", + "description": "Node.js Addons Example #1", + "main": "hello.js", + "private": true, + "dependencies": { + "bindings": "~1.2.1", + "nan": "^2.0.0" + }, + "scripts": { + "test": "node hello.js" + }, + "gypfile": true +} diff --git a/test/test-addon.js b/test/test-addon.js new file mode 100644 index 0000000000..c2a71f4498 --- /dev/null +++ b/test/test-addon.js @@ -0,0 +1,28 @@ +'use strict' + +var test = require('tape') +var execFile = require('child_process').execFile +var path = require('path') +var addonPath = path.resolve(__dirname, 'node_modules', 'hello_world') +var nodeGyp = path.resolve(__dirname, '..', 'bin', 'node-gyp.js') + +test('build simple addon', function (t) { + t.plan(3) + + // Set the loglevel otherwise the output disappears when run via 'npm test' + var cmd = [nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose'] + var proc = execFile(process.execPath, cmd, function (err, stdout, stderr) { + var logLines = stderr.toString().trim().split(/\r?\n/) + var lastLine = logLines[logLines.length-1] + t.strictEqual(err, null) + t.strictEqual(lastLine, 'gyp info ok', 'should end in ok') + try { + var binding = require('hello_world') + t.strictEqual(binding.hello(), 'world') + } catch (error) { + t.error(error, 'load module') + } + }) + proc.stdout.setEncoding('utf-8') + proc.stderr.setEncoding('utf-8') +})