fix(test): stabilize opencode command dir assertions across environments
This commit is contained in:
@@ -1,34 +1,43 @@
|
|||||||
import { describe, expect, it, mock, beforeEach, afterEach } from "bun:test"
|
import { describe, expect, it, mock, beforeEach, afterEach } from "bun:test"
|
||||||
import { join } from "node:path"
|
import { resolve } from "node:path"
|
||||||
|
|
||||||
describe("opencode-command-dirs", () => {
|
describe("opencode-command-dirs", () => {
|
||||||
let originalEnv: string | undefined
|
let originalOpencodeConfigDir: string | undefined
|
||||||
|
let originalXdgConfigHome: string | undefined
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
originalEnv = process.env.OPENCODE_CONFIG_DIR
|
originalOpencodeConfigDir = process.env.OPENCODE_CONFIG_DIR
|
||||||
|
originalXdgConfigHome = process.env.XDG_CONFIG_HOME
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
if (originalEnv !== undefined) {
|
if (originalOpencodeConfigDir !== undefined) {
|
||||||
process.env.OPENCODE_CONFIG_DIR = originalEnv
|
process.env.OPENCODE_CONFIG_DIR = originalOpencodeConfigDir
|
||||||
} else {
|
} else {
|
||||||
delete process.env.OPENCODE_CONFIG_DIR
|
delete process.env.OPENCODE_CONFIG_DIR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (originalXdgConfigHome !== undefined) {
|
||||||
|
process.env.XDG_CONFIG_HOME = originalXdgConfigHome
|
||||||
|
} else {
|
||||||
|
delete process.env.XDG_CONFIG_HOME
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("getOpenCodeSkillDirs", () => {
|
describe("getOpenCodeSkillDirs", () => {
|
||||||
describe("#given config dir inside profiles/", () => {
|
describe("#given config dir inside profiles/", () => {
|
||||||
describe("#when getOpenCodeSkillDirs is called", () => {
|
describe("#when getOpenCodeSkillDirs is called", () => {
|
||||||
it("#then returns both profile and parent skill dirs", async () => {
|
it("#then returns both profile and parent skill dirs", async () => {
|
||||||
|
process.env.XDG_CONFIG_HOME = "/home/user/.config"
|
||||||
process.env.OPENCODE_CONFIG_DIR = "/home/user/.config/opencode/profiles/opus"
|
process.env.OPENCODE_CONFIG_DIR = "/home/user/.config/opencode/profiles/opus"
|
||||||
|
|
||||||
const { getOpenCodeSkillDirs } = await import("./opencode-command-dirs")
|
const { getOpenCodeSkillDirs } = await import("./opencode-command-dirs")
|
||||||
const dirs = getOpenCodeSkillDirs({ binary: "opencode" })
|
const dirs = getOpenCodeSkillDirs({ binary: "opencode" })
|
||||||
|
|
||||||
expect(dirs).toContain("/home/user/.config/opencode/profiles/opus/skills")
|
expect(dirs).toContain(resolve("/home/user/.config/opencode/profiles/opus/skills"))
|
||||||
expect(dirs).toContain("/home/user/.config/opencode/profiles/opus/skill")
|
expect(dirs).toContain(resolve("/home/user/.config/opencode/profiles/opus/skill"))
|
||||||
expect(dirs).toContain("/home/user/.config/opencode/skill")
|
expect(dirs).toContain(resolve("/home/user/.config/opencode/skill"))
|
||||||
expect(dirs).toContain("/home/user/.config/opencode/skills")
|
expect(dirs).toContain(resolve("/home/user/.config/opencode/skills"))
|
||||||
expect(dirs).toHaveLength(4)
|
expect(dirs).toHaveLength(4)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -37,13 +46,14 @@ describe("opencode-command-dirs", () => {
|
|||||||
describe("#given config dir NOT inside profiles/", () => {
|
describe("#given config dir NOT inside profiles/", () => {
|
||||||
describe("#when getOpenCodeSkillDirs is called", () => {
|
describe("#when getOpenCodeSkillDirs is called", () => {
|
||||||
it("#then returns only the config dir skills", async () => {
|
it("#then returns only the config dir skills", async () => {
|
||||||
|
process.env.XDG_CONFIG_HOME = "/home/user/.config"
|
||||||
process.env.OPENCODE_CONFIG_DIR = "/home/user/.config/opencode"
|
process.env.OPENCODE_CONFIG_DIR = "/home/user/.config/opencode"
|
||||||
|
|
||||||
const { getOpenCodeSkillDirs } = await import("./opencode-command-dirs")
|
const { getOpenCodeSkillDirs } = await import("./opencode-command-dirs")
|
||||||
const dirs = getOpenCodeSkillDirs({ binary: "opencode" })
|
const dirs = getOpenCodeSkillDirs({ binary: "opencode" })
|
||||||
|
|
||||||
expect(dirs).toContain("/home/user/.config/opencode/skills")
|
expect(dirs).toContain(resolve("/home/user/.config/opencode/skills"))
|
||||||
expect(dirs).toContain("/home/user/.config/opencode/skill")
|
expect(dirs).toContain(resolve("/home/user/.config/opencode/skill"))
|
||||||
expect(dirs).toHaveLength(2)
|
expect(dirs).toHaveLength(2)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -54,15 +64,16 @@ describe("opencode-command-dirs", () => {
|
|||||||
describe("#given config dir inside profiles/", () => {
|
describe("#given config dir inside profiles/", () => {
|
||||||
describe("#when getOpenCodeCommandDirs is called", () => {
|
describe("#when getOpenCodeCommandDirs is called", () => {
|
||||||
it("#then returns both profile and parent command dirs", async () => {
|
it("#then returns both profile and parent command dirs", async () => {
|
||||||
|
process.env.XDG_CONFIG_HOME = "/home/user/.config"
|
||||||
process.env.OPENCODE_CONFIG_DIR = "/home/user/.config/opencode/profiles/opus"
|
process.env.OPENCODE_CONFIG_DIR = "/home/user/.config/opencode/profiles/opus"
|
||||||
|
|
||||||
const { getOpenCodeCommandDirs } = await import("./opencode-command-dirs")
|
const { getOpenCodeCommandDirs } = await import("./opencode-command-dirs")
|
||||||
const dirs = getOpenCodeCommandDirs({ binary: "opencode" })
|
const dirs = getOpenCodeCommandDirs({ binary: "opencode" })
|
||||||
|
|
||||||
expect(dirs).toContain("/home/user/.config/opencode/profiles/opus/commands")
|
expect(dirs).toContain(resolve("/home/user/.config/opencode/profiles/opus/commands"))
|
||||||
expect(dirs).toContain("/home/user/.config/opencode/profiles/opus/command")
|
expect(dirs).toContain(resolve("/home/user/.config/opencode/profiles/opus/command"))
|
||||||
expect(dirs).toContain("/home/user/.config/opencode/commands")
|
expect(dirs).toContain(resolve("/home/user/.config/opencode/commands"))
|
||||||
expect(dirs).toContain("/home/user/.config/opencode/command")
|
expect(dirs).toContain(resolve("/home/user/.config/opencode/command"))
|
||||||
expect(dirs).toHaveLength(4)
|
expect(dirs).toHaveLength(4)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user