From 9d977fff12c72cff8fadf959f77e02f64305af59 Mon Sep 17 00:00:00 2001 From: Jamie Blair Date: Tue, 19 Nov 2024 17:02:37 +0000 Subject: [PATCH] chore: code review tidy + better error messages --- scripts/dev/curriculum/_commands/helpers.test.ts | 4 ++-- scripts/dev/curriculum/_commands/helpers.ts | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/dev/curriculum/_commands/helpers.test.ts b/scripts/dev/curriculum/_commands/helpers.test.ts index fb45eb7ba3..b35980cecf 100644 --- a/scripts/dev/curriculum/_commands/helpers.test.ts +++ b/scripts/dev/curriculum/_commands/helpers.test.ts @@ -9,10 +9,10 @@ describe("wrapHtmlLayout", () => { describe("outputPathFromLabel", () => { it("should work with valid label", () => { expect(resolveInputPath(":foo")).toEqual( - `${process.cwd()}/scripts/dev/curriculum/output/screenshots/foo/`, + `${process.cwd()}/scripts/dev/curriculum/output/screenshots/foo`, ); expect(resolveInputPath(":foo")).toEqual( - `${process.cwd()}/scripts/dev/curriculum/output/screenshots/foo/`, + `${process.cwd()}/scripts/dev/curriculum/output/screenshots/foo`, ); }); diff --git a/scripts/dev/curriculum/_commands/helpers.ts b/scripts/dev/curriculum/_commands/helpers.ts index e090492644..53a1ebfc93 100644 --- a/scripts/dev/curriculum/_commands/helpers.ts +++ b/scripts/dev/curriculum/_commands/helpers.ts @@ -1,4 +1,5 @@ import { readFile, unlink } from "fs/promises"; +import { join } from "path"; import { Page } from "puppeteer"; import sharp from "sharp"; @@ -91,7 +92,7 @@ export function wrapHtmlLayout(content: string) { export function resolveInputPath(input: string) { if (input.startsWith(":")) { const labelName = input.replace(/^:/, ""); - return `${BASE_PATH}/screenshots/${labelName}/`; + return join(BASE_PATH, "screenshots", labelName); } else { return input; } @@ -116,7 +117,7 @@ export function renderComparison( after: Comparison | null, ) { if (!before || !after) { - throw new Error("Missing"); + throw new Error("Missing data, both comparison objects are empty"); } const slug = before?.slug ?? after?.slug; @@ -212,7 +213,7 @@ export async function screenshotPageCurrent(page: Page, path: string) { } if (images.length < 1) { - throw new Error("Missing"); + throw new Error("Something went wrong, no images generated"); } for (let i = 0; i < images.length; i++) {