diff --git a/index.js b/index.js index 50f6cd6..1ed9fd6 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +const fs = require('fs'); const util = require('util'); const path = require('path'); const EE = require('events').EventEmitter; @@ -124,7 +125,7 @@ Liftoff.prototype.buildEnvironment = function (opts) { cwd: cwd, require: preload, configNameSearch: configNameSearch, - configPath: configPath, + configPath: configPath && fs.realpathSync(configPath), // resolve symlink configBase: configBase, modulePath: modulePath, modulePackage: modulePackage||{} diff --git a/lib/find_config.js b/lib/find_config.js index 3106495..71c3f07 100644 --- a/lib/find_config.js +++ b/lib/find_config.js @@ -19,8 +19,7 @@ module.exports = function (opts) { } // confirm the configPath exists and return an absolute path to it if (fs.existsSync(configPath)) { - // traverse symlinks if needed - return fs.realpathSync(path.resolve(configPath)); + return path.resolve(configPath); } return null; }; diff --git a/test/index.js b/test/index.js index 8b3fe90..1405448 100644 --- a/test/index.js +++ b/test/index.js @@ -87,6 +87,21 @@ describe('Liftoff', function () { expect(app.buildEnvironment().cwd).to.equal(path.resolve('test/fixtures/search_path')); }); + + it('should resolve symlinks if config is one', function () { + var env = app.buildEnvironment({ + cwd: 'test/fixtures/symlink' + }); + expect(env.configPath).to.equal(path.resolve('test/fixtures/mochafile.js')); + }); + + it('should set configBase to the folder of the symlink if configPath is a symlink', function () { + var env = app.buildEnvironment({ + configPath: 'test/fixtures/symlink/mochafile.js' + }); + expect(env.cwd).to.equal(path.resolve('test/fixtures/symlink')); + }) + }); describe('launch', function () { diff --git a/test/lib/find_config.js b/test/lib/find_config.js index d171730..737d0be 100644 --- a/test/lib/find_config.js +++ b/test/lib/find_config.js @@ -27,11 +27,4 @@ describe('findConfig', function () { })).to.equal(path.resolve('test/fixtures/search_path/mochafile.js')); }); - it('should traverse symlinks', function () { - expect(findConfig({ - configNameSearch: ['mochafile.js'], - searchPaths: ['test/fixtures/symlink'] - })).to.equal(path.resolve('test/fixtures/mochafile.js')); - }); - });