Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: ensure 'npm install' script output can be captured #181

Merged
merged 1 commit into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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