Instructions
- Following Playwright test failed.
- Explain why, be concise, respect Playwright best practices.
- Provide a snippet of code with the fix, if possible.
Test info
- Name: regression\02-tts.spec.ts >> TTS语音合成 (TTS) >> T03: 生成音频任务 POST /api/tts/generate
- Location: regression\02-tts.spec.ts:33:7
Error details
Error: expect(received).toBe(expected) // Object.is equality
Expected: 0
Received: 500
Test source
1 | /**
2 | * L2 回归测试:TTS语音合成
3 | * 覆盖:音色列表、提供商列表、音频生成、状态查询、预览、下载
4 | */
5 | import { test, expect } from '@playwright/test';
6 | import { apiGet, apiPost, initApiClient, disposeApiClient } from '../helpers/api-client';
7 | import { trackResource } from '../helpers/test-data';
8 |
9 | let testAudioId: string;
10 |
11 | test.describe('TTS语音合成 (TTS)', () => {
12 | test.beforeAll(async () => {
13 | await initApiClient();
14 | });
15 |
16 | test.afterAll(async () => {
17 | await disposeApiClient();
18 | });
19 |
20 | test('T01: 获取音色列表 GET /api/tts/voices', async () => {
21 | const res = await apiGet('/api/tts/voices');
22 | expect(res.code).toBe(0);
23 | expect(res.data?.voices).toBeDefined();
24 | expect(Array.isArray(res.data.voices)).toBe(true);
25 | });
26 |
27 | test('T02: 获取提供商列表 GET /api/tts/providers', async () => {
28 | const res = await apiGet('/api/tts/providers');
29 | expect(res.code).toBe(0);
30 | expect(res.data?.providers).toBeDefined();
31 | });
32 |
33 | test('T03: 生成音频任务 POST /api/tts/generate', async () => {
34 | const res = await apiPost('/api/tts/generate', {
35 | text: '这是一段自动化测试文本,用于验证TTS音频生成功能。',
36 | voiceId: 'Cherry',
37 | voiceParams: { speed: 1.0, pitch: 0, volume: 50 },
38 | });
39 | // 异步任务应该返回 0
> 40 | expect(res.code).toBe(0);
| ^ Error: expect(received).toBe(expected) // Object.is equality
41 | testAudioId = res.data?.audioId;
42 | expect(testAudioId).toBeDefined();
43 | });
44 |
45 | test('T04: 查询音频状态 GET /api/tts/status/:audioId', async () => {
46 | if (!testAudioId) return test.skip();
47 | const res = await apiGet(`/api/tts/status/${testAudioId}`);
48 | expect([0, 404]).toContain(res.code);
49 | });
50 |
51 | test('T05: 获取下载信息 GET /api/tts/download/:audioId', async () => {
52 | // 使用一个可能存在的音频ID测试路由可达性
53 | const res = await apiGet('/api/tts/download/1');
54 | expect([0, 404, 500]).toContain(res.code);
55 | });
56 | });
57 |