Skip to content

Commit ff52fd5

Browse files
committed
test: log MSBuild output and cache dir on Windows build failures
1 parent b2cde80 commit ff52fd5

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

test/test-addon.js

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ const nodeGyp = path.resolve(__dirname, '..', 'bin', 'node-gyp.js')
1515
const execFileSync = (...args) => cp.execFileSync(...args).toString().trim()
1616

1717
const execFile = async (cmd) => {
18-
const [err,, stderr] = await util.execFile(process.execPath, cmd, {
18+
const [err, stdout, stderr] = await util.execFile(process.execPath, cmd, {
1919
env: { ...process.env, NODE_GYP_NULL_LOGGER: undefined },
2020
encoding: 'utf-8'
2121
})
22-
return [err, stderr.toString().trim().split(/\r?\n/)]
22+
return [err, stderr.toString().trim().split(/\r?\n/), stdout.toString().trim()]
2323
}
2424

2525
function runHello (hostProcess = process.execPath) {
@@ -47,7 +47,23 @@ describe('addon', function () {
4747

4848
// Set the loglevel otherwise the output disappears when run via 'npm test'
4949
const cmd = [nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose']
50-
const [err, logLines] = await execFile(cmd)
50+
const [err, logLines, stdout] = await execFile(cmd)
51+
if (err) {
52+
console.log('-- build stdout (MSBuild/make output) --')
53+
console.log(stdout)
54+
console.log('-- build stderr (gyp logs) --')
55+
console.log(logLines.join('\n'))
56+
if (process.platform === 'win32') {
57+
const devDir = path.join(process.env.LOCALAPPDATA || '', 'node-gyp', 'Cache', process.version.slice(1))
58+
try {
59+
const listing = cp.execFileSync('cmd', ['/c', 'dir', '/s', '/b', devDir], { encoding: 'utf-8' })
60+
console.log('-- node-gyp cache dir listing --')
61+
console.log(listing)
62+
} catch (e) {
63+
console.log('-- failed to list cache dir:', devDir, e.message, '--')
64+
}
65+
}
66+
}
5167
const lastLine = logLines[logLines.length - 1]
5268
assert.strictEqual(err, null)
5369
assert.strictEqual(lastLine, 'gyp info ok', 'should end in ok')
@@ -103,12 +119,18 @@ describe('addon', function () {
103119
'--loglevel=verbose',
104120
'-nodedir=' + testNodeDir
105121
]
106-
const [err, logLines] = await execFile(cmd)
122+
const [err, logLines, stdout] = await execFile(cmd)
107123
try {
108124
fs.unlink(testNodeDir)
109125
} catch (err) {
110126
assert.fail(err)
111127
}
128+
if (err) {
129+
console.log('-- build stdout (MSBuild/make output) --')
130+
console.log(stdout)
131+
console.log('-- build stderr (gyp logs) --')
132+
console.log(logLines.join('\n'))
133+
}
112134
const lastLine = logLines[logLines.length - 1]
113135
assert.strictEqual(err, null)
114136
assert.strictEqual(lastLine, 'gyp info ok', 'should end in ok')
@@ -122,7 +144,13 @@ describe('addon', function () {
122144
fs.copyFileSync(process.execPath, notNodePath)
123145

124146
const cmd = [nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose']
125-
const [err, logLines] = await execFile(cmd)
147+
const [err, logLines, stdout] = await execFile(cmd)
148+
if (err) {
149+
console.log('-- build stdout (MSBuild/make output) --')
150+
console.log(stdout)
151+
console.log('-- build stderr (gyp logs) --')
152+
console.log(logLines.join('\n'))
153+
}
126154
const lastLine = logLines[logLines.length - 1]
127155
assert.strictEqual(err, null)
128156
assert.strictEqual(lastLine, 'gyp info ok', 'should end in ok')

0 commit comments

Comments
 (0)