|
| 1 | +import { |
| 2 | + type Suite, |
| 3 | + type TestCase, |
| 4 | + type Location, |
| 5 | + type TestResult, |
| 6 | + type TestError, |
| 7 | +} from '@playwright/test/reporter' |
| 8 | + |
| 9 | +/** |
| 10 | + * Creates a minimal Suite object with a single failed test |
| 11 | + */ |
| 12 | +export const createFailedTestSuite = (): Suite => { |
| 13 | + const testError: TestError = { |
| 14 | + message: 'test-error-message', |
| 15 | + stack: 'test-error-stack', |
| 16 | + snippet: 'test-error-snippet', |
| 17 | + } |
| 18 | + |
| 19 | + const testResult: TestResult = { |
| 20 | + retry: 0, |
| 21 | + duration: 120, |
| 22 | + status: 'failed', |
| 23 | + startTime: new Date('2023-01-01T00:00:00.000Z'), |
| 24 | + parallelIndex: 0, |
| 25 | + workerIndex: 0, |
| 26 | + attachments: [], |
| 27 | + errors: [testError], |
| 28 | + error: testError, |
| 29 | + steps: [], |
| 30 | + stdout: [], |
| 31 | + stderr: [], |
| 32 | + } |
| 33 | + |
| 34 | + const testCase: TestCase = { |
| 35 | + title: 'should validate the expected condition', |
| 36 | + id: 'test-id-123', |
| 37 | + annotations: [], |
| 38 | + expectedStatus: 'passed', |
| 39 | + timeout: 30000, |
| 40 | + results: [testResult], |
| 41 | + location: { |
| 42 | + file: 'test-file.spec.ts', |
| 43 | + line: 42, |
| 44 | + column: 3, |
| 45 | + }, |
| 46 | + parent: undefined as any, // Will be set later |
| 47 | + outcome: () => 'unexpected', |
| 48 | + ok: () => false, |
| 49 | + titlePath: () => [ |
| 50 | + 'Failed Test Suite', |
| 51 | + 'should validate the expected condition', |
| 52 | + ], |
| 53 | + repeatEachIndex: 0, |
| 54 | + retries: 0, |
| 55 | + } |
| 56 | + |
| 57 | + const suite: Suite = { |
| 58 | + title: 'Failed Test Suite', |
| 59 | + titlePath: () => ['Failed Test Suite'], |
| 60 | + location: { |
| 61 | + file: 'test-file.spec.ts', |
| 62 | + line: 10, |
| 63 | + column: 1, |
| 64 | + } as Location, |
| 65 | + project: () => ({ |
| 66 | + name: 'Test Project', |
| 67 | + outputDir: './test-results', |
| 68 | + grep: /.*/, |
| 69 | + grepInvert: null, |
| 70 | + metadata: {}, |
| 71 | + dependencies: [], |
| 72 | + repeatEach: 1, |
| 73 | + retries: 0, |
| 74 | + timeout: 30000, |
| 75 | + use: {}, |
| 76 | + testDir: './tests', |
| 77 | + testIgnore: [], |
| 78 | + testMatch: [], |
| 79 | + snapshotDir: './snapshots', |
| 80 | + }), |
| 81 | + allTests: () => [testCase], |
| 82 | + tests: [testCase], |
| 83 | + suites: [], |
| 84 | + } |
| 85 | + |
| 86 | + testCase.parent = suite |
| 87 | + |
| 88 | + return suite |
| 89 | +} |
0 commit comments