Initial commit
[yaffs-website] / node_modules / node-gyp / test / test-addon.js
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 })