Skip to content

Commit befdbbb

Browse files
committed
Fix usePantry().missing
Refs pkgxdev/pkgx#664
1 parent 7b0b0fc commit befdbbb

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

src/hooks/usePantry.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assert, assertEquals } from "deno/testing/asserts.ts"
1+
import { assert, assertEquals, assertFalse } from "deno/testing/asserts.ts"
22
import { useTestConfig } from "./useTestConfig.ts"
33
import { _internals } from "../utils/host.ts"
44
import { stub } from "deno/testing/mock.ts"
@@ -47,3 +47,13 @@ Deno.test("runtime.env", async () => {
4747

4848
_config_internals.reset()
4949
})
50+
51+
Deno.test("missing()", () => {
52+
useTestConfig({TEA_PANTRY_PATH: "/a"})
53+
assert(usePantry().missing())
54+
})
55+
56+
Deno.test("!missing()", () => {
57+
useTestConfig()
58+
assertFalse(usePantry().missing())
59+
})

src/hooks/usePantry.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,17 @@ export default function usePantry() {
181181
return undefined
182182
}
183183

184-
const missing = () => !pantry_paths().some(x => x.exists())
184+
const missing = () => {
185+
try {
186+
return !pantry_paths().some(x => x.exists())
187+
} catch (e) {
188+
if (e instanceof PantryNotFoundError) {
189+
return false
190+
} else {
191+
throw e
192+
}
193+
}
194+
}
185195

186196
const neglected = () => {
187197
if (!prefix.exists()) return true

0 commit comments

Comments
 (0)