mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-01 21:44:27 +00:00
feat(e2e): set up fullstack app-level e2e test framework and signup test case
This commit is contained in:
@@ -0,0 +1,36 @@
|
|||||||
|
import { teardown as dbTeardown } from '../../../packages/db/src/test-global-setup'
|
||||||
|
import * as fs from 'fs'
|
||||||
|
import * as path from 'path'
|
||||||
|
import { fileURLToPath } from 'url'
|
||||||
|
|
||||||
|
const currentDir = path.dirname(fileURLToPath(import.meta.url))
|
||||||
|
|
||||||
|
export default async function globalTeardown() {
|
||||||
|
const envPath = path.resolve(currentDir, '.env.e2e')
|
||||||
|
if (fs.existsSync(envPath)) {
|
||||||
|
const content = fs.readFileSync(envPath, 'utf8')
|
||||||
|
let bucketName: string | undefined
|
||||||
|
|
||||||
|
content.split('\n').forEach((line) => {
|
||||||
|
const parts = line.split('=')
|
||||||
|
if (parts.length >= 2 && parts[0].trim() === 'S3_BUCKET') {
|
||||||
|
bucketName = parts.slice(1).join('=').trim()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (bucketName) {
|
||||||
|
const bucketDir = path.resolve('data', bucketName)
|
||||||
|
if (fs.existsSync(bucketDir)) {
|
||||||
|
console.log(`Cleaning up E2E local storage bucket: ${bucketDir}`)
|
||||||
|
fs.rmSync(bucketDir, { recursive: true, force: true })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the temp .env.e2e file
|
||||||
|
fs.unlinkSync(envPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stop pgvector container
|
||||||
|
await dbTeardown()
|
||||||
|
console.log('Global teardown complete.')
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { globalTestSetup } from '../../../packages/db/src/test-global-setup'
|
||||||
|
import { randomBytes } from 'crypto'
|
||||||
|
import * as fs from 'fs'
|
||||||
|
import * as path from 'path'
|
||||||
|
import { fileURLToPath } from 'url'
|
||||||
|
|
||||||
|
const currentDir = path.dirname(fileURLToPath(import.meta.url))
|
||||||
|
|
||||||
|
async function start() {
|
||||||
|
console.log('Starting E2E test database container...')
|
||||||
|
await globalTestSetup()
|
||||||
|
|
||||||
|
// Generate a random S3 bucket name
|
||||||
|
const randomSuffix = randomBytes(4).toString('hex')
|
||||||
|
const bucketName = `shumai-e2e-${randomSuffix}`
|
||||||
|
|
||||||
|
process.env.S3_BUCKET = bucketName
|
||||||
|
process.env.SHUMAI_SERVER_PORT = '5200'
|
||||||
|
process.env.BETTER_AUTH_URL = 'http://localhost:5200'
|
||||||
|
process.env.NODE_ENV = 'development'
|
||||||
|
|
||||||
|
// Write variables to .env.e2e file so the teardown can load them
|
||||||
|
const envContent = [`DATABASE_URL=${process.env.DATABASE_URL}`, `S3_BUCKET=${bucketName}`].join(
|
||||||
|
'\n',
|
||||||
|
)
|
||||||
|
|
||||||
|
fs.writeFileSync(path.resolve(currentDir, '.env.e2e'), envContent)
|
||||||
|
console.log(`E2E env file written. Starting Web App...`)
|
||||||
|
|
||||||
|
// Now run the web app
|
||||||
|
await import('../src/index.ts')
|
||||||
|
}
|
||||||
|
|
||||||
|
start().catch(console.error)
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import { expect, test } from '@playwright/test'
|
||||||
|
import * as fs from 'fs'
|
||||||
|
import * as path from 'path'
|
||||||
|
import { fileURLToPath } from 'url'
|
||||||
|
|
||||||
|
const currentDir = path.dirname(fileURLToPath(import.meta.url))
|
||||||
|
const tempImgPath = path.resolve(currentDir, 'temp-cover.png')
|
||||||
|
|
||||||
|
test.beforeAll(async () => {
|
||||||
|
// Create a 1x1 transparent PNG file
|
||||||
|
const pngBase64 =
|
||||||
|
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='
|
||||||
|
fs.writeFileSync(tempImgPath, Buffer.from(pngBase64, 'base64'))
|
||||||
|
})
|
||||||
|
|
||||||
|
test.afterAll(async () => {
|
||||||
|
if (fs.existsSync(tempImgPath)) {
|
||||||
|
fs.unlinkSync(tempImgPath)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
test('should sign up and create a project with a cover image', async ({ page }) => {
|
||||||
|
const email = `test-${Date.now()}@shumai.local`
|
||||||
|
const password = 'Password123!'
|
||||||
|
|
||||||
|
// 1. Sign Up Flow
|
||||||
|
await page.goto('/signup')
|
||||||
|
await expect(page).toHaveURL(/\/signup/)
|
||||||
|
|
||||||
|
// Fill credentials
|
||||||
|
await page.fill('#email', email)
|
||||||
|
await page.fill('#password', password)
|
||||||
|
|
||||||
|
// Submit sign up
|
||||||
|
await page.click('button[type="submit"]')
|
||||||
|
|
||||||
|
// Wait for the automatic redirect to the team page (since only one team exists)
|
||||||
|
await expect(page).toHaveURL(/\/teams\/[^/]+/)
|
||||||
|
|
||||||
|
// 2. Create Project Flow
|
||||||
|
// Click the "Create Project" button on the dashboard
|
||||||
|
await page.click('button:has-text("Create Project")')
|
||||||
|
|
||||||
|
const dialog = page.locator('[role="dialog"]')
|
||||||
|
await expect(dialog).toBeVisible()
|
||||||
|
|
||||||
|
// Fill project name
|
||||||
|
const projectName = `My Project ${Date.now()}`
|
||||||
|
await dialog.locator('#name').fill(projectName)
|
||||||
|
|
||||||
|
// Set cover image
|
||||||
|
await dialog.locator('input[type="file"]').setInputFiles(tempImgPath)
|
||||||
|
|
||||||
|
// Wait for image upload completion and preview
|
||||||
|
await expect(dialog.locator('img[alt="Cover Preview"]')).toBeVisible({ timeout: 15_000 })
|
||||||
|
|
||||||
|
// Click submit in dialog
|
||||||
|
await dialog.locator('button[type="submit"]').click()
|
||||||
|
|
||||||
|
// Wait for navigation to the project page
|
||||||
|
await expect(page).toHaveURL(/\/projects\/[^/]+/)
|
||||||
|
|
||||||
|
// Verify project name appears in the project view
|
||||||
|
await expect(page.locator(`text=${projectName}`).first()).toBeVisible()
|
||||||
|
|
||||||
|
// 3. Verification on Dashboard
|
||||||
|
// Navigate back to the dashboard via sidebar
|
||||||
|
await page.click('button[aria-label="Dashboard"]')
|
||||||
|
|
||||||
|
// Wait for dashboard URL
|
||||||
|
await expect(page).toHaveURL(/\/teams\/[^/]+/)
|
||||||
|
|
||||||
|
// Verify the project card is visible and displays the cover image with project name alt text
|
||||||
|
await expect(page.locator(`img[alt="${projectName}"]`)).toBeVisible()
|
||||||
|
})
|
||||||
+11
-5
@@ -96,7 +96,6 @@ async function run() {
|
|||||||
.replaceAll('content="./', 'content="/')
|
.replaceAll('content="./', 'content="/')
|
||||||
const serveMainHtml = () => new Response(mainHtmlText, { headers: mainHtmlHeaders })
|
const serveMainHtml = () => new Response(mainHtmlText, { headers: mainHtmlHeaders })
|
||||||
|
|
||||||
|
|
||||||
routes['/'] = serveMainHtml
|
routes['/'] = serveMainHtml
|
||||||
routes['/*'] = serveMainHtml
|
routes['/*'] = serveMainHtml
|
||||||
} else {
|
} else {
|
||||||
@@ -136,7 +135,14 @@ async function run() {
|
|||||||
process.on('SIGTERM', shutdown)
|
process.on('SIGTERM', shutdown)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleDaemonCommands('shumai', run).catch((err) => {
|
if (process.env.S3_BUCKET && process.env.S3_BUCKET.startsWith('shumai-e2e')) {
|
||||||
console.error(err)
|
run().catch((err) => {
|
||||||
process.exit(1)
|
console.error(err)
|
||||||
})
|
process.exit(1)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
handleDaemonCommands('shumai', run).catch((err) => {
|
||||||
|
console.error(err)
|
||||||
|
process.exit(1)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
+36
-29
@@ -1,19 +1,13 @@
|
|||||||
import { defineConfig, devices } from '@playwright/test'
|
import { defineConfig, devices } from '@playwright/test'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Playwright configuration for the webui UI integration tests.
|
* Playwright configuration for the monorepo integration and E2E tests.
|
||||||
*
|
*
|
||||||
* The suite runs against a backend-free harness (packages/webui/e2e) served by
|
* We support two test projects:
|
||||||
* Bun's native HTML bundler, so no database, auth or transcode pipeline is
|
* 1. harness: pure frontend UI integration tests served on port 5199.
|
||||||
* required.
|
* 2. app: fullstack end-to-end tests with real backend, pgvector container, and S3 local storage on port 5200.
|
||||||
*
|
|
||||||
* Browser selection: pass `--project=<name>` to pick an engine, e.g.
|
|
||||||
* bun run test:e2e --project=webkit # WebKit (Safari engine), used on macOS CI
|
|
||||||
* bun run test:e2e --project=chromium
|
|
||||||
* bun run test:e2e --project=firefox
|
|
||||||
*/
|
*/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
testDir: './packages/webui/e2e/tests',
|
|
||||||
testMatch: '**/*.spec.ts',
|
testMatch: '**/*.spec.ts',
|
||||||
fullyParallel: true,
|
fullyParallel: true,
|
||||||
forbidOnly: !!process.env.CI,
|
forbidOnly: !!process.env.CI,
|
||||||
@@ -23,35 +17,48 @@ export default defineConfig({
|
|||||||
timeout: 60_000,
|
timeout: 60_000,
|
||||||
expect: { timeout: 10_000 },
|
expect: { timeout: 10_000 },
|
||||||
|
|
||||||
|
globalTeardown: './apps/web/e2e/global-teardown.ts',
|
||||||
|
|
||||||
use: {
|
use: {
|
||||||
// `baseURL` is Playwright's required option key and cannot be renamed.
|
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
||||||
baseURL: 'http://localhost:5199',
|
|
||||||
trace: 'on-first-retry',
|
trace: 'on-first-retry',
|
||||||
video: 'retain-on-failure',
|
video: 'retain-on-failure',
|
||||||
},
|
},
|
||||||
|
|
||||||
projects: [
|
projects: [
|
||||||
{
|
{
|
||||||
name: 'chromium',
|
name: 'harness',
|
||||||
use: { ...devices['Desktop Chrome'] },
|
testDir: './packages/webui/e2e/tests',
|
||||||
|
use: {
|
||||||
|
...devices['Desktop Chrome'],
|
||||||
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
|
baseURL: 'http://localhost:5199',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'firefox',
|
name: 'app',
|
||||||
use: { ...devices['Desktop Firefox'] },
|
testDir: './apps/web/e2e',
|
||||||
},
|
fullyParallel: false, // run sequentially to avoid DB and storage conflicts
|
||||||
{
|
use: {
|
||||||
name: 'webkit',
|
...devices['Desktop Chrome'],
|
||||||
use: { ...devices['Desktop Safari'] },
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
|
baseURL: 'http://localhost:5200',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
// Launch the isolated harness dev server (Bun's native HTML bundler) before
|
// Launch both the isolated harness server and the fullstack web app server
|
||||||
// the tests.
|
webServer: [
|
||||||
webServer: {
|
{
|
||||||
command: 'bun run packages/webui/e2e/harness/serve.ts',
|
command: 'bun run packages/webui/e2e/harness/serve.ts',
|
||||||
url: 'http://localhost:5199',
|
url: 'http://localhost:5199',
|
||||||
reuseExistingServer: !process.env.CI,
|
reuseExistingServer: !process.env.CI,
|
||||||
timeout: 120_000,
|
timeout: 120_000,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
command: 'bun run apps/web/e2e/serve.ts',
|
||||||
|
url: 'http://localhost:5200',
|
||||||
|
reuseExistingServer: !process.env.CI,
|
||||||
|
timeout: 120_000,
|
||||||
|
},
|
||||||
|
],
|
||||||
})
|
})
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ export default defineConfig({
|
|||||||
pool: 'forks',
|
pool: 'forks',
|
||||||
// Playwright e2e specs live under packages/webui/e2e and are run by the
|
// Playwright e2e specs live under packages/webui/e2e and are run by the
|
||||||
// Playwright runner (bun run test:e2e), not Vitest.
|
// Playwright runner (bun run test:e2e), not Vitest.
|
||||||
exclude: [...configDefaults.exclude, 'packages/webui/e2e/**'],
|
exclude: [...configDefaults.exclude, 'packages/webui/e2e/**', 'apps/web/e2e/**'],
|
||||||
server: {
|
server: {
|
||||||
deps: {
|
deps: {
|
||||||
inline: ['zod'],
|
inline: ['zod'],
|
||||||
|
|||||||
Reference in New Issue
Block a user