From c8b45d593cdb96d153ea97fc82ce5128f267ea43 Mon Sep 17 00:00:00 2001 From: Matt Blank <34134349+mattblank11@users.noreply.github.com> Date: Wed, 6 Nov 2024 13:13:42 -0500 Subject: [PATCH] Update getDirectoryContentsForSnapshot --- packages/cli/ete-tests/src/tests/init/init.test.ts | 2 +- packages/commons/fs-utils/src/getDirectoryContents.ts | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/cli/ete-tests/src/tests/init/init.test.ts b/packages/cli/ete-tests/src/tests/init/init.test.ts index 10aa198295e..48e65a2d66f 100644 --- a/packages/cli/ete-tests/src/tests/init/init.test.ts +++ b/packages/cli/ete-tests/src/tests/init/init.test.ts @@ -75,6 +75,6 @@ describe("fern init", () => { additionalArgs: [{ name: "--mintlify", value: mintJsonPath }] }); - expect(await getDirectoryContentsForSnapshot(pathOfDirectory)).toMatchSnapshot(); + expect(await getDirectoryContentsForSnapshot(pathOfDirectory, { skipBinaryContents: true })).toMatchSnapshot(); }, 60_000); }); diff --git a/packages/commons/fs-utils/src/getDirectoryContents.ts b/packages/commons/fs-utils/src/getDirectoryContents.ts index 0bdc79ffb37..7c04f01c6bd 100644 --- a/packages/commons/fs-utils/src/getDirectoryContents.ts +++ b/packages/commons/fs-utils/src/getDirectoryContents.ts @@ -23,6 +23,7 @@ export interface Directory { export declare namespace getDirectoryContents { export interface Options { fileExtensions?: string[]; + skipBinaryContents?: boolean; } } @@ -80,13 +81,18 @@ export interface SnapshotDirectory { contents: SnapshotFileOrDirectory[]; } +const BINARY_EXTENSIONS = [".png", ".jpg", ".jpeg", ".gif", ".ico", ".bin"]; + export async function getDirectoryContentsForSnapshot( absolutePath: AbsoluteFilePath, - options: getDirectoryContents.Options = {} + options: getDirectoryContents.Options = { skipBinaryContents: false } ): Promise { const contents = await getDirectoryContents(absolutePath, options); const removeAbsolutePath = (fileOrDir: FileOrDirectory): SnapshotFileOrDirectory => { if (fileOrDir.type === "file") { + if (options.skipBinaryContents && BINARY_EXTENSIONS.includes(path.extname(fileOrDir.name))) { + return { type: "file", name: fileOrDir.name, contents: "" }; + } return { type: "file", name: fileOrDir.name, contents: fileOrDir.contents }; } else { return {