From d1853cbd75167140945b85c290ace8194c9db87d Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Mon, 30 May 2022 19:47:07 +0100 Subject: [PATCH] Ensure script output can be captured by tests (#181) Replaces temporary logfile workaround --- log.js | 12 ------------ test/skip-test.js | 13 +++---------- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/log.js b/log.js index 115adcd..13011b5 100644 --- a/log.js +++ b/log.js @@ -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' @@ -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 } diff --git a/test/skip-test.js b/test/skip-test.js index 93a8bdc..d60dfb0 100644 --- a/test/skip-test.js +++ b/test/skip-test.js @@ -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, { @@ -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)) }) }