Skip to content

Commit

Permalink
fix(mocks): fix conflict between mocks and skip (#863)
Browse files Browse the repository at this point in the history
This fixes a conflict between mocks.init() and
utils.skipOnWin/skipOnUnix. mocks.init() mocks out process.stderr.write,
which utils.js implicitly depends on.

Instead, preserve stderr.write in a local variable to avoid polluting
mocked stdio and to correctly output warning messages.

Fixes #862
Test: locally apply mocks.init() inside test/which.js
  • Loading branch information
nfischer committed Jun 28, 2018
1 parent 72ff790 commit 1dd437e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions test/utils/utils.js
Expand Up @@ -5,6 +5,9 @@ const chalk = require('chalk');

const common = require('../../src/common');

// Capture process.stderr.write, otherwise we have a conflict with mocks.js
const _processStderrWrite = process.stderr.write.bind(process.stderr);

function numLines(str) {
return typeof str === 'string' ? (str.match(/\n/g) || []).length + 1 : 0;
}
Expand All @@ -23,7 +26,7 @@ function skipOnWinForEPERM(action, testCase) {
const error = ret.code;
const isWindows = process.platform === 'win32';
if (isWindows && error && /EPERM:/.test(error)) {
console.warn('Got EPERM when testing symlinks on Windows. Assuming non-admin environment and skipping test.');
_processStderrWrite('Got EPERM when testing symlinks on Windows. Assuming non-admin environment and skipping test.\n');
} else {
testCase();
}
Expand Down Expand Up @@ -56,9 +59,10 @@ exports.mkfifo = mkfifo;

function skipIfTrue(booleanValue, t, closure) {
if (booleanValue) {
console.warn(
_processStderrWrite(
chalk.yellow('Warning: skipping platform-dependent test ') +
chalk.bold.white(`'${t._test.title}'`)
chalk.bold.white(`'${t._test.title}'`) +
'\n'
);
t.truthy(true); // dummy assertion to satisfy ava v0.19+
} else {
Expand Down

0 comments on commit 1dd437e

Please sign in to comment.