From 8619e2a894127de35230094c03ad32c2b15872a5 Mon Sep 17 00:00:00 2001 From: Ryan Block Date: Tue, 5 Dec 2023 19:52:25 -0800 Subject: [PATCH] Windows --- src/config/project/prefs/index.js | 10 ++++++-- test/integration/preferences-test.js | 23 +++++++++++-------- test/lib/index.js | 10 +++++++- test/unit/src/config/project/index-test.js | 11 +++++---- .../src/config/project/prefs/index-test.js | 6 +++-- 5 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/config/project/prefs/index.js b/src/config/project/prefs/index.js index 3c5dfa9..c4bab52 100644 --- a/src/config/project/prefs/index.js +++ b/src/config/project/prefs/index.js @@ -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(/^[A-Z]:\\/, '') + 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/integration/preferences-test.js b/test/integration/preferences-test.js index 9ae61b3..626bd7a 100644 --- a/test/integration/preferences-test.js +++ b/test/integration/preferences-test.js @@ -1,14 +1,17 @@ let { join } = require('path') -let { homedir } = require('os') let test = require('tape') -let sut = join(process.cwd(), 'src', 'index') -let inv = require(sut) let mockTmp = require('mock-tmp') +let cwd = process.cwd() +let testLibPath = join(cwd, 'test', 'lib') +let { getHomedir } = require(testLibPath) +let sut = join(cwd, 'src', 'index') +let inv = require(sut) -let mock = join(process.cwd(), 'test', 'mock') +let _homedir = getHomedir() +let mock = join(cwd, 'test', 'mock') let arc = '@app\nappname\n@events\nan-event' // Not using @http so we can skip ASAP filesystem checks let reset = () => mockTmp.reset() -let _testing = true, cwd +let _testing = true /** * Duplicates some unit tests as part of the larger whole integration test @@ -56,8 +59,8 @@ testing env_var_1 foo env_var_2 bar ` - let path = join(homedir(), '.prefs.arc') - cwd = mockTmp({ + let path = join(_homedir, '.prefs.arc') + let cwd = mockTmp({ 'app.arc': arc, [path]: prefsText }) @@ -198,8 +201,8 @@ staging production: null, } } - let path = join(homedir(), '.prefs.arc') - cwd = mockTmp({ + let path = join(_homedir, '.prefs.arc') + let cwd = mockTmp({ 'app.arc': arc, [path]: globalPrefsText, 'preferences.arc': localPrefsText @@ -239,7 +242,7 @@ test('Preferences validation errors', async t => { @env foo ` - cwd = mockTmp({ + let cwd = mockTmp({ 'app.arc': arc, 'prefs.arc': prefs, }) diff --git a/test/lib/index.js b/test/lib/index.js index 82e2ab2..620e3c5 100644 --- a/test/lib/index.js +++ b/test/lib/index.js @@ -1,5 +1,12 @@ +let { homedir } = require('os') let { is } = require('../../src/lib') +function getHomedir () { + let _homedir = homedir() + if (process.platform === 'win32') _homedir = _homedir.replace(/^[A-Z]:\\/, '') + return _homedir +} + function setterPluginSetup (setter, fns) { let methods = is.array(fns) ? fns : [ fns ] methods = methods.map(m => { @@ -11,5 +18,6 @@ function setterPluginSetup (setter, fns) { } module.exports = { - setterPluginSetup + getHomedir, + setterPluginSetup, } diff --git a/test/unit/src/config/project/index-test.js b/test/unit/src/config/project/index-test.js index b37ad66..88629fa 100644 --- a/test/unit/src/config/project/index-test.js +++ b/test/unit/src/config/project/index-test.js @@ -1,8 +1,9 @@ let { join } = require('path') -let { homedir } = require('os') let test = require('tape') let mockTmp = require('mock-tmp') let cwd = process.cwd() +let testLibPath = join(cwd, 'test', 'lib') +let { getHomedir } = require(testLibPath) let inventoryDefaultsPath = join(process.cwd(), 'src', 'defaults') let inventoryDefaults = require(inventoryDefaultsPath) let defaultFunctionConfigPath = join(process.cwd(), 'src', 'defaults', 'function-config') @@ -11,7 +12,9 @@ let sut = join(cwd, 'src', 'config', 'project') let getProjectConfig = require(sut) let localPrefsFile = 'prefs.arc' -let globalPrefsFile = join(homedir(), 'prefs.arc') +let _homedir = getHomedir() +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)') diff --git a/test/unit/src/config/project/prefs/index-test.js b/test/unit/src/config/project/prefs/index-test.js index 5fac341..6bba19a 100644 --- a/test/unit/src/config/project/prefs/index-test.js +++ b/test/unit/src/config/project/prefs/index-test.js @@ -1,14 +1,16 @@ let { join } = require('path') -let { homedir } = require('os') let test = require('tape') let mockTmp = require('mock-tmp') let cwd = process.cwd() +let testLibPath = join(cwd, 'test', 'lib') +let { getHomedir } = require(testLibPath) let inventoryDefaultsPath = join(cwd, 'src', 'defaults') let inventoryDefaults = require(inventoryDefaultsPath) let sut = join(cwd, 'src', 'config', 'project', 'prefs') let getPrefs = require(sut) -let path = join(homedir(), '.prefs.arc') +let _homedir = getHomedir() +let path = join(_homedir, '.prefs.arc') let reset = () => mockTmp.restore() function clean (preferences) { // Delete the meta stuff so the actual preferences match during an equality check