diff --git a/e2e/e2e-utils/src/index.ts b/e2e/e2e-utils/src/index.ts index 70a37f4c234..43f7c837990 100644 --- a/e2e/e2e-utils/src/index.ts +++ b/e2e/e2e-utils/src/index.ts @@ -1,2 +1,4 @@ export { derivePort } from './derivePort' export { localDummyServer } from './localDummyServer' +export { toRuntimePath } from './to-runtime-path' +export { resolveRuntimeSuffix } from './resolve-runtime-suffix' diff --git a/e2e/e2e-utils/src/resolve-runtime-suffix.ts b/e2e/e2e-utils/src/resolve-runtime-suffix.ts new file mode 100644 index 00000000000..3f30ed70b32 --- /dev/null +++ b/e2e/e2e-utils/src/resolve-runtime-suffix.ts @@ -0,0 +1,13 @@ +/** + * Resolves the runtime suffix based on the provided input or the environment variable `VITE_APP_HISTORY`. + * + * @param {string} [input] - Optional input to override the environment variable. + * @returns {string} Returns 'hash' if the input or `VITE_APP_HISTORY` is set to 'hash', otherwise returns 'browser'. + */ +export function resolveRuntimeSuffix(input?: string): string { + const value = + input === 'hash' || process.env.VITE_APP_HISTORY === 'hash' + ? 'hash' + : 'browser' + return value +} diff --git a/e2e/e2e-utils/src/to-runtime-path.ts b/e2e/e2e-utils/src/to-runtime-path.ts new file mode 100644 index 00000000000..72609cf0ac8 --- /dev/null +++ b/e2e/e2e-utils/src/to-runtime-path.ts @@ -0,0 +1,17 @@ +/** + * Converts the given input string to a valid runtime path based on the environment configuration. + * If the environment variable `VITE_APP_HISTORY` is set to 'hash', the input will be prefixed with `/#`. + * Otherwise, the input will be returned as is. + * + * @param {string} input - The input string to be converted. + * @returns {string} - The converted test URL value. + * @example + * toRuntimePath('/normal-page') // '/normal-page' + * // or + * process.env.VITE_APP_HISTORY = 'hash' + * toRuntimePath('/normal-page') // '/#/normal-page' + */ +export function toRuntimePath(input: string) { + const value = process.env.VITE_APP_HISTORY === 'hash' ? `/#${input}` : input + return value +} diff --git a/e2e/react-router/basic-esbuild-file-based/.gitignore b/e2e/react-router/basic-esbuild-file-based/.gitignore index a6ea47e5085..4d2da67b504 100644 --- a/e2e/react-router/basic-esbuild-file-based/.gitignore +++ b/e2e/react-router/basic-esbuild-file-based/.gitignore @@ -1,6 +1,7 @@ node_modules .DS_Store dist +dist-hash dist-ssr *.local diff --git a/e2e/react-router/basic-file-based-code-splitting/.gitignore b/e2e/react-router/basic-file-based-code-splitting/.gitignore index a6ea47e5085..4d2da67b504 100644 --- a/e2e/react-router/basic-file-based-code-splitting/.gitignore +++ b/e2e/react-router/basic-file-based-code-splitting/.gitignore @@ -1,6 +1,7 @@ node_modules .DS_Store dist +dist-hash dist-ssr *.local diff --git a/e2e/react-router/basic-file-based/.gitignore b/e2e/react-router/basic-file-based/.gitignore index a6ea47e5085..4d2da67b504 100644 --- a/e2e/react-router/basic-file-based/.gitignore +++ b/e2e/react-router/basic-file-based/.gitignore @@ -1,6 +1,7 @@ node_modules .DS_Store dist +dist-hash dist-ssr *.local diff --git a/e2e/react-router/basic-react-query-file-based/.gitignore b/e2e/react-router/basic-react-query-file-based/.gitignore index a6ea47e5085..4d2da67b504 100644 --- a/e2e/react-router/basic-react-query-file-based/.gitignore +++ b/e2e/react-router/basic-react-query-file-based/.gitignore @@ -1,6 +1,7 @@ node_modules .DS_Store dist +dist-hash dist-ssr *.local diff --git a/e2e/react-router/basic-react-query/.gitignore b/e2e/react-router/basic-react-query/.gitignore index a6ea47e5085..4d2da67b504 100644 --- a/e2e/react-router/basic-react-query/.gitignore +++ b/e2e/react-router/basic-react-query/.gitignore @@ -1,6 +1,7 @@ node_modules .DS_Store dist +dist-hash dist-ssr *.local diff --git a/e2e/react-router/basic-scroll-restoration/.gitignore b/e2e/react-router/basic-scroll-restoration/.gitignore index 8354e4d50d5..218ef7614ba 100644 --- a/e2e/react-router/basic-scroll-restoration/.gitignore +++ b/e2e/react-router/basic-scroll-restoration/.gitignore @@ -1,6 +1,7 @@ node_modules .DS_Store dist +dist-hash dist-ssr *.local diff --git a/e2e/react-router/basic-virtual-file-based/.gitignore b/e2e/react-router/basic-virtual-file-based/.gitignore index a6ea47e5085..4d2da67b504 100644 --- a/e2e/react-router/basic-virtual-file-based/.gitignore +++ b/e2e/react-router/basic-virtual-file-based/.gitignore @@ -1,6 +1,7 @@ node_modules .DS_Store dist +dist-hash dist-ssr *.local diff --git a/e2e/react-router/basic-virtual-named-export-config-file-based/.gitignore b/e2e/react-router/basic-virtual-named-export-config-file-based/.gitignore index ea2b6bb1fc7..47bb41d43a5 100644 --- a/e2e/react-router/basic-virtual-named-export-config-file-based/.gitignore +++ b/e2e/react-router/basic-virtual-named-export-config-file-based/.gitignore @@ -1,6 +1,7 @@ node_modules .DS_Store dist +dist-hash dist-ssr *.local diff --git a/e2e/react-router/basic/.gitignore b/e2e/react-router/basic/.gitignore index 8354e4d50d5..218ef7614ba 100644 --- a/e2e/react-router/basic/.gitignore +++ b/e2e/react-router/basic/.gitignore @@ -1,6 +1,7 @@ node_modules .DS_Store dist +dist-hash dist-ssr *.local diff --git a/e2e/react-router/rspack-basic-file-based/.gitignore b/e2e/react-router/rspack-basic-file-based/.gitignore index fbb2bd02932..e826cc86e81 100644 --- a/e2e/react-router/rspack-basic-file-based/.gitignore +++ b/e2e/react-router/rspack-basic-file-based/.gitignore @@ -6,6 +6,7 @@ # Dist node_modules dist/ +dist-hash/ # IDE .vscode/* diff --git a/e2e/react-router/rspack-basic-virtual-named-export-config-file-based/.gitignore b/e2e/react-router/rspack-basic-virtual-named-export-config-file-based/.gitignore index fbb2bd02932..e826cc86e81 100644 --- a/e2e/react-router/rspack-basic-virtual-named-export-config-file-based/.gitignore +++ b/e2e/react-router/rspack-basic-virtual-named-export-config-file-based/.gitignore @@ -6,6 +6,7 @@ # Dist node_modules dist/ +dist-hash/ # IDE .vscode/* diff --git a/e2e/react-router/scroll-restoration-sandbox-vite/playwright.browser.config.ts b/e2e/react-router/scroll-restoration-sandbox-vite/playwright.browser.config.ts index 0439dae37ee..7ac948806df 100644 --- a/e2e/react-router/scroll-restoration-sandbox-vite/playwright.browser.config.ts +++ b/e2e/react-router/scroll-restoration-sandbox-vite/playwright.browser.config.ts @@ -1,8 +1,10 @@ import { defineConfig, devices } from '@playwright/test' -import { derivePort } from '@tanstack/router-e2e-utils' +import { derivePort, resolveRuntimeSuffix } from '@tanstack/router-e2e-utils' import packageJson from './package.json' with { type: 'json' } -const PORT = derivePort(packageJson.name + '-browser') +const PORT = derivePort( + packageJson.name + `-${resolveRuntimeSuffix('browser')}`, +) const baseURL = `http://localhost:${PORT}` /** * See https://playwright.dev/docs/test-configuration. diff --git a/e2e/react-router/scroll-restoration-sandbox-vite/playwright.hash.config.ts b/e2e/react-router/scroll-restoration-sandbox-vite/playwright.hash.config.ts index 66cb974b0d8..0e492ec9703 100644 --- a/e2e/react-router/scroll-restoration-sandbox-vite/playwright.hash.config.ts +++ b/e2e/react-router/scroll-restoration-sandbox-vite/playwright.hash.config.ts @@ -1,8 +1,10 @@ import { defineConfig, devices } from '@playwright/test' -import { derivePort } from '@tanstack/router-e2e-utils' +import { derivePort, resolveRuntimeSuffix } from '@tanstack/router-e2e-utils' import packageJson from './package.json' with { type: 'json' } -const PORT = derivePort(packageJson.name + '-hash') +const PORT = derivePort( + packageJson.name + `-${resolveRuntimeSuffix('browser')}`, +) const baseURL = `http://localhost:${PORT}` /** * See https://playwright.dev/docs/test-configuration. diff --git a/e2e/react-router/scroll-restoration-sandbox-vite/tests/app.spec.ts b/e2e/react-router/scroll-restoration-sandbox-vite/tests/app.spec.ts index 77426058a6a..4cdb608958f 100644 --- a/e2e/react-router/scroll-restoration-sandbox-vite/tests/app.spec.ts +++ b/e2e/react-router/scroll-restoration-sandbox-vite/tests/app.spec.ts @@ -1,13 +1,9 @@ import { expect, test } from '@playwright/test' import { linkOptions } from '@tanstack/react-router' - -function toValue(input: string) { - const value = process.env.VITE_APP_HISTORY === 'hash' ? `/#${input}` : input - return value -} +import { toRuntimePath } from '@tanstack/router-e2e-utils' test('Smoke - Renders home', async ({ page }) => { - await page.goto(toValue('/')) + await page.goto(toRuntimePath('/')) await expect( page.getByRole('heading', { name: 'Welcome Home!' }), ).toBeVisible() @@ -24,7 +20,7 @@ test('Smoke - Renders home', async ({ page }) => { test(`On navigate to ${options.to} (from the header), scroll should be at top`, async ({ page, }) => { - await page.goto(toValue('/')) + await page.goto(toRuntimePath('/')) await page.getByRole('link', { name: `Head-${options.to}` }).click() await expect(page.getByTestId('at-the-top')).toBeInViewport() }) @@ -33,7 +29,7 @@ test('Smoke - Renders home', async ({ page }) => { test(`On navigate via index page tests to ${options.to}, scroll should resolve at the bottom`, async ({ page, }) => { - await page.goto(toValue('/')) + await page.goto(toRuntimePath('/')) await page .getByRole('link', { name: `${options.to}#at-the-bottom` }) .click() @@ -48,7 +44,7 @@ test('Smoke - Renders home', async ({ page }) => { if ('search' in options) { url = `${url}?where=${options.search.where}` } - await page.goto(toValue(`${url}#at-the-bottom`)) + await page.goto(toRuntimePath(`${url}#at-the-bottom`)) await expect(page.getByTestId('at-the-bottom')).toBeInViewport() }) }) diff --git a/e2e/react-router/sentry-integration/.gitignore b/e2e/react-router/sentry-integration/.gitignore index 8354e4d50d5..218ef7614ba 100644 --- a/e2e/react-router/sentry-integration/.gitignore +++ b/e2e/react-router/sentry-integration/.gitignore @@ -1,6 +1,7 @@ node_modules .DS_Store dist +dist-hash dist-ssr *.local diff --git a/e2e/solid-router/basic-esbuild-file-based/.gitignore b/e2e/solid-router/basic-esbuild-file-based/.gitignore index a6ea47e5085..4d2da67b504 100644 --- a/e2e/solid-router/basic-esbuild-file-based/.gitignore +++ b/e2e/solid-router/basic-esbuild-file-based/.gitignore @@ -1,6 +1,7 @@ node_modules .DS_Store dist +dist-hash dist-ssr *.local diff --git a/e2e/solid-router/basic-file-based-code-splitting/.gitignore b/e2e/solid-router/basic-file-based-code-splitting/.gitignore index a6ea47e5085..4d2da67b504 100644 --- a/e2e/solid-router/basic-file-based-code-splitting/.gitignore +++ b/e2e/solid-router/basic-file-based-code-splitting/.gitignore @@ -1,6 +1,7 @@ node_modules .DS_Store dist +dist-hash dist-ssr *.local diff --git a/e2e/solid-router/basic-file-based/.gitignore b/e2e/solid-router/basic-file-based/.gitignore index a6ea47e5085..4d2da67b504 100644 --- a/e2e/solid-router/basic-file-based/.gitignore +++ b/e2e/solid-router/basic-file-based/.gitignore @@ -1,6 +1,7 @@ node_modules .DS_Store dist +dist-hash dist-ssr *.local diff --git a/e2e/solid-router/basic-scroll-restoration/.gitignore b/e2e/solid-router/basic-scroll-restoration/.gitignore index 8354e4d50d5..218ef7614ba 100644 --- a/e2e/solid-router/basic-scroll-restoration/.gitignore +++ b/e2e/solid-router/basic-scroll-restoration/.gitignore @@ -1,6 +1,7 @@ node_modules .DS_Store dist +dist-hash dist-ssr *.local diff --git a/e2e/solid-router/basic-solid-query-file-based/.gitignore b/e2e/solid-router/basic-solid-query-file-based/.gitignore index a6ea47e5085..4d2da67b504 100644 --- a/e2e/solid-router/basic-solid-query-file-based/.gitignore +++ b/e2e/solid-router/basic-solid-query-file-based/.gitignore @@ -1,6 +1,7 @@ node_modules .DS_Store dist +dist-hash dist-ssr *.local diff --git a/e2e/solid-router/basic-solid-query/.gitignore b/e2e/solid-router/basic-solid-query/.gitignore index a6ea47e5085..4d2da67b504 100644 --- a/e2e/solid-router/basic-solid-query/.gitignore +++ b/e2e/solid-router/basic-solid-query/.gitignore @@ -1,6 +1,7 @@ node_modules .DS_Store dist +dist-hash dist-ssr *.local diff --git a/e2e/solid-router/basic-virtual-file-based/.gitignore b/e2e/solid-router/basic-virtual-file-based/.gitignore index a6ea47e5085..4d2da67b504 100644 --- a/e2e/solid-router/basic-virtual-file-based/.gitignore +++ b/e2e/solid-router/basic-virtual-file-based/.gitignore @@ -1,6 +1,7 @@ node_modules .DS_Store dist +dist-hash dist-ssr *.local diff --git a/e2e/solid-router/basic-virtual-named-export-config-file-based/.gitignore b/e2e/solid-router/basic-virtual-named-export-config-file-based/.gitignore index ea2b6bb1fc7..47bb41d43a5 100644 --- a/e2e/solid-router/basic-virtual-named-export-config-file-based/.gitignore +++ b/e2e/solid-router/basic-virtual-named-export-config-file-based/.gitignore @@ -1,6 +1,7 @@ node_modules .DS_Store dist +dist-hash dist-ssr *.local diff --git a/e2e/solid-router/basic/.gitignore b/e2e/solid-router/basic/.gitignore index 8354e4d50d5..218ef7614ba 100644 --- a/e2e/solid-router/basic/.gitignore +++ b/e2e/solid-router/basic/.gitignore @@ -1,6 +1,7 @@ node_modules .DS_Store dist +dist-hash dist-ssr *.local diff --git a/e2e/solid-router/rspack-basic-file-based/.gitignore b/e2e/solid-router/rspack-basic-file-based/.gitignore index fbb2bd02932..e826cc86e81 100644 --- a/e2e/solid-router/rspack-basic-file-based/.gitignore +++ b/e2e/solid-router/rspack-basic-file-based/.gitignore @@ -6,6 +6,7 @@ # Dist node_modules dist/ +dist-hash/ # IDE .vscode/* diff --git a/e2e/solid-router/rspack-basic-virtual-named-export-config-file-based/.gitignore b/e2e/solid-router/rspack-basic-virtual-named-export-config-file-based/.gitignore index fbb2bd02932..e826cc86e81 100644 --- a/e2e/solid-router/rspack-basic-virtual-named-export-config-file-based/.gitignore +++ b/e2e/solid-router/rspack-basic-virtual-named-export-config-file-based/.gitignore @@ -6,6 +6,7 @@ # Dist node_modules dist/ +dist-hash/ # IDE .vscode/* diff --git a/e2e/solid-router/scroll-restoration-sandbox-vite/playwright.browser.config.ts b/e2e/solid-router/scroll-restoration-sandbox-vite/playwright.browser.config.ts index 0439dae37ee..7ac948806df 100644 --- a/e2e/solid-router/scroll-restoration-sandbox-vite/playwright.browser.config.ts +++ b/e2e/solid-router/scroll-restoration-sandbox-vite/playwright.browser.config.ts @@ -1,8 +1,10 @@ import { defineConfig, devices } from '@playwright/test' -import { derivePort } from '@tanstack/router-e2e-utils' +import { derivePort, resolveRuntimeSuffix } from '@tanstack/router-e2e-utils' import packageJson from './package.json' with { type: 'json' } -const PORT = derivePort(packageJson.name + '-browser') +const PORT = derivePort( + packageJson.name + `-${resolveRuntimeSuffix('browser')}`, +) const baseURL = `http://localhost:${PORT}` /** * See https://playwright.dev/docs/test-configuration. diff --git a/e2e/solid-router/scroll-restoration-sandbox-vite/playwright.config.ts b/e2e/solid-router/scroll-restoration-sandbox-vite/playwright.config.ts deleted file mode 100644 index 2eeb79844fc..00000000000 --- a/e2e/solid-router/scroll-restoration-sandbox-vite/playwright.config.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { defineConfig, devices } from '@playwright/test' -import { derivePort } from '@tanstack/router-e2e-utils' -import packageJson from './package.json' with { type: 'json' } - -const PORT = derivePort(packageJson.name) -const baseURL = `http://localhost:${PORT}` -/** - * See https://playwright.dev/docs/test-configuration. - */ -export default defineConfig({ - testDir: './tests', - workers: 1, - - reporter: [['line']], - - use: { - /* Base URL to use in actions like `await page.goto('/')`. */ - baseURL, - }, - - webServer: { - command: `VITE_SERVER_PORT=${PORT} pnpm build && VITE_SERVER_PORT=${PORT} pnpm serve --port ${PORT}`, - url: baseURL, - reuseExistingServer: !process.env.CI, - stdout: 'pipe', - }, - - projects: [ - { - name: 'chromium', - use: { ...devices['Desktop Chrome'] }, - }, - ], -}) diff --git a/e2e/solid-router/scroll-restoration-sandbox-vite/playwright.hash.config.ts b/e2e/solid-router/scroll-restoration-sandbox-vite/playwright.hash.config.ts index 66cb974b0d8..f6a402a2dd3 100644 --- a/e2e/solid-router/scroll-restoration-sandbox-vite/playwright.hash.config.ts +++ b/e2e/solid-router/scroll-restoration-sandbox-vite/playwright.hash.config.ts @@ -1,8 +1,8 @@ import { defineConfig, devices } from '@playwright/test' -import { derivePort } from '@tanstack/router-e2e-utils' +import { derivePort, resolveRuntimeSuffix } from '@tanstack/router-e2e-utils' import packageJson from './package.json' with { type: 'json' } -const PORT = derivePort(packageJson.name + '-hash') +const PORT = derivePort(packageJson.name + `-${resolveRuntimeSuffix('hash')}`) const baseURL = `http://localhost:${PORT}` /** * See https://playwright.dev/docs/test-configuration. diff --git a/e2e/solid-router/scroll-restoration-sandbox-vite/tests/app.spec.ts b/e2e/solid-router/scroll-restoration-sandbox-vite/tests/app.spec.ts index cb36fc53c4a..5f226c6db31 100644 --- a/e2e/solid-router/scroll-restoration-sandbox-vite/tests/app.spec.ts +++ b/e2e/solid-router/scroll-restoration-sandbox-vite/tests/app.spec.ts @@ -1,12 +1,8 @@ import { expect, test } from '@playwright/test' - -function toValue(input: string) { - const value = process.env.VITE_APP_HISTORY === 'hash' ? `/#${input}` : input - return value -} +import { toRuntimePath } from '@tanstack/router-e2e-utils' test('Smoke - Renders home', async ({ page }) => { - await page.goto(toValue('/')) + await page.goto(toRuntimePath('/')) await expect( page.getByRole('heading', { name: 'Welcome Home!' }), ).toBeVisible() @@ -23,7 +19,7 @@ test('Smoke - Renders home', async ({ page }) => { test(`On navigate to ${options.to} (from the header), scroll should be at top`, async ({ page, }) => { - await page.goto(toValue('/')) + await page.goto(toRuntimePath('/')) await page.getByRole('link', { name: `Head-${options.to}` }).click() await page.waitForTimeout(0) await expect(page.getByTestId('at-the-top')).toBeInViewport() @@ -33,7 +29,7 @@ test('Smoke - Renders home', async ({ page }) => { test(`On navigate via index page tests to ${options.to}, scroll should resolve at the bottom`, async ({ page, }) => { - await page.goto(toValue('/')) + await page.goto(toRuntimePath('/')) await page .getByRole('link', { name: `${options.to}#at-the-bottom` }) .click() @@ -49,7 +45,7 @@ test('Smoke - Renders home', async ({ page }) => { if ('search' in options) { url = `${url}?where=${options.search?.where}` } - await page.goto(toValue(`${url}#at-the-bottom`)) + await page.goto(toRuntimePath(`${url}#at-the-bottom`)) await page.waitForTimeout(0) await expect(page.getByTestId('at-the-bottom')).toBeInViewport() })