Skip to content

Commit

Permalink
test: add simple addon test
Browse files Browse the repository at this point in the history
PR-URL: #955
Reviewed-By: Ben Noordhuis <[email protected]>
  • Loading branch information
richardlau authored and bnoordhuis committed Jun 17, 2016
1 parent c4344b3 commit 0dba4bd
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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-*"
Expand Down
11 changes: 11 additions & 0 deletions test/node_modules/hello_world/binding.gyp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions test/node_modules/hello_world/hello.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/node_modules/hello_world/hello.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions test/node_modules/hello_world/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions test/test-addon.js
Original file line number Diff line number Diff line change
@@ -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')
})

0 comments on commit 0dba4bd

Please sign in to comment.