From fdc05bb42e535398c3eb2ac8ab78e62203cdaab0 Mon Sep 17 00:00:00 2001 From: Ryan Turnquist Date: Thu, 4 Apr 2024 11:08:45 -0700 Subject: [PATCH] fix: test snapshot hash replacement --- .../src/components/class-component.marko | 11 +++-------- .../src/components/read-head.marko | 8 +++++--- src/__tests__/main.test.ts | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/__tests__/fixtures/isomorphic-modulepreload/src/components/class-component.marko b/src/__tests__/fixtures/isomorphic-modulepreload/src/components/class-component.marko index 65914b5..b651b0d 100644 --- a/src/__tests__/fixtures/isomorphic-modulepreload/src/components/class-component.marko +++ b/src/__tests__/fixtures/isomorphic-modulepreload/src/components/class-component.marko @@ -1,10 +1,9 @@ import logo from "./logo.svg"; - class { onCreate() { this.state = { clickCount: 0, - mounted: false + mounted: false, }; } onMount() { @@ -16,10 +15,6 @@ class { } } - - Mounted: ${state.mounted} - Clicks: ${state.clickCount} - - LOGO_PATH: ${logo.replace(/-[a-z0-9]+(\.\w+)$/i, '-[hash]$1')} - ENV: ${import.meta.env.BASE_URL} +
+ Mounted: ${state.mounted} Clicks: ${state.clickCount} LOGO_PATH: ${logo} ENV: ${import.meta.env.BASE_URL}
diff --git a/src/__tests__/fixtures/isomorphic-modulepreload/src/components/read-head.marko b/src/__tests__/fixtures/isomorphic-modulepreload/src/components/read-head.marko index ab60eec..fdf288f 100644 --- a/src/__tests__/fixtures/isomorphic-modulepreload/src/components/read-head.marko +++ b/src/__tests__/fixtures/isomorphic-modulepreload/src/components/read-head.marko @@ -1,14 +1,16 @@ class { onCreate() { this.state = { - modulePreloads: [] + modulePreloads: [], }; } onMount() { - this.state.modulePreloads = document.querySelectorAll('link[rel="modulepreload"]'); + this.state.modulePreloads = document.querySelectorAll( + 'link[rel="modulepreload"]', + ); } } -
PRELOAD: ${new URL(link.href).pathname.replace(/-[a-z0-9]+(\.\w+)$/i, '-[hash]$1')}
+
PRELOAD: ${new URL(link.href).pathname}
diff --git a/src/__tests__/main.test.ts b/src/__tests__/main.test.ts index 616926e..9ae6fa9 100644 --- a/src/__tests__/main.test.ts +++ b/src/__tests__/main.test.ts @@ -52,7 +52,7 @@ before(async () => { const formatted = defaultSerializer( defaultNormalizer(JSDOM.fragment(html)), ) - .replace(/-[a-z0-9_]+(\.\w+)/gi, "-[hash]$1") + .replace(/-[a-z0-9_-]+(\.\w+)/gi, "-[hash]$1") .replace(/[?&][tv]=[\d.]+/, ""); if (changes.at(-1) !== formatted) {