Skip to content

Commit d1853cb

Browse files
authored
Ensure script output can be captured by tests (#181)
Replaces temporary logfile workaround
1 parent 5065bce commit d1853cb

File tree

2 files changed

+3
-22
lines changed

2 files changed

+3
-22
lines changed

log.js

-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
const log = require('npmlog')
2-
const fs = require('fs')
3-
const path = require('path')
42

53
module.exports = function (rc, env) {
64
log.heading = 'prebuild-install'
@@ -11,15 +9,5 @@ module.exports = function (rc, env) {
119
log.level = env.npm_config_loglevel || 'notice'
1210
}
1311

14-
// Temporary workaround for npm 7 which swallows our output
15-
if (process.env.npm_config_prebuild_install_logfile) {
16-
const fp = path.resolve(process.env.npm_config_prebuild_install_logfile)
17-
18-
log.on('log', function (msg) {
19-
// Only for tests, don't care about performance
20-
fs.appendFileSync(fp, [log.heading, msg.level, msg.prefix, msg.message].join(' ') + '\n')
21-
})
22-
}
23-
2412
return log
2513
}

test/skip-test.js

+3-10
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ test('does not skip download in standalone package', function (t) {
3333

3434
function run (t, mode, args, cb) {
3535
const addon = tempy.directory()
36-
const logfile = path.join(addon, 'prebuild-install.log')
3736
let cwd = addon
3837

3938
writePackage(addon, {
@@ -62,19 +61,13 @@ function run (t, mode, args, cb) {
6261
npm_config_addon_binary_host: 'http://localhost:1234',
6362
npm_config_prefer_offline: 'true',
6463
npm_config_audit: 'false',
65-
66-
// Temporary workaround for npm 7 which swallows our output
67-
npm_config_prebuild_install_logfile: logfile,
64+
npm_config_foreground_scripts: true,
6865
npm_config_loglevel: 'info'
6966
})
7067

71-
exec(npm + ' install', { cwd, env }, function (err) {
68+
exec(npm + ' install', { cwd, env }, function (err, stdout, stderr) {
7269
t.ifError(err, 'no install error')
73-
74-
fs.readFile(logfile, 'utf8', function (err, data) {
75-
t.ifError(err, 'no read error')
76-
cb(logs(data))
77-
})
70+
cb(logs(stderr))
7871
})
7972
}
8073

0 commit comments

Comments
 (0)