|
| 1 | +import useConfig, { ConfigDefault } from "../../src/hooks/useConfig.ts" |
| 2 | +import { assertEquals } from "deno/testing/asserts.ts" |
| 3 | +import { _internals } from "tea/hooks/useConfig.ts" |
| 4 | +import { Path } from "tea" |
| 5 | + |
| 6 | +Deno.test("prefix discovery", async () => { |
| 7 | + const tmp = new Path(await Deno.makeTempDir()) |
| 8 | + const tea = tmp.join("tea.xyz/v1.2.3/bin").mkdir('p').join("tea").touch() |
| 9 | + const config = ConfigDefault(undefined, tea.string, {}) |
| 10 | + assertEquals(config.prefix, tmp) |
| 11 | +}) |
| 12 | + |
| 13 | +Deno.test("prefix discovery via versioned symlink", async () => { |
| 14 | + const tmp = new Path(await Deno.makeTempDir()) |
| 15 | + const shelf = tmp.join("tea.xyz") |
| 16 | + const keg = shelf.join("v1.2.3") |
| 17 | + |
| 18 | + keg.join("bin").mkdir('p').join("tea").touch() |
| 19 | + |
| 20 | + const v1 = shelf.join("v1").ln('s', { target: keg }) |
| 21 | + const config = ConfigDefault(undefined, v1.join('bin/tea').string, {}) |
| 22 | + assertEquals(config.prefix, tmp) |
| 23 | +}) |
| 24 | + |
| 25 | +Deno.test("prefix discovery via separate symlink", async () => { |
| 26 | + const tmp = new Path(await Deno.makeTempDir()) |
| 27 | + const tea = tmp.join('tea').ln('s', { target: tmp.join("tea.xyz/v1.2.3/bin").mkdir('p').join("tea").touch() }) |
| 28 | + |
| 29 | + const config = ConfigDefault(undefined, tea.string, {}) |
| 30 | + assertEquals(config.prefix, tmp) |
| 31 | +}) |
| 32 | + |
| 33 | +Deno.test("prefix discovery defaults to ~/.tea", async () => { |
| 34 | + const tmp = new Path(await Deno.makeTempDir()) |
| 35 | + const tea = tmp.join('tea').touch() |
| 36 | + |
| 37 | + const config = ConfigDefault(undefined, tea.string, {}) |
| 38 | + assertEquals(config.prefix, Path.home().join(".tea")) |
| 39 | +}) |
0 commit comments