Skip to content

Commit fff8e36

Browse files
Merge pull request #29 from jembezmamy/fix-expected-fail
Report expected failures as passed
2 parents 5515e99 + 807c875 commit fff8e36

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

src/generate-report.ts

Lines changed: 4 additions & 1 deletion
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

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

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

35-
const testCase: TestCase = {
35+
const failedTestCase: TestCase = {
3636
title: 'should validate the expected condition',
37-
id: 'test-id-123',
37+
id: 'test-id-1',
3838
annotations: [],
3939
tags: [],
4040
type: 'test',
@@ -57,6 +57,26 @@ export const createFailedTestSuite = (): Suite => {
5757
retries: 0,
5858
}
5959

60+
const passedTestCase: TestCase = {
61+
title: 'should fail as expected',
62+
id: 'test-id-2',
63+
annotations: [],
64+
expectedStatus: 'failed',
65+
timeout: 30000,
66+
results: [testResult],
67+
location: {
68+
file: 'test-file.spec.ts',
69+
line: 42,
70+
column: 3,
71+
},
72+
parent: undefined as any, // Will be set later
73+
outcome: () => 'expected',
74+
ok: () => true,
75+
titlePath: () => ['Failed Test Suite', 'should fail as expected'],
76+
repeatEachIndex: 0,
77+
retries: 0,
78+
}
79+
6080
const suite: Suite = {
6181
title: 'Failed Test Suite',
6282
titlePath: () => ['Failed Test Suite'],
@@ -83,12 +103,13 @@ export const createFailedTestSuite = (): Suite => {
83103
testMatch: [],
84104
snapshotDir: './snapshots',
85105
}),
86-
allTests: () => [testCase],
87-
tests: [testCase],
106+
allTests: () => [failedTestCase, passedTestCase],
107+
tests: [failedTestCase, passedTestCase],
88108
suites: [],
89109
}
90110

91-
testCase.parent = suite
111+
failedTestCase.parent = suite
112+
passedTestCase.parent = suite
92113

93114
return suite
94115
}

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)