Skip to content

Commit 0dba4bd

Browse files
richardlaubnoordhuis
authored andcommitted
test: add simple addon test
PR-URL: #955 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent c4344b3 commit 0dba4bd

File tree

6 files changed

+72
-1
lines changed

6 files changed

+72
-1
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
"node": ">= 0.8.0"
4242
},
4343
"devDependencies": {
44-
"tape": "~4.2.0"
44+
"tape": "~4.2.0",
45+
"bindings": "~1.2.1",
46+
"nan": "^2.0.0"
4547
},
4648
"scripts": {
4749
"test": "tape test/test-*"

test/node_modules/hello_world/binding.gyp

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/node_modules/hello_world/hello.cc

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/node_modules/hello_world/hello.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/node_modules/hello_world/package.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test-addon.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict'
2+
3+
var test = require('tape')
4+
var execFile = require('child_process').execFile
5+
var path = require('path')
6+
var addonPath = path.resolve(__dirname, 'node_modules', 'hello_world')
7+
var nodeGyp = path.resolve(__dirname, '..', 'bin', 'node-gyp.js')
8+
9+
test('build simple addon', function (t) {
10+
t.plan(3)
11+
12+
// Set the loglevel otherwise the output disappears when run via 'npm test'
13+
var cmd = [nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose']
14+
var proc = execFile(process.execPath, cmd, function (err, stdout, stderr) {
15+
var logLines = stderr.toString().trim().split(/\r?\n/)
16+
var lastLine = logLines[logLines.length-1]
17+
t.strictEqual(err, null)
18+
t.strictEqual(lastLine, 'gyp info ok', 'should end in ok')
19+
try {
20+
var binding = require('hello_world')
21+
t.strictEqual(binding.hello(), 'world')
22+
} catch (error) {
23+
t.error(error, 'load module')
24+
}
25+
})
26+
proc.stdout.setEncoding('utf-8')
27+
proc.stderr.setEncoding('utf-8')
28+
})

0 commit comments

Comments
 (0)