From 00a9f3541024cd76baaf74c7a9db4988a3da5e62 Mon Sep 17 00:00:00 2001 From: Ari Porad Date: Sat, 19 Dec 2015 15:33:01 -0800 Subject: [PATCH 1/3] Add test to make sure that --require is relative to where `ava` is invoked, not where the test is. Refs #343. --- test/api.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/api.js b/test/api.js index dbbf7fe43..ad66e6e33 100644 --- a/test/api.js +++ b/test/api.js @@ -314,9 +314,14 @@ test('test file in node_modules is ignored', function (t) { test('Node.js-style --require CLI argument', function (t) { t.plan(1); + var requirePath = path.relative(process.cwd(), path.join(__dirname, 'fixture', 'install-global.js')); + // `path` will use \\ to seperate paths on windows, but require doesn't. + requirePath = requirePath.split(path.sep).join('/'); + requirePath = './' + requirePath; + var api = new Api( [path.join(__dirname, 'fixture/validate-installed-global.js')], - {require: [path.join(__dirname, 'fixture', 'install-global.js')]} + {require: [requirePath]} ); api.run() From 087756d1a61e6564f6487d1cd0e118ff2bd2e7a7 Mon Sep 17 00:00:00 2001 From: Ari Porad Date: Sat, 19 Dec 2015 14:50:47 -0800 Subject: [PATCH 2/3] Make --require relative to where the command is run Fixes #343. --- api.js | 3 +++ lib/babel.js | 5 +---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api.js b/api.js index f8e8937e8..f583cc642 100644 --- a/api.js +++ b/api.js @@ -9,6 +9,7 @@ var figures = require('figures'); var globby = require('globby'); var chalk = require('chalk'); var fork = require('./lib/fork'); +var resolveCwd = require('resolve-cwd'); var formatter = require('./lib/enhance-assert').formatter(); function Api(files, options) { @@ -20,6 +21,8 @@ function Api(files, options) { this.options = options || {}; + this.options.require = (this.options.require || []).map(resolveCwd); + this.rejectionCount = 0; this.exceptionCount = 0; this.passCount = 0; diff --git a/lib/babel.js b/lib/babel.js index 08fc14eb7..82a7ef9a5 100644 --- a/lib/babel.js +++ b/lib/babel.js @@ -16,10 +16,7 @@ if (debug.enabled) { // Bind globals first, before anything has a chance to interfere. var globals = require('./globals'); -var resolveCwd = require('resolve-cwd'); -(opts.require || []).forEach(function (moduleId) { - require(resolveCwd(moduleId)); -}); +(opts.require || []).forEach(require); var sourceMapCache = Object.create(null); From da0a04072b6e65188a869223c9582a092df5fbf5 Mon Sep 17 00:00:00 2001 From: Ari Porad Date: Tue, 22 Dec 2015 08:21:41 -0800 Subject: [PATCH 3/3] Don't normalize windows paths to posix in tests --- test/api.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/api.js b/test/api.js index ad66e6e33..dcf64fb20 100644 --- a/test/api.js +++ b/test/api.js @@ -315,9 +315,7 @@ test('Node.js-style --require CLI argument', function (t) { t.plan(1); var requirePath = path.relative(process.cwd(), path.join(__dirname, 'fixture', 'install-global.js')); - // `path` will use \\ to seperate paths on windows, but require doesn't. - requirePath = requirePath.split(path.sep).join('/'); - requirePath = './' + requirePath; + requirePath = '.' + path.sep + requirePath; var api = new Api( [path.join(__dirname, 'fixture/validate-installed-global.js')],