-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: default node path should be using
path.join
for cross platform…
… path construction
- Loading branch information
1 parent
7b1edbd
commit 27df70f
Showing
2 changed files
with
24 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,32 @@ | ||
import os from 'os'; | ||
import path from 'path'; | ||
import process from 'process'; | ||
import * as utils from '@/utils'; | ||
|
||
describe('utils', () => { | ||
test('getting default node path', () => { | ||
const homeDir = os.homedir(); | ||
const prefix = 'polykey'; | ||
const p = utils.getDefaultNodePath(); | ||
expect(p).toBeDefined(); | ||
if (process.platform === 'linux') { | ||
expect(p).toBe(`${homeDir}/.local/share/polykey`); | ||
const dataDir = process.env.XDG_DATA_HOME; | ||
if (dataDir != null) { | ||
expect(p).toBe(path.join(dataDir, prefix)); | ||
} else { | ||
expect(p).toBe(path.join(homeDir, '.local', 'share', prefix)); | ||
} | ||
} else if (process.platform === 'darwin') { | ||
expect(p).toBe(`${homeDir}/Library/Application Support/polykey`); | ||
expect(p).toBe( | ||
path.join(homeDir, 'Library', 'Application Support', 'polykey'), | ||
); | ||
} else if (process.platform === 'win32') { | ||
expect(p).toBe(`${homeDir}/AppData/Local/polykey`); | ||
const appDataDir = process.env.LOCALAPPDATA; | ||
if (appDataDir != null) { | ||
expect(p).toBe(path.join(appDataDir, prefix)); | ||
} else { | ||
expect(p).toBe(path.join(homeDir, 'AppData', 'Local', prefix)); | ||
} | ||
} | ||
}); | ||
}); |