Skip to content

Commit

Permalink
Ensure script output can be captured by tests (#181)
Browse files Browse the repository at this point in the history
Replaces temporary logfile workaround
  • Loading branch information
lovell authored May 30, 2022
1 parent 5065bce commit d1853cb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 22 deletions.
12 changes: 0 additions & 12 deletions log.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const log = require('npmlog')
const fs = require('fs')
const path = require('path')

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

// Temporary workaround for npm 7 which swallows our output
if (process.env.npm_config_prebuild_install_logfile) {
const fp = path.resolve(process.env.npm_config_prebuild_install_logfile)

log.on('log', function (msg) {
// Only for tests, don't care about performance
fs.appendFileSync(fp, [log.heading, msg.level, msg.prefix, msg.message].join(' ') + '\n')
})
}

return log
}
13 changes: 3 additions & 10 deletions test/skip-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ test('does not skip download in standalone package', function (t) {

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

writePackage(addon, {
Expand Down Expand Up @@ -62,19 +61,13 @@ function run (t, mode, args, cb) {
npm_config_addon_binary_host: 'http://localhost:1234',
npm_config_prefer_offline: 'true',
npm_config_audit: 'false',

// Temporary workaround for npm 7 which swallows our output
npm_config_prebuild_install_logfile: logfile,
npm_config_foreground_scripts: true,
npm_config_loglevel: 'info'
})

exec(npm + ' install', { cwd, env }, function (err) {
exec(npm + ' install', { cwd, env }, function (err, stdout, stderr) {
t.ifError(err, 'no install error')

fs.readFile(logfile, 'utf8', function (err, data) {
t.ifError(err, 'no read error')
cb(logs(data))
})
cb(logs(stderr))
})
}

Expand Down

0 comments on commit d1853cb

Please sign in to comment.