From c2aab4f9bbf316559e144cdc83d671a6f85f0add Mon Sep 17 00:00:00 2001 From: Emanuele Ingrosso Date: Tue, 9 Feb 2016 10:10:01 +0100 Subject: [PATCH 01/15] Support NODE_PATH in forked process --- api.js | 4 ++++ lib/test-worker.js | 3 +++ 2 files changed, 7 insertions(+) diff --git a/api.js b/api.js index 31ce3f569..64916a046 100644 --- a/api.js +++ b/api.js @@ -49,6 +49,10 @@ function Api(files, options) { }, this); this._reset(); + + if (process.env.NODE_PATH) { + process.env.NODE_PATH = path.join(process.cwd(), process.env.NODE_PATH); + } } util.inherits(Api, EventEmitter); diff --git a/lib/test-worker.js b/lib/test-worker.js index f241042e8..c69278031 100644 --- a/lib/test-worker.js +++ b/lib/test-worker.js @@ -86,6 +86,9 @@ var oldNodeModulesPaths = module.constructor._nodeModulePaths; module.constructor._nodeModulePaths = function () { var ret = oldNodeModulesPaths.apply(this, arguments); ret.push(nodeModulesDir); + if (process.env.NODE_PATH) { + ret.push(process.env.NODE_PATH); + } return ret; }; From 3704a070f70b6561dbb57da874e7d14317569d1b Mon Sep 17 00:00:00 2001 From: Emanuele Ingrosso Date: Tue, 9 Feb 2016 14:50:34 +0100 Subject: [PATCH 02/15] Reworked how to pass the project path to the forked process --- api.js | 4 ---- lib/fork.js | 3 ++- lib/test-worker.js | 5 ++++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api.js b/api.js index 64916a046..31ce3f569 100644 --- a/api.js +++ b/api.js @@ -49,10 +49,6 @@ function Api(files, options) { }, this); this._reset(); - - if (process.env.NODE_PATH) { - process.env.NODE_PATH = path.join(process.cwd(), process.env.NODE_PATH); - } } util.inherits(Api, EventEmitter); diff --git a/lib/fork.js b/lib/fork.js index b9bc5cfaf..4c1de86e9 100644 --- a/lib/fork.js +++ b/lib/fork.js @@ -13,7 +13,8 @@ module.exports = function (file, opts) { tty: process.stdout.isTTY ? { columns: process.stdout.columns, rows: process.stdout.rows - } : false + } : false, + projectRoot: process.cwd() }, opts); var ps = childProcess.fork(path.join(__dirname, 'test-worker.js'), [JSON.stringify(opts)], { diff --git a/lib/test-worker.js b/lib/test-worker.js index c69278031..542d83035 100644 --- a/lib/test-worker.js +++ b/lib/test-worker.js @@ -87,7 +87,10 @@ module.constructor._nodeModulePaths = function () { var ret = oldNodeModulesPaths.apply(this, arguments); ret.push(nodeModulesDir); if (process.env.NODE_PATH) { - ret.push(process.env.NODE_PATH); + var osSplitChar = /^win/.test(process.platform) ? ';' : ','; + process.env.NODE_PATH.split(osSplitChar).forEach(function(additionalPath) { + ret.push(path.join(opts.projectRoot, additionalPath)); + }); } return ret; }; From 33dd8f6717346b26fc679a0ec299d09514bd970e Mon Sep 17 00:00:00 2001 From: Emanuele Ingrosso Date: Tue, 9 Feb 2016 14:50:34 +0100 Subject: [PATCH 03/15] Reworked how to pass the project path to the forked process --- api.js | 4 ---- lib/fork.js | 3 ++- lib/test-worker.js | 5 ++++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api.js b/api.js index 64916a046..31ce3f569 100644 --- a/api.js +++ b/api.js @@ -49,10 +49,6 @@ function Api(files, options) { }, this); this._reset(); - - if (process.env.NODE_PATH) { - process.env.NODE_PATH = path.join(process.cwd(), process.env.NODE_PATH); - } } util.inherits(Api, EventEmitter); diff --git a/lib/fork.js b/lib/fork.js index b9bc5cfaf..4c1de86e9 100644 --- a/lib/fork.js +++ b/lib/fork.js @@ -13,7 +13,8 @@ module.exports = function (file, opts) { tty: process.stdout.isTTY ? { columns: process.stdout.columns, rows: process.stdout.rows - } : false + } : false, + projectRoot: process.cwd() }, opts); var ps = childProcess.fork(path.join(__dirname, 'test-worker.js'), [JSON.stringify(opts)], { diff --git a/lib/test-worker.js b/lib/test-worker.js index c69278031..65d74c74e 100644 --- a/lib/test-worker.js +++ b/lib/test-worker.js @@ -87,7 +87,10 @@ module.constructor._nodeModulePaths = function () { var ret = oldNodeModulesPaths.apply(this, arguments); ret.push(nodeModulesDir); if (process.env.NODE_PATH) { - ret.push(process.env.NODE_PATH); + var osSplitChar = /^win/.test(process.platform) ? ';' : ','; + process.env.NODE_PATH.split(osSplitChar).forEach(function (additionalPath) { + ret.push(path.join(opts.projectRoot, additionalPath)); + }); } return ret; }; From d37a3565a60a2bfad21a8207c4a90d43d3d0161e Mon Sep 17 00:00:00 2001 From: Emanuele Ingrosso Date: Tue, 9 Feb 2016 16:14:37 +0100 Subject: [PATCH 04/15] Update logic to generate an array of additional paths from the NODE_PATH env --- cli.js | 11 ++++++++++- lib/fork.js | 2 +- lib/test-worker.js | 7 +++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cli.js b/cli.js index 449fea459..30941d41d 100755 --- a/cli.js +++ b/cli.js @@ -93,11 +93,20 @@ if (cli.flags.init) { return; } +var additionalPaths = []; +if (process.env.NODE_PATH) { + var osSplitChar = process.platform === 'win32' ? ';' : ':'; + process.env.NODE_PATH.split(osSplitChar).forEach(function (additionalPath) { + additionalPaths.push(path.resolve(opts.projectRoot, additionalPath)); + }); +} + var api = new Api(cli.input.length ? cli.input : arrify(conf.files), { failFast: cli.flags.failFast, serial: cli.flags.serial, require: arrify(cli.flags.require), - cacheEnabled: cli.flags.cache !== false + cacheEnabled: cli.flags.cache !== false, + additionalPaths: additionalPaths }); var logger = new Logger(); diff --git a/lib/fork.js b/lib/fork.js index 4c1de86e9..0a4e830fb 100644 --- a/lib/fork.js +++ b/lib/fork.js @@ -14,7 +14,7 @@ module.exports = function (file, opts) { columns: process.stdout.columns, rows: process.stdout.rows } : false, - projectRoot: process.cwd() + additionalPaths: opts.additionalPaths }, opts); var ps = childProcess.fork(path.join(__dirname, 'test-worker.js'), [JSON.stringify(opts)], { diff --git a/lib/test-worker.js b/lib/test-worker.js index 65d74c74e..45f4199ec 100644 --- a/lib/test-worker.js +++ b/lib/test-worker.js @@ -86,10 +86,9 @@ var oldNodeModulesPaths = module.constructor._nodeModulePaths; module.constructor._nodeModulePaths = function () { var ret = oldNodeModulesPaths.apply(this, arguments); ret.push(nodeModulesDir); - if (process.env.NODE_PATH) { - var osSplitChar = /^win/.test(process.platform) ? ';' : ','; - process.env.NODE_PATH.split(osSplitChar).forEach(function (additionalPath) { - ret.push(path.join(opts.projectRoot, additionalPath)); + if (opts.additionalPaths && opts.additionalPaths.length > 0) { + opts.additionalPaths.forEach(function (additionalPath) { + ret.push(additionalPath); }); } return ret; From 082708be319424d12f48501a52b2b5c0c33a2f78 Mon Sep 17 00:00:00 2001 From: Emanuele Ingrosso Date: Tue, 9 Feb 2016 17:46:48 +0100 Subject: [PATCH 05/15] Changed options name and added test to support NODE_PATH --- cli.js | 15 +++++++++------ lib/fork.js | 3 +-- lib/test-worker.js | 6 ++---- test/cli.js | 12 +++++++++++- test/fixture/node-paths.js | 7 +++++++ test/fixture/node-paths/modules/nested/foo.js | 3 +++ 6 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 test/fixture/node-paths.js create mode 100644 test/fixture/node-paths/modules/nested/foo.js diff --git a/cli.js b/cli.js index 30941d41d..09b56aa9f 100755 --- a/cli.js +++ b/cli.js @@ -17,6 +17,7 @@ if (debug.enabled) { require('time-require'); } +var path = require('path'); var updateNotifier = require('update-notifier'); var figures = require('figures'); var arrify = require('arrify'); @@ -93,12 +94,14 @@ if (cli.flags.init) { return; } -var additionalPaths = []; +var nodePaths; if (process.env.NODE_PATH) { - var osSplitChar = process.platform === 'win32' ? ';' : ':'; - process.env.NODE_PATH.split(osSplitChar).forEach(function (additionalPath) { - additionalPaths.push(path.resolve(opts.projectRoot, additionalPath)); - }); + var osSplitChar = process.platform === 'win32' ? ';' : ':'; + nodePaths = process.env.NODE_PATH.split(osSplitChar).map(function (p) { + return path.resolve(process.cwd(), p) + }); +} else { + nodePaths = [] } var api = new Api(cli.input.length ? cli.input : arrify(conf.files), { @@ -106,7 +109,7 @@ var api = new Api(cli.input.length ? cli.input : arrify(conf.files), { serial: cli.flags.serial, require: arrify(cli.flags.require), cacheEnabled: cli.flags.cache !== false, - additionalPaths: additionalPaths + nodePaths: nodePaths }); var logger = new Logger(); diff --git a/lib/fork.js b/lib/fork.js index 0a4e830fb..b9bc5cfaf 100644 --- a/lib/fork.js +++ b/lib/fork.js @@ -13,8 +13,7 @@ module.exports = function (file, opts) { tty: process.stdout.isTTY ? { columns: process.stdout.columns, rows: process.stdout.rows - } : false, - additionalPaths: opts.additionalPaths + } : false }, opts); var ps = childProcess.fork(path.join(__dirname, 'test-worker.js'), [JSON.stringify(opts)], { diff --git a/lib/test-worker.js b/lib/test-worker.js index 45f4199ec..0b10e5596 100644 --- a/lib/test-worker.js +++ b/lib/test-worker.js @@ -86,10 +86,8 @@ var oldNodeModulesPaths = module.constructor._nodeModulePaths; module.constructor._nodeModulePaths = function () { var ret = oldNodeModulesPaths.apply(this, arguments); ret.push(nodeModulesDir); - if (opts.additionalPaths && opts.additionalPaths.length > 0) { - opts.additionalPaths.forEach(function (additionalPath) { - ret.push(additionalPath); - }); + if (opts.nodePaths && opts.nodePaths.length > 0) { + ret = ret.concat(opts.nodePaths); } return ret; }; diff --git a/test/cli.js b/test/cli.js index cadb0ad7b..3d786220a 100644 --- a/test/cli.js +++ b/test/cli.js @@ -15,7 +15,10 @@ function execCli(args, dirname, cb) { dirname = path.join(__dirname, dirname); } - var env = {}; + var env = { + // This probably should be set only for the corresponding test + NODE_PATH: 'node-paths/modules' + }; if (process.env.AVA_APPVEYOR) { env.AVA_APPVEYOR = 1; @@ -110,3 +113,10 @@ test('pkg-conf: cli takes precedence', function (t) { t.end(); }); }); + +test('handles NODE_PATH', function (t) { + execCli('fixture/node-paths.js', function (err) { + t.notOk(err); + t.end(); + }); +}); diff --git a/test/fixture/node-paths.js b/test/fixture/node-paths.js new file mode 100644 index 000000000..743625818 --- /dev/null +++ b/test/fixture/node-paths.js @@ -0,0 +1,7 @@ +import test from '../../'; + +import foo from 'nested/foo'; + +test('relative require', t => { + t.is(foo(), 'bar'); +}); diff --git a/test/fixture/node-paths/modules/nested/foo.js b/test/fixture/node-paths/modules/nested/foo.js new file mode 100644 index 000000000..1723f5abd --- /dev/null +++ b/test/fixture/node-paths/modules/nested/foo.js @@ -0,0 +1,3 @@ +module.exports = function() { + return 'bar'; +} From d4bf3ee4049255c4d69315e5841e3590b8255239 Mon Sep 17 00:00:00 2001 From: Emanuele Ingrosso Date: Tue, 9 Feb 2016 18:03:40 +0100 Subject: [PATCH 06/15] Partially fixed tests --- test/cli.js | 2 +- test/fixture/node-paths.js | 2 ++ test/fixture/node-paths/deep/nested/path/bar.js | 3 +++ test/fixture/node-paths/modules/nested/foo.js | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 test/fixture/node-paths/deep/nested/path/bar.js diff --git a/test/cli.js b/test/cli.js index 3d786220a..93e54a950 100644 --- a/test/cli.js +++ b/test/cli.js @@ -17,7 +17,7 @@ function execCli(args, dirname, cb) { var env = { // This probably should be set only for the corresponding test - NODE_PATH: 'node-paths/modules' + NODE_PATH: 'node-paths/modules;node-paths/deep/nested' }; if (process.env.AVA_APPVEYOR) { diff --git a/test/fixture/node-paths.js b/test/fixture/node-paths.js index 743625818..a199611e7 100644 --- a/test/fixture/node-paths.js +++ b/test/fixture/node-paths.js @@ -1,7 +1,9 @@ import test from '../../'; import foo from 'nested/foo'; +import bar from 'path/bar'; test('relative require', t => { t.is(foo(), 'bar'); + t.is(bar(), 'baz'); }); diff --git a/test/fixture/node-paths/deep/nested/path/bar.js b/test/fixture/node-paths/deep/nested/path/bar.js new file mode 100644 index 000000000..8831d60c1 --- /dev/null +++ b/test/fixture/node-paths/deep/nested/path/bar.js @@ -0,0 +1,3 @@ +module.exports = function() { + return 'baz'; +}; diff --git a/test/fixture/node-paths/modules/nested/foo.js b/test/fixture/node-paths/modules/nested/foo.js index 1723f5abd..bb539eff5 100644 --- a/test/fixture/node-paths/modules/nested/foo.js +++ b/test/fixture/node-paths/modules/nested/foo.js @@ -1,3 +1,3 @@ module.exports = function() { return 'bar'; -} +}; From 1e2d8ad3a0ffd9143d9844023693794207772b81 Mon Sep 17 00:00:00 2001 From: Emanuele Ingrosso Date: Wed, 10 Feb 2016 09:53:16 +0100 Subject: [PATCH 07/15] Fix cli test for NODE_PATH support --- test/cli.js | 15 +++++++++------ test/fixture/node-paths/deep/nested/path/bar.js | 1 + test/fixture/node-paths/modules/nested/foo.js | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/test/cli.js b/test/cli.js index 93e54a950..12e5fbbb6 100644 --- a/test/cli.js +++ b/test/cli.js @@ -7,7 +7,7 @@ var getStream = require('get-stream'); var arrify = require('arrify'); var cliPath = path.join(__dirname, '../cli.js'); -function execCli(args, dirname, cb) { +function execCli(args, dirname, env, cb) { if (typeof dirname === 'function') { cb = dirname; dirname = __dirname; @@ -15,10 +15,12 @@ function execCli(args, dirname, cb) { dirname = path.join(__dirname, dirname); } - var env = { - // This probably should be set only for the corresponding test - NODE_PATH: 'node-paths/modules;node-paths/deep/nested' - }; + if (typeof env === 'function') { + cb = env; + env = {}; + } + + env = env || {}; if (process.env.AVA_APPVEYOR) { env.AVA_APPVEYOR = 1; @@ -115,8 +117,9 @@ test('pkg-conf: cli takes precedence', function (t) { }); test('handles NODE_PATH', function (t) { - execCli('fixture/node-paths.js', function (err) { + execCli('fixture/node-paths.js', '', { NODE_PATH: 'node-paths/modules;node-paths/deep/nested' }, function (err, stdout, stderr) { t.notOk(err); t.end(); }); }); + diff --git a/test/fixture/node-paths/deep/nested/path/bar.js b/test/fixture/node-paths/deep/nested/path/bar.js index 8831d60c1..eeaff8f96 100644 --- a/test/fixture/node-paths/deep/nested/path/bar.js +++ b/test/fixture/node-paths/deep/nested/path/bar.js @@ -1,3 +1,4 @@ module.exports = function() { return 'baz'; }; + diff --git a/test/fixture/node-paths/modules/nested/foo.js b/test/fixture/node-paths/modules/nested/foo.js index bb539eff5..e68f18037 100644 --- a/test/fixture/node-paths/modules/nested/foo.js +++ b/test/fixture/node-paths/modules/nested/foo.js @@ -1,3 +1,4 @@ module.exports = function() { return 'bar'; }; + From eecfebb1579ceebbcde3ec3e06749b8d20917089 Mon Sep 17 00:00:00 2001 From: Emanuele Ingrosso Date: Wed, 10 Feb 2016 10:10:54 +0100 Subject: [PATCH 08/15] Fix test for NODE_PATH on all os --- test/cli.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/cli.js b/test/cli.js index 12e5fbbb6..fd610d587 100644 --- a/test/cli.js +++ b/test/cli.js @@ -117,7 +117,9 @@ test('pkg-conf: cli takes precedence', function (t) { }); test('handles NODE_PATH', function (t) { - execCli('fixture/node-paths.js', '', { NODE_PATH: 'node-paths/modules;node-paths/deep/nested' }, function (err, stdout, stderr) { + var separator = process.platform === 'win32' ? ';' : ':'; + var nodePaths = 'node-paths/modules' + separator + 'node-paths/deep/nested'; + execCli('fixture/node-paths.js', '', {NODE_PATH: nodePaths}, function (err) { t.notOk(err); t.end(); }); From c42afed9d6a5252c6b7afaa16f3df89b4b09b3cd Mon Sep 17 00:00:00 2001 From: Emanuele Ingrosso Date: Wed, 10 Feb 2016 10:56:14 +0100 Subject: [PATCH 09/15] Use path.delimiter instead of check os --- cli.js | 7 +++---- test/cli.js | 3 +-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/cli.js b/cli.js index 09b56aa9f..5f5f8b293 100755 --- a/cli.js +++ b/cli.js @@ -96,12 +96,11 @@ if (cli.flags.init) { var nodePaths; if (process.env.NODE_PATH) { - var osSplitChar = process.platform === 'win32' ? ';' : ':'; - nodePaths = process.env.NODE_PATH.split(osSplitChar).map(function (p) { - return path.resolve(process.cwd(), p) + nodePaths = process.env.NODE_PATH.split(path.delimiter).map(function (p) { + return path.resolve(process.cwd(), p); }); } else { - nodePaths = [] + nodePaths = []; } var api = new Api(cli.input.length ? cli.input : arrify(conf.files), { diff --git a/test/cli.js b/test/cli.js index fd610d587..cda5afc74 100644 --- a/test/cli.js +++ b/test/cli.js @@ -117,8 +117,7 @@ test('pkg-conf: cli takes precedence', function (t) { }); test('handles NODE_PATH', function (t) { - var separator = process.platform === 'win32' ? ';' : ':'; - var nodePaths = 'node-paths/modules' + separator + 'node-paths/deep/nested'; + var nodePaths = 'node-paths/modules' + path.delimiter + 'node-paths/deep/nested'; execCli('fixture/node-paths.js', '', {NODE_PATH: nodePaths}, function (err) { t.notOk(err); t.end(); From 581e77633f1139962f34372890c99c833476d974 Mon Sep 17 00:00:00 2001 From: Emanuele Ingrosso Date: Wed, 10 Feb 2016 17:26:27 +0100 Subject: [PATCH 10/15] Removed unnecessarily call to process.cwd() --- cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli.js b/cli.js index 5f5f8b293..abfe14c8a 100755 --- a/cli.js +++ b/cli.js @@ -97,7 +97,7 @@ if (cli.flags.init) { var nodePaths; if (process.env.NODE_PATH) { nodePaths = process.env.NODE_PATH.split(path.delimiter).map(function (p) { - return path.resolve(process.cwd(), p); + return path.resolve(p); }); } else { nodePaths = []; From 5dc109e9588520d83431f113164f13cb77ee6880 Mon Sep 17 00:00:00 2001 From: Emanuele Ingrosso Date: Fri, 12 Feb 2016 11:46:00 +0100 Subject: [PATCH 11/15] New approach to retrieve NODE_PATH from forked process --- cli.js | 12 +------- lib/fork.js | 18 +++++++++++- lib/test-worker.js | 3 -- test/cli.js | 29 +++++++++---------- .../node-paths/deep/nested/path/bar.js | 2 +- test/fixture/node-paths/modules/nested/foo.js | 2 +- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/cli.js b/cli.js index abfe14c8a..5da3c91a4 100755 --- a/cli.js +++ b/cli.js @@ -94,21 +94,11 @@ if (cli.flags.init) { return; } -var nodePaths; -if (process.env.NODE_PATH) { - nodePaths = process.env.NODE_PATH.split(path.delimiter).map(function (p) { - return path.resolve(p); - }); -} else { - nodePaths = []; -} - var api = new Api(cli.input.length ? cli.input : arrify(conf.files), { failFast: cli.flags.failFast, serial: cli.flags.serial, require: arrify(cli.flags.require), - cacheEnabled: cli.flags.cache !== false, - nodePaths: nodePaths + cacheEnabled: cli.flags.cache !== false }); var logger = new Logger(); diff --git a/lib/fork.js b/lib/fork.js index b9bc5cfaf..e14380799 100644 --- a/lib/fork.js +++ b/lib/fork.js @@ -16,9 +16,25 @@ module.exports = function (file, opts) { } : false }, opts); + var env = process.env; + + if (process.env.NODE_PATH) { + var nodePath = process.env.NODE_PATH + .split(path.delimiter) + .map(function (p) { + return path.resolve(p); + }) + .join(path.delimiter); + + env = objectAssign({ + NODE_PATH: nodePath + }, env); + } + var ps = childProcess.fork(path.join(__dirname, 'test-worker.js'), [JSON.stringify(opts)], { cwd: path.dirname(file), - silent: true + silent: true, + env: env }); var relFile = path.relative('.', file); diff --git a/lib/test-worker.js b/lib/test-worker.js index 0b10e5596..f241042e8 100644 --- a/lib/test-worker.js +++ b/lib/test-worker.js @@ -86,9 +86,6 @@ var oldNodeModulesPaths = module.constructor._nodeModulePaths; module.constructor._nodeModulePaths = function () { var ret = oldNodeModulesPaths.apply(this, arguments); ret.push(nodeModulesDir); - if (opts.nodePaths && opts.nodePaths.length > 0) { - ret = ret.concat(opts.nodePaths); - } return ret; }; diff --git a/test/cli.js b/test/cli.js index cda5afc74..45ac01dcd 100644 --- a/test/cli.js +++ b/test/cli.js @@ -7,21 +7,19 @@ var getStream = require('get-stream'); var arrify = require('arrify'); var cliPath = path.join(__dirname, '../cli.js'); -function execCli(args, dirname, env, cb) { - if (typeof dirname === 'function') { - cb = dirname; - dirname = __dirname; - } else { - dirname = path.join(__dirname, dirname); - } +function execCli(args, opts, cb) { + var dirname; + var env; - if (typeof env === 'function') { - cb = env; + if (typeof opts === 'function') { + cb = opts; + dirname = __dirname; env = {}; + } else { + dirname = path.join(__dirname, opts.dirname ? opts.dirname : ''); + env = opts.env; } - env = env || {}; - if (process.env.AVA_APPVEYOR) { env.AVA_APPVEYOR = 1; } @@ -96,21 +94,21 @@ test('log failed tests', function (t) { }); test('pkg-conf: defaults', function (t) { - execCli([], 'fixture/pkg-conf/defaults', function (err) { + execCli([], {dirname:'fixture/pkg-conf/defaults'}, function (err) { t.ifError(err); t.end(); }); }); test('pkg-conf: pkg-overrides', function (t) { - execCli([], 'fixture/pkg-conf/pkg-overrides', function (err) { + execCli([], {dirname:'fixture/pkg-conf/pkg-overrides'}, function (err) { t.ifError(err); t.end(); }); }); test('pkg-conf: cli takes precedence', function (t) { - execCli(['--no-serial', '--cache', '--no-fail-fast', '--require=./required.js', 'c.js'], 'fixture/pkg-conf/precedence', function (err) { + execCli(['--no-serial', '--cache', '--no-fail-fast', '--require=./required.js', 'c.js'], {dirname:'fixture/pkg-conf/precedence'}, function (err) { t.ifError(err); t.end(); }); @@ -118,9 +116,8 @@ test('pkg-conf: cli takes precedence', function (t) { test('handles NODE_PATH', function (t) { var nodePaths = 'node-paths/modules' + path.delimiter + 'node-paths/deep/nested'; - execCli('fixture/node-paths.js', '', {NODE_PATH: nodePaths}, function (err) { + execCli('fixture/node-paths.js', {env:{NODE_PATH: nodePaths}}, function (err, stdout, stderr) { t.notOk(err); t.end(); }); }); - diff --git a/test/fixture/node-paths/deep/nested/path/bar.js b/test/fixture/node-paths/deep/nested/path/bar.js index eeaff8f96..9642d6cc4 100644 --- a/test/fixture/node-paths/deep/nested/path/bar.js +++ b/test/fixture/node-paths/deep/nested/path/bar.js @@ -1,4 +1,4 @@ -module.exports = function() { +module.exports = function () { return 'baz'; }; diff --git a/test/fixture/node-paths/modules/nested/foo.js b/test/fixture/node-paths/modules/nested/foo.js index e68f18037..a695c3b37 100644 --- a/test/fixture/node-paths/modules/nested/foo.js +++ b/test/fixture/node-paths/modules/nested/foo.js @@ -1,4 +1,4 @@ -module.exports = function() { +module.exports = function () { return 'bar'; }; From f947eb07a3d81ffe672977c7ef203aa9e98c9124 Mon Sep 17 00:00:00 2001 From: Emanuele Ingrosso Date: Fri, 12 Feb 2016 11:49:41 +0100 Subject: [PATCH 12/15] Linting --- cli.js | 1 - lib/fork.js | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cli.js b/cli.js index 5da3c91a4..449fea459 100755 --- a/cli.js +++ b/cli.js @@ -17,7 +17,6 @@ if (debug.enabled) { require('time-require'); } -var path = require('path'); var updateNotifier = require('update-notifier'); var figures = require('figures'); var arrify = require('arrify'); diff --git a/lib/fork.js b/lib/fork.js index e14380799..f4eb69aa6 100644 --- a/lib/fork.js +++ b/lib/fork.js @@ -19,12 +19,12 @@ module.exports = function (file, opts) { var env = process.env; if (process.env.NODE_PATH) { - var nodePath = process.env.NODE_PATH - .split(path.delimiter) - .map(function (p) { - return path.resolve(p); - }) - .join(path.delimiter); + var nodePath = process.env.NODE_PATH + .split(path.delimiter) + .map(function (p) { + return path.resolve(p); + }) + .join(path.delimiter); env = objectAssign({ NODE_PATH: nodePath From d2fa2a2676ca67a87f6003cc179e55142db0176e Mon Sep 17 00:00:00 2001 From: Emanuele Ingrosso Date: Mon, 15 Feb 2016 12:04:44 +0100 Subject: [PATCH 13/15] Linting --- test/cli.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/cli.js b/test/cli.js index 615142aec..abf65a905 100644 --- a/test/cli.js +++ b/test/cli.js @@ -98,21 +98,21 @@ test('log failed tests', function (t) { }); test('pkg-conf: defaults', function (t) { - execCli([], {dirname:'fixture/pkg-conf/defaults'}, function (err) { + execCli([], {dirname: 'fixture/pkg-conf/defaults'}, function (err) { t.ifError(err); t.end(); }); }); test('pkg-conf: pkg-overrides', function (t) { - execCli([], {dirname:'fixture/pkg-conf/pkg-overrides'}, function (err) { + execCli([], {dirname: 'fixture/pkg-conf/pkg-overrides'}, function (err) { t.ifError(err); t.end(); }); }); test('pkg-conf: cli takes precedence', function (t) { - execCli(['--no-serial', '--cache', '--no-fail-fast', '--require=./required.js', 'c.js'], {dirname:'fixture/pkg-conf/precedence'}, function (err) { + execCli(['--no-serial', '--cache', '--no-fail-fast', '--require=./required.js', 'c.js'], {dirname: 'fixture/pkg-conf/precedence'}, function (err) { t.ifError(err); t.end(); }); @@ -127,7 +127,7 @@ test('watcher works', function (t) { hasChokidar = true; } catch (err) {} - var child = execCli(['--verbose', '--watch', 'test.js'], {dirname:'fixture/watcher'}, function (err, stdout) { + var child = execCli(['--verbose', '--watch', 'test.js'], {dirname: 'fixture/watcher'}, function (err, stdout) { if (err && err.code === 1 && !hasChokidar) { t.comment('chokidar dependency is missing, cannot test watcher'); t.match(stdout, 'The optional dependency chokidar failed to install and is required for --watch. Chokidar is likely not supported on your platform.'); @@ -161,7 +161,7 @@ test('watcher works', function (t) { test('handles NODE_PATH', function (t) { var nodePaths = 'node-paths/modules' + path.delimiter + 'node-paths/deep/nested'; - execCli('fixture/node-paths.js', {env:{NODE_PATH: nodePaths}}, function (err, stdout, stderr) { + execCli('fixture/node-paths.js', {env: {NODE_PATH: nodePaths}}, function (err) { t.notOk(err); t.end(); }); From efdc4c26ec21019531af49f872ef532914e0cc5b Mon Sep 17 00:00:00 2001 From: Emanuele Ingrosso Date: Mon, 15 Feb 2016 12:16:37 +0100 Subject: [PATCH 14/15] Fix build APPVEYOR --- test/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cli.js b/test/cli.js index abf65a905..555f8b0c7 100644 --- a/test/cli.js +++ b/test/cli.js @@ -18,7 +18,7 @@ function execCli(args, opts, cb) { env = {}; } else { dirname = path.join(__dirname, opts.dirname ? opts.dirname : ''); - env = opts.env; + env = opts.env || {}; } if (process.env.AVA_APPVEYOR) { From 75b0de0a19c13f4b3d9046d1558026945465223a Mon Sep 17 00:00:00 2001 From: Emanuele Ingrosso Date: Mon, 15 Feb 2016 13:05:21 +0100 Subject: [PATCH 15/15] Moved env generation for fork process outside --- lib/fork.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/fork.js b/lib/fork.js index f4eb69aa6..3affd0795 100644 --- a/lib/fork.js +++ b/lib/fork.js @@ -7,6 +7,21 @@ var debug = require('debug')('ava'); var AvaError = require('./ava-error'); var send = require('./send'); +var env = process.env; + +if (process.env.NODE_PATH) { + var nodePath = process.env.NODE_PATH + .split(path.delimiter) + .map(function (p) { + return path.resolve(p); + }) + .join(path.delimiter); + + env = objectAssign({ + NODE_PATH: nodePath + }, env); +} + module.exports = function (file, opts) { opts = objectAssign({ file: file, @@ -16,21 +31,6 @@ module.exports = function (file, opts) { } : false }, opts); - var env = process.env; - - if (process.env.NODE_PATH) { - var nodePath = process.env.NODE_PATH - .split(path.delimiter) - .map(function (p) { - return path.resolve(p); - }) - .join(path.delimiter); - - env = objectAssign({ - NODE_PATH: nodePath - }, env); - } - var ps = childProcess.fork(path.join(__dirname, 'test-worker.js'), [JSON.stringify(opts)], { cwd: path.dirname(file), silent: true,