test(tests): measure the drag on a production build (vite preview)

Opt-in with MEASURE_DRAG=1 MEASURE_BUILD=preview: the app built with
the shell config's sandbox environment into e2e/test-results, served
by vite preview on 127.0.0.1:5193 (--strictPort), the allowlist set
to that origin and the fake Supabase origin. Suites unchanged.
This commit is contained in:
bchanot committed 2026-11-18 11:09:06 +01:00
1 parent bc8d645554
commit 181f81789a
2 files changed
+112 -4

No files matched your search

+28 -4
View File
@@ -1,32 +1,56 @@
import { test } from '../support/browser'
import { measureDrag } from '../support/measure-drag'
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
import {
PREVIEW_ORIGIN,
previewMeasure,
startPreview,
} from '../support/measure-preview'
import {
dropLateReplays,
FAKE_SUPABASE_ORIGIN,
routeToSandbox,
} from '../support/sandbox'
// U2 Task 8: the hand-run smoothness measure (support/measure-drag.ts). Skipped unless
// MEASURE_DRAG=1: a timing figure, never a suite assertion.
// MEASURE_DRAG=1: a timing figure, never a suite assertion. With MEASURE_BUILD=preview it
// runs on a production build (support/measure-preview.ts) instead of the dev server.
const preview = previewMeasure()
test.describe('drag smoothness measure (hand-run)', () => {
test.use({
locale: 'fr-FR',
hasTouch: true,
viewport: { width: 1180, height: 800 },
...(preview
? {
baseURL: PREVIEW_ORIGIN,
allowedOrigins: [PREVIEW_ORIGIN, FAKE_SUPABASE_ORIGIN],
}
: {}),
})
let stopPreview: (() => void) | null = null
test.beforeEach(async ({ context }, info) => {
test.skip(process.env.MEASURE_DRAG !== '1', 'run by hand: MEASURE_DRAG=1')
test.skip(info.project.name !== 'chromium-desktop', 'one run, at 1 180 px')
test.setTimeout(600_000)
if (preview) stopPreview = await startPreview()
await routeToSandbox(context)
})
test.afterEach(async ({ context }) => {
await dropLateReplays(context)
stopPreview?.()
stopPreview = null
})
test('vertex drag on the equine main view, touch with the loupe and mouse', async ({
page,
context,
}, info) => {
test.setTimeout(180_000)
test.setTimeout(600_000)
const build = preview ? 'production build (vite preview)' : 'dev server'
for (const figures of await measureDrag(page, context)) {
const line = JSON.stringify(figures)
const line = JSON.stringify({ build, ...figures })
console.log(`MEASURE ${line}`)
info.annotations.push({ type: 'measure', description: line })
}
+84
View File
@@ -0,0 +1,84 @@
/**
* The production build of the hand-run measure (support/measure-drag.ts), opt-in with
* MEASURE_DRAG=1 MEASURE_BUILD=preview: the app built with the same sandbox environment
* the shell config gives its dev server (the fake Supabase origin, the sandbox anon key),
* written under the git-ignored e2e/test-results, then served by `vite preview` on a
* loopback port of its own (`--strictPort`, never reused). No suite and no Docker config
* uses it.
*/
import { spawn, type ChildProcess } from 'node:child_process'
import { join } from 'node:path'
import { FAKE_SUPABASE_ORIGIN } from './sandbox'
export const PREVIEW_ORIGIN = 'http://127.0.0.1:5193'
const APP = join(__dirname, '../..')
const OUT = join(APP, 'e2e/test-results/measure-build')
const VITE = join(APP, 'node_modules/.bin/vite')
export const previewMeasure = () =>
process.env.MEASURE_DRAG === '1' && process.env.MEASURE_BUILD === 'preview'
function viteEnv() {
const anonKey = process.env.SANDBOX_ANON_KEY
if (!anonKey)
throw new Error('SANDBOX_ANON_KEY missing: run through db:sandbox')
return {
...process.env,
VITE_SUPABASE_URL: FAKE_SUPABASE_ORIGIN,
VITE_SUPABASE_ANON_KEY: anonKey,
}
}
function run(args: string[]): Promise<void> {
return new Promise((done, fail) => {
const child = spawn(VITE, args, {
cwd: APP,
env: viteEnv(),
stdio: 'inherit',
})
child.on('error', fail)
child.on('exit', (code) =>
code === 0 ? done() : fail(new Error(`vite ${args[0]} exited ${code}`)),
)
})
}
async function ready(child: ChildProcess): Promise<void> {
for (let tries = 0; tries < 100; tries++) {
if (child.exitCode !== null) throw new Error('vite preview stopped')
const up = await fetch(`${PREVIEW_ORIGIN}/`).then(
(r) => r.ok,
() => false,
)
if (up) return
await new Promise((wait) => setTimeout(wait, 200))
}
throw new Error('vite preview did not answer')
}
/** Builds the app and serves it; resolves with the function that stops the server. */
export async function startPreview(): Promise<() => void> {
await run(['build', '--outDir', OUT, '--emptyOutDir'])
const { port } = new URL(PREVIEW_ORIGIN)
const preview = spawn(
VITE,
[
'preview',
'--outDir',
OUT,
'--host',
'127.0.0.1',
'--port',
port,
'--strictPort',
],
{ cwd: APP, env: viteEnv(), stdio: 'inherit' },
)
try {
await ready(preview)
} catch (error) {
preview.kill()
throw error
}
return () => preview.kill()
}