Browse Source

Only fix `npm link` of AVA as necessary. (#827)

browser-support
James Talmage 9 years ago
committed by Sindre Sorhus
parent
commit
4abb351903
  1. 25
      lib/fork.js

25
lib/fork.js

@ -1,12 +1,23 @@
'use strict';
var childProcess = require('child_process');
var path = require('path');
var fs = require('fs');
var objectAssign = require('object-assign');
var Promise = require('bluebird');
var debug = require('debug')('ava');
var AvaError = require('./ava-error');
var doSend = require('./send');
var fixNpmLink = fs.realpathSync(__filename) !== __filename;
if (fixNpmLink) {
// Workaround for breakage caused by https://github.com/nodejs/node/pull/5950
// Those changes will be reverted in https://github.com/nodejs/node/pull/6537
// Revert #815 and #827 when the above changes land in Node.js
console.warn('WARNING: `npm link ava` detected: This breaks NYC coverage on early versions of Node 6.\nSee https://github.com/sindresorhus/ava/pull/815');
}
var env = process.env;
// ensure NODE_PATH paths are absolute
@ -31,10 +42,13 @@ module.exports = function (file, opts) {
} : false
}, opts);
var ps;
if (fixNpmLink) {
// Workaround for breakage caused by https://github.com/nodejs/node/pull/5950
// Those changes will be reverted in https://github.com/nodejs/node/pull/6537
// Revert #815 when these changes land in Node.js
// Revert #815 and #827 when the above changes land in Node.js
var execArgv = process.execArgv;
var cwd = path.dirname(file);
@ -57,11 +71,18 @@ module.exports = function (file, opts) {
JSON.stringify(opts)
]);
var ps = childProcess.spawn(process.execPath, args, {
ps = childProcess.spawn(process.execPath, args, {
cwd: cwd,
stdio: ['pipe', 'pipe', 'pipe', 'ipc'],
env: env
});
} else {
ps = childProcess.fork(path.join(__dirname, 'test-worker.js'), [JSON.stringify(opts)], {
cwd: path.dirname(file),
silent: true,
env: env
});
}
var relFile = path.relative('.', file);

Loading…
Cancel
Save