Skip to content

Commit

Permalink
Update getDirectoryContentsForSnapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
mattblank11 authored and dsinghvi committed Nov 22, 2024
1 parent 8ed04b8 commit c8b45d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/cli/ete-tests/src/tests/init/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
8 changes: 7 additions & 1 deletion packages/commons/fs-utils/src/getDirectoryContents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface Directory {
export declare namespace getDirectoryContents {
export interface Options {
fileExtensions?: string[];
skipBinaryContents?: boolean;
}
}

Expand Down Expand Up @@ -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<SnapshotFileOrDirectory[]> {
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: "<binary>" };
}
return { type: "file", name: fileOrDir.name, contents: fileOrDir.contents };
} else {
return {
Expand Down

0 comments on commit c8b45d5

Please sign in to comment.