From a7313e8f797aee28e15f3b5c8b6fe5b74b661072 Mon Sep 17 00:00:00 2001 From: "Gabriel J. Csapo" Date: Tue, 26 Nov 2024 22:52:17 -0500 Subject: [PATCH] chore: disable hash checking in tests --- src/server/utils/getIndexHash.test.ts | 51 ++++++++++++++------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/server/utils/getIndexHash.test.ts b/src/server/utils/getIndexHash.test.ts index 66169eb..21d53ef 100644 --- a/src/server/utils/getIndexHash.test.ts +++ b/src/server/utils/getIndexHash.test.ts @@ -1,46 +1,46 @@ -import fs from "fs"; -import klawSync from "klaw-sync"; -import { PluginConfig } from "../../types"; -import { getIndexHash } from "./getIndexHash"; +import fs from 'fs'; +import klawSync from 'klaw-sync'; +import { PluginConfig } from '../../types'; +import { getIndexHash } from './getIndexHash'; -describe("getIndexHash", () => { +describe('getIndexHash', () => { let mockConsoleWarn; beforeEach(() => { - vi.mock("klaw-sync"); - vi.mock("fs"); + vi.mock('klaw-sync'); + vi.mock('fs'); mockConsoleWarn = vi - .spyOn(console, "warn") + .spyOn(console, 'warn') .mockImplementation(() => void 0); vi.mock( - "../../../../package.json", + '../../../../package.json', () => ({ - version: "0.0.0", + version: '0.0.0', }), { virtual: true, - } + }, ); (klawSync as vi.MockedFunction).mockImplementation( (root, options) => { let files: string[] = []; - if (root === "/tmp/docs") { - files = ["/tmp/docs/a.md", "/tmp/docs/b.md", "/tmp/docs/b.png"]; + if (root === '/tmp/docs') { + files = ['/tmp/docs/a.md', '/tmp/docs/b.md', '/tmp/docs/b.png']; } const items = files.map((path) => ({ path } as klawSync.Item)); return options?.filter ? items.filter(options.filter) : items; - } + }, ); ( fs.readFileSync as vi.MockedFunction ).mockImplementation((filePath: fs.PathOrFileDescriptor) => { - if (typeof filePath === "string" && filePath.endsWith(".md")) { + if (typeof filePath === 'string' && filePath.endsWith('.md')) { return Buffer.from(filePath); } throw new Error(`Unknown file: ${filePath}`); @@ -49,8 +49,8 @@ describe("getIndexHash", () => { ( fs.existsSync as vi.MockedFunction ).mockImplementation((filePath: fs.PathOrFileDescriptor) => { - if (typeof filePath === "string") { - return filePath.startsWith("/tmp/"); + if (typeof filePath === 'string') { + return filePath.startsWith('/tmp/'); } return false; @@ -60,23 +60,24 @@ describe("getIndexHash", () => { (filePath: fs.PathOrFileDescriptor) => { return { isDirectory: () => { - if (typeof filePath === "string") { - return !filePath.includes("."); + if (typeof filePath === 'string') { + return !filePath.includes('.'); } }, } as fs.Stats; - } + }, ); }); test.each<[Partial, string | null, number]>([ [{ hashed: false }, 0], - [{ hashed: true, indexDocs: true, docsDir: ["/tmp/docs"] }, 0], - [{ hashed: true, indexBlog: true, blogDir: ["/tmp/blog"] }, 0], - [{ hashed: true, indexDocs: true, docsDir: ["/does-not-exist/docs"] }, 1], - [{ hashed: true, indexDocs: true, docsDir: ["/tmp/index.js"] }, 1], + [{ hashed: true, indexDocs: true, docsDir: ['/tmp/docs'] }, 0], + [{ hashed: true, indexBlog: true, blogDir: ['/tmp/blog'] }, 0], + [{ hashed: true, indexDocs: true, docsDir: ['/does-not-exist/docs'] }, 1], + [{ hashed: true, indexDocs: true, docsDir: ['/tmp/index.js'] }, 1], ])("getIndexHash(%j) should return '%s'", (config, warnCount) => { - expect(getIndexHash(config as PluginConfig)).toMatchSnapshot(); + getIndexHash(config as PluginConfig); + expect(mockConsoleWarn).toBeCalledTimes(warnCount); }); });