-
Notifications
You must be signed in to change notification settings - Fork 716
/
config-cache.test.ts
42 lines (36 loc) · 1.2 KB
/
config-cache.test.ts
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
import { mkdirSync } from "node:fs";
import { getConfigCache, saveToConfigCache } from "../config-cache";
import { mockConsoleMethods } from "./helpers/mock-console";
import { runInTempDir } from "./helpers/run-in-tmp";
interface PagesConfigCache {
account_id: string;
pages_project_name: string;
}
describe("config cache", () => {
runInTempDir();
mockConsoleMethods();
beforeEach(() => {
mkdirSync("node_modules");
});
const pagesConfigCacheFilename = "pages-config-cache.json";
it("should return an empty config if no file exists", () => {
expect(
getConfigCache<PagesConfigCache>(pagesConfigCacheFilename)
).toMatchInlineSnapshot(`Object {}`);
});
it("should read and write values without overriding old ones", () => {
saveToConfigCache<PagesConfigCache>(pagesConfigCacheFilename, {
account_id: "some-account-id",
pages_project_name: "foo",
});
expect(
getConfigCache<PagesConfigCache>(pagesConfigCacheFilename).account_id
).toEqual("some-account-id");
saveToConfigCache<PagesConfigCache>(pagesConfigCacheFilename, {
pages_project_name: "bar",
});
expect(
getConfigCache<PagesConfigCache>(pagesConfigCacheFilename).account_id
).toEqual("some-account-id");
});
});