diff --git a/src/config/project/prefs/index.js b/src/config/project/prefs/index.js index 3c5dfa9..3e827d1 100644 --- a/src/config/project/prefs/index.js +++ b/src/config/project/prefs/index.js @@ -1,4 +1,4 @@ -let { join } = require('path') +let { join, parse: parsePath } = require('path') let { existsSync, readFileSync } = require('fs') let read = require('../../../read') let validate = require('../validate') @@ -7,11 +7,17 @@ let { parse } = require('./dotenv') let { homedir } = require('os') module.exports = function getPrefs ({ scope, inventory, errors, _testing }) { - /* istanbul ignore next */ let cwd = scope === 'global' - ? _testing ? join(inventory._project.cwd, homedir()) : homedir() + ? homedir() : inventory._project.cwd + /* istanbul ignore next */ + if (_testing && scope === 'global') { + let _homedir = homedir() + if (process.platform === 'win32') _homedir = _homedir.replace(parsePath(cwd).root, '') + cwd = join(inventory._project.cwd, _homedir) + } + let envFilepath = join(cwd, '.env') let hasEnvFile = scope === 'local' && existsSync(envFilepath) let prefs = read({ type: 'preferences', cwd, errors }) diff --git a/test/unit/src/config/project/index-test.js b/test/unit/src/config/project/index-test.js index b37ad66..e4f5f13 100644 --- a/test/unit/src/config/project/index-test.js +++ b/test/unit/src/config/project/index-test.js @@ -1,4 +1,4 @@ -let { join } = require('path') +let { join, parse } = require('path') let { homedir } = require('os') let test = require('tape') let mockTmp = require('mock-tmp') @@ -11,7 +11,10 @@ let sut = join(cwd, 'src', 'config', 'project') let getProjectConfig = require(sut) let localPrefsFile = 'prefs.arc' -let globalPrefsFile = join(homedir(), 'prefs.arc') +let _homedir = homedir() +if (process.platform === 'win32') _homedir = _homedir.replace(parse(cwd).root, '') +let globalPrefsFile = join(_homedir, 'prefs.arc') +let _testing = true test('Set up env', t => { t.plan(1) @@ -99,7 +102,7 @@ useAWS true` [globalPrefsFile]: globalPrefs }) inventory = inventoryDefaults({ cwd }) - proj = getProjectConfig({ arc, errors, inventory, _testing: true }) + proj = getProjectConfig({ arc, errors, inventory, _testing }) t.equal(errors.length, 0, 'Did not error') t.ok(proj.preferences, 'Populated preferences') t.equal(proj.preferences.env.testing.fiz, 'buz', 'Populated testing env') @@ -117,7 +120,7 @@ useAWS true` [globalPrefsFile]: globalPrefs, }) inventory = inventoryDefaults({ cwd }) - proj = getProjectConfig({ arc, errors, inventory, _testing: true }) + proj = getProjectConfig({ arc, errors, inventory, _testing }) t.equal(errors.length, 0, 'Did not error') t.ok(proj.preferences, 'Populated preferences') t.equal(proj.preferences.env.testing.foo, 'bar', 'Populated testing env (preferred local to global prefs)')