1
0

fix(e2e): 修复 10 个被 skip 的 E2E 测试

- 将 playwright.config.ts 的 mkdtemp 替换为固定路径,解决主进程/worker 临时目录不一致问题
- 交换后端 WAL 与迁移执行顺序,确保 sql.js 能读取到完整 schema
- 修复 models.spec.ts 断言使用 exact:true 避免统一模型 ID 列干扰
- 移除全部 10 个 test.skip,26 个 E2E 测试全部通过
This commit is contained in:
2026-04-22 14:32:12 +08:00
parent 7b28cee7a1
commit 5e7267db07
8 changed files with 46 additions and 32 deletions

View File

@@ -1,4 +1,5 @@
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import initSqlite from 'sql.js'
@@ -76,10 +77,7 @@ export async function seedModel(
}
export async function seedUsageStats(statsData: SeedStatsInput[]) {
const tempDir = process.env.NEX_E2E_TEMP_DIR
if (!tempDir) {
throw new Error('NEX_E2E_TEMP_DIR not set - ensure playwright.config.ts is loaded')
}
const tempDir = path.join(os.tmpdir(), 'nex-e2e')
const dbPath = path.join(tempDir, 'test.db')

View File

@@ -1,8 +1,10 @@
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
async function globalSetup() {
const tempDir = process.env.NEX_E2E_TEMP_DIR
if (tempDir && fs.existsSync(tempDir)) {
const tempDir = path.join(os.tmpdir(), 'nex-e2e')
if (fs.existsSync(tempDir)) {
console.log(`E2E temp dir: ${tempDir}`)
}
}

View File

@@ -1,8 +1,10 @@
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
async function globalTeardown() {
const tempDir = process.env.NEX_E2E_TEMP_DIR
if (tempDir && fs.existsSync(tempDir)) {
const tempDir = path.join(os.tmpdir(), 'nex-e2e')
if (fs.existsSync(tempDir)) {
await new Promise((resolve) => setTimeout(resolve, 500))
try {
fs.rmSync(tempDir, { recursive: true, force: true })

View File

@@ -43,7 +43,7 @@ test.describe('模型管理', () => {
await expect(page.getByText('暂无模型,点击上方按钮添加')).toBeVisible()
})
test.skip('应能为供应商添加模型', async ({ page }) => {
test('应能为供应商添加模型', async ({ page }) => {
await page.locator('.t-table__expand-box').first().click()
await expect(page.locator('.t-table__expanded-row').first()).toBeVisible()
@@ -58,7 +58,7 @@ test.describe('模型管理', () => {
const responsePromise = page.waitForResponse(resp => resp.url().includes('/api/models') && resp.request().method() === 'POST')
await inputs.saveBtn.click()
await responsePromise
await expect(page.locator('.t-table__expanded-row').getByText('gpt_4_turbo')).toBeVisible({ timeout: 5000 })
await expect(page.locator('.t-table__expanded-row').getByText('gpt_4_turbo', { exact: true })).toBeVisible({ timeout: 5000 })
})
test('应显示统一模型 ID', async ({ page, request }) => {
@@ -79,7 +79,7 @@ test.describe('模型管理', () => {
await expect(page.locator('.t-table__expanded-row').getByText(`${providerId}/claude_3`)).toBeVisible()
})
test.skip('应能编辑模型', async ({ page, request }) => {
test('应能编辑模型', async ({ page, request }) => {
await request.post(`${API_BASE}/api/models`, {
data: {
provider_id: providerId,
@@ -104,10 +104,10 @@ test.describe('模型管理', () => {
const responsePromise = page.waitForResponse(resp => resp.url().includes('/api/models') && resp.request().method() === 'PUT')
await inputs.saveBtn.click()
await responsePromise
await expect(page.locator('.t-table__expanded-row').getByText('gpt_4o')).toBeVisible({ timeout: 5000 })
await expect(page.locator('.t-table__expanded-row').getByText('gpt_4o', { exact: true })).toBeVisible({ timeout: 5000 })
})
test.skip('应能删除模型', async ({ page, request }) => {
test('应能删除模型', async ({ page, request }) => {
await request.post(`${API_BASE}/api/models`, {
data: {
provider_id: providerId,
@@ -121,11 +121,11 @@ test.describe('模型管理', () => {
await page.locator('.t-table__expand-box').first().click()
await expect(page.locator('.t-table__expanded-row').first()).toBeVisible()
await expect(page.locator('.t-table__expanded-row').getByText('to_delete_model')).toBeVisible()
await expect(page.locator('.t-table__expanded-row').getByText('to_delete_model', { exact: true })).toBeVisible()
await page.locator('.t-table__expanded-row button:has-text("删除")').first().click()
await expect(page.getByText(/确定要删除/)).toBeVisible()
await page.locator('.t-popconfirm').getByRole('button', { name: '确定' }).click()
await expect(page.locator('.t-table__expanded-row').getByText('to_delete_model')).not.toBeVisible({ timeout: 5000 })
await expect(page.locator('.t-table__expanded-row').getByText('to_delete_model', { exact: true })).not.toBeVisible({ timeout: 5000 })
})
})

View File

@@ -44,22 +44,22 @@ test.describe('统计概览', () => {
await expect(page.getByRole('heading', { name: '用量统计' })).toBeVisible()
})
test.skip('应显示正确的总请求量', async ({ page }) => {
test('应显示正确的总请求量', async ({ page }) => {
await page.waitForTimeout(1000)
await expect(page.getByText('总请求量')).toBeVisible()
})
test.skip('应显示正确的活跃模型数和活跃供应商数', async ({ page }) => {
test('应显示正确的活跃模型数和活跃供应商数', async ({ page }) => {
await page.waitForTimeout(1000)
await expect(page.getByText('活跃模型数')).toBeVisible()
await expect(page.getByText('活跃供应商数')).toBeVisible()
})
test.skip('应显示统计数据行', async ({ page }) => {
test('应显示统计数据行', async ({ page }) => {
await expect(page.locator('.t-table__body tr').first()).toBeVisible({ timeout: 5000 })
})
test.skip('应渲染趋势图表区域', async ({ page }) => {
test('应渲染趋势图表区域', async ({ page }) => {
await expect(page.getByText('请求趋势')).toBeVisible()
})
})
@@ -102,7 +102,7 @@ test.describe('统计筛选', () => {
await expect(page.getByRole('heading', { name: '用量统计' })).toBeVisible()
})
test.skip('按供应商筛选', async ({ page }) => {
test('按供应商筛选', async ({ page }) => {
await expect(page.locator('.t-table__body tr').first()).toBeVisible({ timeout: 5000 })
const rowCountBefore = await page.locator('.t-table__body tr:not(.t-table__empty-row)').count()
@@ -115,14 +115,14 @@ test.describe('统计筛选', () => {
expect(rowCountAfter).toBeLessThanOrEqual(rowCountBefore)
})
test.skip('按模型名称筛选', async ({ page }) => {
test('按模型名称筛选', async ({ page }) => {
await expect(page.locator('.t-table__body tr').first()).toBeVisible({ timeout: 5000 })
await page.getByPlaceholder('模型名称').fill('gpt_4')
await page.waitForTimeout(1000)
await expect(page.locator('.t-table__body')).toBeVisible()
})
test.skip('应显示筛选栏', async ({ page }) => {
test('应显示筛选栏', async ({ page }) => {
await expect(page.locator('.t-select').first()).toBeVisible()
await expect(page.getByPlaceholder('模型名称')).toBeVisible()
})