Skip to content

Commit

Permalink
Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanblock committed Dec 6, 2023
1 parent 8b1fe31 commit 8619e2a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 19 deletions.
10 changes: 8 additions & 2 deletions src/config/project/prefs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
23 changes: 13 additions & 10 deletions test/integration/preferences-test.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
})
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -239,7 +242,7 @@ test('Preferences validation errors', async t => {
@env
foo
`
cwd = mockTmp({
let cwd = mockTmp({
'app.arc': arc,
'prefs.arc': prefs,
})
Expand Down
10 changes: 9 additions & 1 deletion test/lib/index.js
Original file line number Diff line number Diff line change
@@ -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 => {
Expand All @@ -11,5 +18,6 @@ function setterPluginSetup (setter, fns) {
}

module.exports = {
setterPluginSetup
getHomedir,
setterPluginSetup,
}
11 changes: 7 additions & 4 deletions test/unit/src/config/project/index-test.js
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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)
Expand Down Expand Up @@ -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')
Expand All @@ -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)')
Expand Down
6 changes: 4 additions & 2 deletions test/unit/src/config/project/prefs/index-test.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 8619e2a

Please sign in to comment.