From 967674bc8c82e00390a1c37fd64b39f2e6e72ee5 Mon Sep 17 00:00:00 2001 From: Natalie Wolfe Date: Wed, 5 Apr 2017 11:20:04 -0700 Subject: [PATCH] Add test for specifying target to build --- test/test-addon.js | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/test/test-addon.js b/test/test-addon.js index c2a71f4498..dad49da461 100644 --- a/test/test-addon.js +++ b/test/test-addon.js @@ -9,9 +9,7 @@ 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) { + exec(t, ['rebuild'], [], function (err, stdout, stderr) { var logLines = stderr.toString().trim().split(/\r?\n/) var lastLine = logLines[logLines.length-1] t.strictEqual(err, null) @@ -23,6 +21,38 @@ test('build simple addon', function (t) { t.error(error, 'load module') } }) +}) + +test('build specific addon', function (t) { + t.plan(4) + + exec(t, ['clean', 'configure'], [], function (err) { + t.error(err, 'clean build') + + exec(t, ['build'], ['hello'], 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') + } + }) + }) +}) + +function exec(t, cmd, args, cb) { + // Set the loglevel otherwise the output disappears when run via 'npm test' + var toExec = [nodeGyp] + .concat(cmd) + .concat(['-C', addonPath, '--loglevel=verbose']) + .concat(args) + + t.comment(toExec.join(' ')) + var proc = execFile(process.execPath, toExec, cb) proc.stdout.setEncoding('utf-8') proc.stderr.setEncoding('utf-8') -}) +}