test-addon.js 977 B

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