health.spec.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * L1 冒烟测试:健康检查
  3. * 验证后端服务基础健康状态
  4. */
  5. import { test, expect } from '@playwright/test';
  6. import { apiGet, initApiClient, disposeApiClient } from '../helpers/api-client';
  7. test.describe('健康检查', () => {
  8. test.beforeAll(async () => {
  9. await initApiClient();
  10. });
  11. test.afterAll(async () => {
  12. await disposeApiClient();
  13. });
  14. test('S01: 服务健康检查 /health', async () => {
  15. const res = await apiGet('/health');
  16. expect(res.code).toBe(0);
  17. expect(res.data?.status).toBe('healthy');
  18. });
  19. test('S02: 数据库连接检查 /api/tts/test-db', async () => {
  20. const res = await apiGet('/api/tts/test-db');
  21. expect(res.code).toBe(0);
  22. expect(res.data?.connectionState).toBe('connected');
  23. });
  24. test('S03: 性能指标端点 /api/metrics', async () => {
  25. const res = await apiGet('/api/metrics');
  26. // metrics 可能返回非标准格式,只验证可达
  27. expect([0, 200]).toContain(res.code);
  28. });
  29. test('S04: 静态文件服务可用 /uploads', async () => {
  30. const { apiRaw } = require('../helpers/api-client');
  31. const raw = await apiRaw('GET', '/uploads/');
  32. expect([200, 404]).toContain(raw.status());
  33. });
  34. });