From 75f10535e7a4648ac49f3393b458e251a342e490 Mon Sep 17 00:00:00 2001 From: Ryan Block Date: Tue, 5 Dec 2023 19:47:47 -0800 Subject: [PATCH] Windows. Please. --- test/integration/preferences-test.js | 23 +++++++++++-------- test/lib/index.js | 10 +++++++- test/unit/src/config/project/index-test.js | 12 +++------- .../src/config/project/prefs/index-test.js | 6 +++-- 4 files changed, 29 insertions(+), 22 deletions(-) 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 3affaa2..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,14 +12,7 @@ let sut = join(cwd, 'src', 'config', 'project') let getProjectConfig = require(sut) let localPrefsFile = 'prefs.arc' -let _homedir = homedir() -// TODO ↓ remove me! ↓ -console.log(`_homedir:`, _homedir) -// TODO ↓ remove me! ↓ -console.log(`cwd:`, cwd) -if (process.platform === 'win32') _homedir = _homedir.replace(/^[A-Z]:\\/, '') -// TODO ↓ remove me! ↓ -console.log(`_homedir:`, _homedir) +let _homedir = getHomedir() let globalPrefsFile = join(_homedir, 'prefs.arc') let _testing = true 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