-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathopen-nudge.test.ts
More file actions
70 lines (60 loc) · 2.05 KB
/
Copy pathopen-nudge.test.ts
File metadata and controls
70 lines (60 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { access } from "node:fs/promises";
import { mkdtemp, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { maybeNudgeOpen, OPEN_NUDGE_HINT } from "../src/lib/open-nudge.js";
const cleanupPaths: string[] = [];
afterEach(async () => {
while (cleanupPaths.length > 0) {
const path = cleanupPaths.pop();
if (!path) continue;
await rm(path, { recursive: true, force: true });
}
});
async function freshCacheFile(): Promise<string> {
const dir = await mkdtemp(join(tmpdir(), "browse-open-nudge-"));
cleanupPaths.push(dir);
return join(dir, "open-nudge.json");
}
const enabledEnv: NodeJS.ProcessEnv = { NODE_ENV: "development", CI: "" };
describe("maybeNudgeOpen", () => {
it("returns the hint once, then honors the install marker", async () => {
const cacheFile = await freshCacheFile();
expect(await maybeNudgeOpen({ cacheFile }, enabledEnv)).toBe(
OPEN_NUDGE_HINT,
);
await expect(access(cacheFile)).resolves.toBeUndefined();
expect(await maybeNudgeOpen({ cacheFile }, enabledEnv)).toBeNull();
});
it("respects BROWSE_DISABLE_OPEN_NUDGE and BB_DISABLE_OPEN_NUDGE", async () => {
const cacheFile = await freshCacheFile();
expect(
await maybeNudgeOpen(
{ cacheFile },
{ ...enabledEnv, BROWSE_DISABLE_OPEN_NUDGE: "1" },
),
).toBeNull();
expect(
await maybeNudgeOpen(
{ cacheFile },
{ ...enabledEnv, BB_DISABLE_OPEN_NUDGE: "1" },
),
).toBeNull();
});
it("does not nudge in CI or test environments", async () => {
const cacheFile = await freshCacheFile();
expect(
await maybeNudgeOpen(
{ cacheFile },
{ NODE_ENV: "development", CI: "true" },
),
).toBeNull();
expect(
await maybeNudgeOpen({ cacheFile }, { NODE_ENV: "test", CI: "" }),
).toBeNull();
});
it("returns null when no cache file is configured", async () => {
expect(await maybeNudgeOpen({}, enabledEnv)).toBeNull();
});
});