Add custom path support for cli/tui in terminal config
This commit is contained in:
@@ -12,6 +12,20 @@ import {
|
||||
} from "../../src/utils/paths";
|
||||
|
||||
describe("paths utilities", () => {
|
||||
const originalConfigDir = process.env["XO_CONFIG_DIR"];
|
||||
|
||||
beforeEach(() => {
|
||||
delete process.env["XO_CONFIG_DIR"];
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
if (originalConfigDir === undefined) {
|
||||
delete process.env["XO_CONFIG_DIR"];
|
||||
} else {
|
||||
process.env["XO_CONFIG_DIR"] = originalConfigDir;
|
||||
}
|
||||
});
|
||||
|
||||
describe("getConfigDir", () => {
|
||||
test("returns path under ~/.config/xo-cli", () => {
|
||||
const configDir = getConfigDir();
|
||||
@@ -24,6 +38,26 @@ describe("paths utilities", () => {
|
||||
|
||||
expect(existsSync(configDir)).toBe(true);
|
||||
});
|
||||
|
||||
test("uses XO_CONFIG_DIR when configured", () => {
|
||||
const customDir = path.join(tmpdir(), `xo-cli-config-test-${Date.now()}`);
|
||||
process.env["XO_CONFIG_DIR"] = customDir;
|
||||
|
||||
try {
|
||||
expect(getConfigDir()).toBe(customDir);
|
||||
expect(getMnemonicsDir()).toBe(path.join(customDir, "mnemonics"));
|
||||
expect(getDataDir()).toBe(path.join(customDir, "data"));
|
||||
expect(getWalletConfigPath()).toBe(path.join(customDir, ".wallet"));
|
||||
} finally {
|
||||
rmSync(customDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("uses the default when XO_CONFIG_DIR is empty", () => {
|
||||
process.env["XO_CONFIG_DIR"] = "";
|
||||
|
||||
expect(getConfigDir()).toBe(path.join(homedir(), ".config", "xo-cli"));
|
||||
});
|
||||
});
|
||||
|
||||
describe("getMnemonicsDir", () => {
|
||||
@@ -106,6 +140,7 @@ describe("paths utilities", () => {
|
||||
});
|
||||
|
||||
test("resolves from global mnemonics dir when file exists there", () => {
|
||||
process.env["XO_CONFIG_DIR"] = tempDir;
|
||||
const mnemonicsDir = getMnemonicsDir();
|
||||
const testFile = path.join(mnemonicsDir, "mnemonic-global-test");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user