Skip to content

Commit

Permalink
Add test for specifying target to build
Browse files Browse the repository at this point in the history
  • Loading branch information
NatalieWolfe committed Apr 5, 2017
1 parent 40aa544 commit 6f05f6c
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions test/test-addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -23,6 +21,39 @@ test('build simple addon', function (t) {
t.error(error, 'load module')
}
})
})

test('build specific addon', function (t) {
t.plan(4)

var cmd = [nodeGyp, 'clean', 'configure', '-C', addonPath, '--loglevel=verbose']
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')
})
}

0 comments on commit 6f05f6c

Please sign in to comment.