Free & Open-Source Invoice Generator - No Sign-Up, No Ads, Instant PDF Export, 100% In-Browser, and Fully Customizable Templates.
TypeScript fintechinvoiceinvoice-generatorinvoice-pdfinvoice-templateinvoicesnextjsopen-sourcequotesreactreact-pdf-rendererself-hostedshadcn-uitailwindcsstypescript
feat: enhance PDF and testing configurations for WebKit support (#263)
Vlad Sazonau89ec1bd429bb
diff --git a/e2e/default-invoice-template/default-invoice-template.test.ts b/e2e/default-invoice-template/default-invoice-template.test.tsindex bd6d714..c7efbd1 100644--- a/e2e/default-invoice-template/default-invoice-template.test.ts+++ b/e2e/default-invoice-template/default-invoice-template.test.ts@@ -24,8 +24,9 @@ test.describe("Default Invoice Template", () => {"downloads PDF in English and verifies content",{// client side PDF generation + download is the most engine sensitive path- // we have, so it is part of the Gecko smoke run- tag: "@firefox-smoke",+ // we have, so it is part of both engine smoke runs. On `Desktop Safari` it is+ // also the only place the desktop preview pane renders on WebKit+ tag: ["@firefox-smoke", "@webkit-desktop-smoke"],},async ({ page, browserName, downloadDir }) => {const { suggestedFilename, numPages } = await expectPdfScreenshot(page, {diff --git a/e2e/generate-invoice-link.test.ts b/e2e/generate-invoice-link.test.tsindex 6931e72..db81b46 100644--- a/e2e/generate-invoice-link.test.ts+++ b/e2e/generate-invoice-link.test.ts@@ -49,8 +49,8 @@ test.describe("Generate Invoice Link (Get link)", () => {"can share invoice and data is persisted in new tab",{// the URL encoded/compressed invoice state round trip, a likely place for a- // Gecko vs Chromium divergence to hide- tag: "@firefox-smoke",+ // Gecko or WebKit vs Chromium divergence to hide+ tag: ["@firefox-smoke", "@webkit-desktop-smoke"],},async ({ page, context }) => {// Verify shared invoice badge is NOT visible before sharingdiff --git a/e2e/invoice-form.test.ts b/e2e/invoice-form.test.tsindex 803063a..981225d 100644--- a/e2e/invoice-form.test.ts+++ b/e2e/invoice-form.test.ts@@ -208,45 +208,60 @@ test.describe("Invoice Generator Page", () => {).toBeEnabled();});- test("handles mobile/desktop views", async ({ page }) => {- // Test mobile view- await page.setViewportSize({ width: 375, height: 667 });+ test(+ "handles mobile/desktop views",+ {+ // the `useIsDesktop` matchMedia listener swapping the mobile tabs for the+ // desktop layout, and `src/hooks/use-media-query.tsx` carries a Safari+ // specific fallback, so this runs on desktop WebKit too+ tag: "@webkit-desktop-smoke",+ },+ async ({ page }) => {+ // Test mobile view+ await page.setViewportSize({ width: 375, height: 667 });- // check that tabs are visible in mobile view- await expect(page.getByRole("tab", { name: "Edit Invoice" })).toBeVisible();- await expect(page.getByRole("tab", { name: "Preview PDF" })).toBeVisible();+ // check that tabs are visible in mobile view+ await expect(+ page.getByRole("tab", { name: "Edit Invoice" }),+ ).toBeVisible();+ await expect(+ page.getByRole("tab", { name: "Preview PDF" }),+ ).toBeVisible();- const termsOfServiceMobile = page.getByTestId(- "mobile-terms-of-service-link",- );- const termsOfServiceLinkMobile = termsOfServiceMobile.getByRole("link");+ const termsOfServiceMobile = page.getByTestId(+ "mobile-terms-of-service-link",+ );+ const termsOfServiceLinkMobile = termsOfServiceMobile.getByRole("link");- // Check that Terms of Service are displayed- await expect(termsOfServiceMobile).toBeVisible();- await expect(termsOfServiceMobile).toHaveText(- "By using this tool, you agree to the Terms of Service",- );- await expect(termsOfServiceLinkMobile).toHaveAttribute("href", "/tos");+ // Check that Terms of Service are displayed+ await expect(termsOfServiceMobile).toBeVisible();+ await expect(termsOfServiceMobile).toHaveText(+ "By using this tool, you agree to the Terms of Service",+ );+ await expect(termsOfServiceLinkMobile).toHaveAttribute("href", "/tos");- // Test desktop view- await page.setViewportSize({ width: 1280, height: 800 });+ // Test desktop view+ await page.setViewportSize({ width: 1280, height: 800 });- // check that tabs are not visible in desktop view- await expect(page.getByRole("tab", { name: "Edit Invoice" })).toBeHidden();- await expect(page.getByRole("tab", { name: "Preview PDF" })).toBeHidden();+ // check that tabs are not visible in desktop view+ await expect(+ page.getByRole("tab", { name: "Edit Invoice" }),+ ).toBeHidden();+ await expect(page.getByRole("tab", { name: "Preview PDF" })).toBeHidden();- const termsOfServiceDesktop = page.getByTestId(- "desktop-terms-of-service-link",- );- const termsOfServiceLinkDesktop = termsOfServiceDesktop.getByRole("link");+ const termsOfServiceDesktop = page.getByTestId(+ "desktop-terms-of-service-link",+ );+ const termsOfServiceLinkDesktop = termsOfServiceDesktop.getByRole("link");- // Check that Terms of Service are displayed- await expect(termsOfServiceDesktop).toBeVisible();- await expect(termsOfServiceDesktop).toHaveText(- "By using this tool, you agree to the Terms of Service",- );- await expect(termsOfServiceLinkDesktop).toHaveAttribute("href", "/tos");- });+ // Check that Terms of Service are displayed+ await expect(termsOfServiceDesktop).toBeVisible();+ await expect(termsOfServiceDesktop).toHaveText(+ "By using this tool, you agree to the Terms of Service",+ );+ await expect(termsOfServiceLinkDesktop).toHaveAttribute("href", "/tos");+ },+ );test("keeps a form edit made right before switching to the preview tab", async ({page,@@ -1137,8 +1152,9 @@ test.describe("Invoice Generator Page", () => {test("persists data in local storage",{- // form state -> localStorage -> rehydrate on reload, verified on Gecko too- tag: "@firefox-smoke",+ // form state -> localStorage -> rehydrate on reload, verified on Gecko and+ // desktop WebKit too+ tag: ["@firefox-smoke", "@webkit-desktop-smoke"],},async ({ page }) => {// Fill in some datadiff --git a/next.config.mjs b/next.config.mjsindex aa61663..28f74f5 100644--- a/next.config.mjs+++ b/next.config.mjs@@ -136,6 +136,12 @@ const withMDX = createMDX({/** @type {import('next').NextConfig} */const nextConfig = {+ // pdfjs-dist ships untranspiled ES2022 (static init blocks, private static+ // methods). Next does not compile node_modules, so the chunk reaches the+ // browser as-is and any Safari < 16.4 dies parsing it with+ // "SyntaxError: Unexpected token '{'". Running it through SWC with our+ // browser targets lowers that syntax.+ transpilePackages: ["pdfjs-dist"],// Configure the file extensions that Next.js should handlepageExtensions: ["ts", "tsx", "js", "jsx", "md", "mdx"],compiler: {diff --git a/playwright.config.ts b/playwright.config.tsindex b0a5a61..5d85e4e 100644--- a/playwright.config.ts+++ b/playwright.config.ts@@ -138,6 +138,35 @@ export default defineConfig({},},+ /**+ * Desktop WebKit smoke coverage.+ *+ * `Mobile Safari` already runs WebKit, but only ever below the 1024px+ * breakpoint that `useIsDesktop` (`src/hooks/use-media-query.tsx`) switches on,+ * so it exercises the mobile tab layout and never the desktop one. This project+ * is the only place the desktop code path runs on WebKit: the shared `usePDF`+ * preview pane next to the form, the download link, and the `matchMedia`+ * listener that flips between the two layouts.+ *+ * Scoped with `grep` to the tests tagged `@webkit-desktop-smoke` instead of the+ * full suite, exactly like `Desktop Firefox` above.+ *+ * NOTE: no `channel` and no `launchOptions.args` here - those are Chromium+ * only. Clipboard permissions are omitted too, like on `Mobile Safari`.+ *+ * Visual snapshots are never compared on this project, see+ * DEFAULT_SNAPSHOT_PROJECT in `e2e/utils/pdf-download.ts`, so it needs no+ * screenshot baselines of its own.+ */+ {+ name: "Desktop Safari",+ grep: /@webkit-desktop-smoke/,+ use: {+ ...devices["Desktop Safari"],+ storageState: STORAGE_STATE,+ },+ },+// /* Test against mobile viewports. */{name: "Mobile Chrome",