From 9c54fd60d5699a0b3f3837fa55dd9c5bb85121ee Mon Sep 17 00:00:00 2001 From: Louis Grasset Date: Sat, 4 Nov 2023 12:16:45 +0100 Subject: [PATCH 1/2] fix(cache): prevent cache creation to break old data --- src/helpers/cache/create-cache.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/helpers/cache/create-cache.ts b/src/helpers/cache/create-cache.ts index bdc9d23..5c5897a 100644 --- a/src/helpers/cache/create-cache.ts +++ b/src/helpers/cache/create-cache.ts @@ -1,17 +1,12 @@ import { access, constants } from "fs/promises"; import { CACHE_PATH, INSTANCE_ID } from "../../constants.js"; -import { getCache } from "./get-cache.js"; import { writeToCacheFile } from "./write-to-cache-file.js"; export const createCacheFile = async () => { try { // Check if the file exists await access(CACHE_PATH, constants.F_OK); - const cache = await getCache(); - if (cache.instance.id !== INSTANCE_ID) { - throw new Error(`Cache for instance ${INSTANCE_ID} not found`); - } } catch { writeToCacheFile({ version: "0.2", From 4a433ea55a74dd7fdfa959a9e9b7143062008a02 Mon Sep 17 00:00:00 2001 From: Louis Grasset Date: Sat, 4 Nov 2023 12:24:31 +0100 Subject: [PATCH 2/2] test(cache): update expectations --- src/helpers/cache/__tests__/create-cache.spec.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/helpers/cache/__tests__/create-cache.spec.ts b/src/helpers/cache/__tests__/create-cache.spec.ts index 158d523..e23594c 100644 --- a/src/helpers/cache/__tests__/create-cache.spec.ts +++ b/src/helpers/cache/__tests__/create-cache.spec.ts @@ -2,7 +2,6 @@ import { access } from "fs/promises"; import { INSTANCE_ID } from "../../../constants.js"; import { createCacheFile } from "../create-cache.js"; -import { getCache } from "../get-cache.js"; import { writeToCacheFile } from "../write-to-cache-file.js"; jest.mock("fs/promises", () => ({ @@ -19,14 +18,6 @@ jest.mock("../../../constants.js", () => { }; }); -jest.mock("../get-cache.js", () => ({ - getCache: jest.fn().mockResolvedValue({ - instance: { - id: INSTANCE_ID, - }, - }), -})); - jest.mock("../write-to-cache-file.js", () => ({ writeToCacheFile: jest.fn(), })); @@ -46,7 +37,6 @@ describe("createCache", () => { await createCacheFile(); expect(promiseAccessMock).toHaveBeenCalledTimes(1); - expect(getCache).toHaveBeenCalledTimes(1); expect(writeToCacheFile).not.toHaveBeenCalled(); }); }); @@ -60,7 +50,6 @@ describe("createCache", () => { await createCacheFile(); expect(promiseAccessMock).toHaveBeenCalledTimes(1); - expect(getCache).not.toHaveBeenCalled(); expect(writeToCacheFile).toHaveBeenCalledWith({ version: "0.2", instance: { id: INSTANCE_ID },