Skip to content

Commit

Permalink
test: add win_delay_load_hook test
Browse files Browse the repository at this point in the history
  • Loading branch information
adill committed Oct 15, 2018
1 parent 7a53da6 commit 12a943e
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions test/test-addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ var test = require('tape')
var path = require('path')
var fs = require('graceful-fs')
var child_process = require('child_process')
var os = require('os')
var addonPath = path.resolve(__dirname, 'node_modules', 'hello_world')
var nodeGyp = path.resolve(__dirname, '..', 'bin', 'node-gyp.js')
var execFileSync = child_process.execFileSync || require('./process-exec-sync')
var execFile = child_process.execFile

function runHello() {
function runHello(hostProcess) {
if (!hostProcess) {
hostProcess = process.execPath
}
var testCode = "console.log(require('hello_world').hello())"
return execFileSync(process.execPath, ['-e', testCode], { cwd: __dirname }).toString()
console.log('running ', hostProcess);
return execFileSync(hostProcess, ['-e', testCode], { cwd: __dirname }).toString()
}

function getEncoding() {
Expand Down Expand Up @@ -111,3 +116,22 @@ test('build simple addon in path with non-ascii characters', function (t) {
proc.stdout.setEncoding('utf-8')
proc.stderr.setEncoding('utf-8')
})

test('addon works with renamed host executable', function (t) {
t.plan(3)

var notNodePath = path.join(os.tmpdir(), 'notnode' + path.extname(process.execPath))
fs.copyFileSync(process.execPath, notNodePath)

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')
t.strictEqual(runHello(notNodePath).trim(), 'world')
fs.unlinkSync(notNodePath)
})
proc.stdout.setEncoding('utf-8')
proc.stderr.setEncoding('utf-8')
})

0 comments on commit 12a943e

Please sign in to comment.