From 2e3e4bf3cfce5875cc9d6ad851309849ae04fdae Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Thu, 10 Mar 2022 08:00:43 +0100 Subject: [PATCH] Fix wrong urls if file name contains multiple dots --- src/index.ts | 2 +- test/fixtures/typescript/files/{main-a.ts => main-a.foo.ts} | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) rename test/fixtures/typescript/files/{main-a.ts => main-a.foo.ts} (80%) diff --git a/src/index.ts b/src/index.ts index 93caf02..09c5dab 100644 --- a/src/index.ts +++ b/src/index.ts @@ -166,7 +166,7 @@ function createPreprocessor( return async function preprocess(content, file, done) { // We normalize the file extension to always be '.js', which allows us to // run '.ts' files as test entry-points in a `singleBundle: false` setup. - const jsPath = file.originalPath.replace(/\.[^/]+$/, ".js"); + const jsPath = file.originalPath.replace(/\.[^/.]+$/, ".js"); // Karma likes to turn a win32 path (C:\foo\bar) into a posix-like path (C:/foo/bar). // Normally this wouldn't be so bad, but `bundle.file` is a true win32 path, and we diff --git a/test/fixtures/typescript/files/main-a.ts b/test/fixtures/typescript/files/main-a.foo.ts similarity index 80% rename from test/fixtures/typescript/files/main-a.ts rename to test/fixtures/typescript/files/main-a.foo.ts index ed251be..ca8daa6 100644 --- a/test/fixtures/typescript/files/main-a.ts +++ b/test/fixtures/typescript/files/main-a.foo.ts @@ -13,7 +13,7 @@ describe("simple", () => { }); it("should serve with correct content-type", async () => { - const script = document.querySelector('script[src*="main-a.js"]'); + const script = document.querySelector('script[src*="main-a.foo.js"]'); const resp = await fetchPolyfill(script.src); if (resp.status !== 200) { @@ -27,9 +27,9 @@ describe("simple", () => { }); it("should serve .js.map", async () => { - const script = document.querySelector('script[src*="main-a.js"]'); + const script = document.querySelector('script[src*="main-a.foo.js"]'); - const src = `${script.src.replace(/[?#].*/, '')}.map`; + const src = `${script.src.replace(/[?#].*/, "")}.map`; const resp = await fetchPolyfill(src); if (resp.status !== 200) { throw new Error(resp.status);