diff --git a/api.js b/api.js index f8e8937e8..98128c973 100644 --- a/api.js +++ b/api.js @@ -8,6 +8,7 @@ var Promise = require('bluebird'); var figures = require('figures'); var globby = require('globby'); var chalk = require('chalk'); +var resolveCwd = require('resolve-cwd'); var fork = require('./lib/fork'); var formatter = require('./lib/enhance-assert').formatter(); @@ -19,6 +20,7 @@ function Api(files, options) { EventEmitter.call(this); this.options = options || {}; + this.options.require = (this.options.require || []).map(resolveCwd); this.rejectionCount = 0; this.exceptionCount = 0; diff --git a/lib/babel.js b/lib/babel.js index 5e9a140bb..a88870cc0 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); diff --git a/test/api.js b/test/api.js index dbbf7fe43..be2081152 100644 --- a/test/api.js +++ b/test/api.js @@ -314,9 +314,11 @@ 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('.', path.join(__dirname, 'fixture/install-global.js')).replace(/\\/g, '/'); + var api = new Api( [path.join(__dirname, 'fixture/validate-installed-global.js')], - {require: [path.join(__dirname, 'fixture', 'install-global.js')]} + {require: [requirePath]} ); api.run()