Skip to content

Commit bd250a9

Browse files
committed
fix: report expected failures as passed
1 parent de407d0 commit bd250a9

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

src/generate-report.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ class GenerateCtrfReport implements Reporter {
184184
): void {
185185
const test: CtrfTest = {
186186
name: testCase.title,
187-
status: this.mapPlaywrightStatusToCtrf(testResult.status),
187+
status:
188+
testResult.status === testCase.expectedStatus
189+
? 'passed'
190+
: this.mapPlaywrightStatusToCtrf(testResult.status),
188191
duration: testResult.duration,
189192
}
190193

@@ -217,8 +220,9 @@ class GenerateCtrfReport implements Reporter {
217220
this.extractMetadata(testResult)?.name !== undefined ||
218221
this.extractMetadata(testResult)?.version !== undefined
219222
)
220-
test.browser = `${this.extractMetadata(testResult)
221-
?.name} ${this.extractMetadata(testResult)?.version}`
223+
test.browser = `${
224+
this.extractMetadata(testResult)?.name
225+
} ${this.extractMetadata(testResult)?.version}`
222226
test.attachments = this.filterValidAttachments(testResult.attachments)
223227
test.stdout = testResult.stdout.map((item) =>
224228
Buffer.isBuffer(item) ? item.toString() : String(item)

tests/dummy-suites/failed-test-suite.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ export const createFailedTestSuite = (): Suite => {
3131
stderr: [],
3232
}
3333

34-
const testCase: TestCase = {
34+
const failedTestCase: TestCase = {
3535
title: 'should validate the expected condition',
36-
id: 'test-id-123',
36+
id: 'test-id-1',
3737
annotations: [],
3838
expectedStatus: 'passed',
3939
timeout: 30000,
@@ -54,6 +54,26 @@ export const createFailedTestSuite = (): Suite => {
5454
retries: 0,
5555
}
5656

57+
const passedTestCase: TestCase = {
58+
title: 'should fail as expected',
59+
id: 'test-id-2',
60+
annotations: [],
61+
expectedStatus: 'failed',
62+
timeout: 30000,
63+
results: [testResult],
64+
location: {
65+
file: 'test-file.spec.ts',
66+
line: 42,
67+
column: 3,
68+
},
69+
parent: undefined as any, // Will be set later
70+
outcome: () => 'expected',
71+
ok: () => true,
72+
titlePath: () => ['Failed Test Suite', 'should fail as expected'],
73+
repeatEachIndex: 0,
74+
retries: 0,
75+
}
76+
5777
const suite: Suite = {
5878
title: 'Failed Test Suite',
5979
titlePath: () => ['Failed Test Suite'],
@@ -78,12 +98,13 @@ export const createFailedTestSuite = (): Suite => {
7898
testMatch: [],
7999
snapshotDir: './snapshots',
80100
}),
81-
allTests: () => [testCase],
82-
tests: [testCase],
101+
allTests: () => [failedTestCase, passedTestCase],
102+
tests: [failedTestCase, passedTestCase],
83103
suites: [],
84104
}
85105

86-
testCase.parent = suite
106+
failedTestCase.parent = suite
107+
passedTestCase.parent = suite
87108

88109
return suite
89110
}

tests/failed-tests.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,17 @@ describe('Failed Tests', () => {
2828
const reportJsonContent = mockedFs.writeFileSync.mock.calls[0][1] as string
2929
const parsedReport: CtrfReport = JSON.parse(reportJsonContent)
3030

31-
expect(parsedReport.results.tests).toHaveLength(1)
31+
expect(parsedReport.results.tests).toHaveLength(2)
32+
expect(parsedReport.results.tests[0].status).toBe('failed')
33+
expect(parsedReport.results.tests[0].rawStatus).toBe('failed')
3234
expect(parsedReport.results.tests[0].status).toBe('failed')
3335
expect(parsedReport.results.tests[0].message).toBe('test-error-message')
3436
expect(parsedReport.results.tests[0].trace).toBe('test-error-stack')
3537
expect(parsedReport.results.tests[0].snippet).toBe('test-error-snippet')
38+
expect(parsedReport.results.tests[1].status).toBe('passed')
39+
expect(parsedReport.results.tests[1].rawStatus).toBe('failed')
40+
expect(parsedReport.results.tests[1].message).toBe('test-error-message')
41+
expect(parsedReport.results.tests[1].trace).toBe('test-error-stack')
42+
expect(parsedReport.results.tests[1].snippet).toBe('test-error-snippet')
3643
})
3744
})

0 commit comments

Comments
 (0)