Files
civitai__civitai/playwright.config.ts
T
Zachary Lowden ef8c158d7c test(preview): browser smoke tests for deployed PR previews (#2466)
* test(preview): browser smoke tests for deployed PR previews

Adds a Playwright suite that runs against a live PR preview URL and asserts
the IS_PREVIEW login gate (preview-auth.middleware) behaves per role:

- mod / tester / gold clear the gate and core pages render
- a logged-in non-tester is redirected to /preview-restricted
- an anonymous request is redirected to /login

The local /testing/testing-login flow is dead against a preview (NODE_ENV=
production disables the provider + route), so preview-auth.setup.ts mints the
NextAuth session cookie directly with the preview's shared NEXTAUTH_SECRET via
next-auth/jwt encode() — the same function the app signs with. The middleware
reads token.user straight from the cookie and the session callback fail-opens
on an untracked token id, yielding a fully authenticated session. Backing User
rows (+ a gold subscription) are seeded into cnpg-cluster-dev out-of-band.

Runs only under the new playwright.preview.config.ts (needs PREVIEW_URL); the
default config ignores preview-* files so local `npm test` is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test(preview): clarify auth-mint model + fix parallelism

Addresses audit feedback:
- Correct the setup-file comment: the minted cookie clears the gate, but SSR
  refreshes token.user from the seeded DB row (refreshToken on an untracked
  token id), so the DB row — not the minted fields — drives the session past
  the gate. The minted object only needs id + isModerator (+ tier for the
  gate's Flipt context).
- playwright.preview.config.ts: workers 1 -> 4 (workers:1 defeated fullyParallel).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test(preview): harden against cold-preview SSR latency

The first SSR render of a freshly-deployed preview (the homepage especially)
can take 30-40s while Next warms up — the default 30s per-test timeout flaked
on `mod loads /` (passed on retry). Hardening:

- timeout 30s -> 60s (per-test), navigationTimeout 45s.
- setup fires a warm-up GET / before the suite so the first real test doesn't
  pay the full cold-start cost.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* ci: retrigger preview to exercise pr-smoke-bot comment

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 14:32:57 -05:00

88 lines
2.6 KiB
TypeScript

import { defineConfig, devices } from '@playwright/test';
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// if (process.env.NODE_ENV === 'development') {
// dotenv.config({
// path: ['.env.development.local', '.env.local', '.env.development', '.env'],
// override: false,
// });
// }
/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
// preview-* run only under playwright.preview.config.ts (need PREVIEW_URL); the
// default `setup` project's *.setup.ts glob would otherwise pick them up.
testIgnore: ['example.spec.ts', '**/preview-*.ts'],
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
// workers: 1,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
// reporter: 'html',
reporter: process.env.CI ? 'html' : 'line',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: 'http://localhost:3000',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},
/* Configure projects for major browsers */
projects: [
// Setup project
{ name: 'setup', testMatch: /.*\.setup\.ts/ },
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
dependencies: ['setup'],
},
{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
dependencies: ['setup'],
},
// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
{
name: 'Mobile Safari',
use: { ...devices['iPhone 12'] },
dependencies: ['setup'],
},
/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],
/* Run your local dev server before starting the tests */
webServer: {
command: 'npm run dev',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
},
});