From fe5969c261c7dbe1792262213e8779ea0f2c9660 Mon Sep 17 00:00:00 2001 From: Patrick Pircher Date: Tue, 3 Dec 2024 00:08:11 +0100 Subject: [PATCH] fix tests url --- packages/vite/src/resolver.ts | 14 ++++++++++++++ test-packages/support/testem-proxy.ts | 2 +- tests/scenarios/vite-internals-test.ts | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/resolver.ts b/packages/vite/src/resolver.ts index 002e9d593..59c90e2a7 100644 --- a/packages/vite/src/resolver.ts +++ b/packages/vite/src/resolver.ts @@ -41,6 +41,20 @@ export function resolver(): Plugin { } } }); + return () => { + server.middlewares.use((req, _res, next) => { + const base = server.config.base || '/'; + const originalUrl = req.originalUrl!.slice(base.length - 1); + if (originalUrl && originalUrl.length > 1) { + if (originalUrl?.match(/^\/tests($|\?)/)) { + req.originalUrl = `${base}tests/index.html`; + (req as any).url = `${base}tests/index.html`; + return next(); + } + } + return next(); + }); + }; }, async resolveId(source, importer, options) { diff --git a/test-packages/support/testem-proxy.ts b/test-packages/support/testem-proxy.ts index 13507afb3..2d17af165 100644 --- a/test-packages/support/testem-proxy.ts +++ b/test-packages/support/testem-proxy.ts @@ -26,7 +26,7 @@ export function testemProxy(targetURL: string) { if (url === '/testem.js' || url.startsWith('/testem/')) { return next(); } - let m = /^(\/\d+)\/tests\/index.html/.exec(url); + let m = /^(\/\d+)\/tests($|.)+/.exec(url); if (m) { url = url.slice(m[1].length); } diff --git a/tests/scenarios/vite-internals-test.ts b/tests/scenarios/vite-internals-test.ts index e95d63c19..a80ed0995 100644 --- a/tests/scenarios/vite-internals-test.ts +++ b/tests/scenarios/vite-internals-test.ts @@ -25,7 +25,7 @@ function buildViteInternalsTest(testNonColocatedTemplates: boolean, app: Project 'use strict'; module.exports = { - test_page: 'tests/index.html?hidepassed', + test_page: 'tests?hidepassed', disable_watching: true, launch_in_ci: ['Chrome'], launch_in_dev: ['Chrome'],