diff --git a/package.json b/package.json index 20c2671..03faba4 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "lint":"npx eslint . --ext .ts" }, "name": "playwright-slack-report", - "version": "1.0.4", + "version": "1.0.6", "main": "index.js", "types": "dist/index.d.ts", "repository": "git@github.com:ryanrosello-og/playwright-slack-report.git", diff --git a/src/LayoutGenerator.ts b/src/LayoutGenerator.ts index 8d06846..89052ad 100644 --- a/src/LayoutGenerator.ts +++ b/src/LayoutGenerator.ts @@ -21,11 +21,7 @@ const generateBlocks = async ( summaryResults.skipped > 0 ? `:fast_forward: *${summaryResults.skipped}* skipped` : '' - } \n\n ${ - summaryResults.aborted > 0 - ? `:exclamation: *${summaryResults.aborted}* aborted` - : '' - }`, + } \n\n `, }, }; diff --git a/src/ResultsParser.ts b/src/ResultsParser.ts index 1ef4063..252ec40 100644 --- a/src/ResultsParser.ts +++ b/src/ResultsParser.ts @@ -14,7 +14,7 @@ export type testResult = { reason: string; retry: number; startedAt: string; - status: 'failed' | 'passed' | 'skipped' | 'aborted'; + status: 'passed' | 'failed' | 'timedOut' | 'skipped'; attachments?: { body: string | undefined | Buffer; contentType: string; @@ -43,7 +43,6 @@ export default class ResultsParser { passed: 0, failed: 0, skipped: 0, - aborted: 0, failures: await this.getFailures(), tests: [], }; @@ -52,12 +51,10 @@ export default class ResultsParser { for (const test of suite.testSuite.tests) { if (test.status === 'passed') { summary.passed += 1; - } else if (test.status === 'failed') { + } else if (test.status === 'failed' || test.status === 'timedOut') { summary.failed += 1; } else if (test.status === 'skipped') { summary.skipped += 1; - } else if (test.status === 'aborted') { - summary.aborted += 1; } } } @@ -68,7 +65,7 @@ export default class ResultsParser { const failures: Array = []; for (const suite of this.result) { for (const test of suite.testSuite.tests) { - if (test.status === 'failed') { + if (test.status === 'failed' || test.status === 'timedOut') { failures.push({ test: test.name, failureReason: test.reason, @@ -97,9 +94,7 @@ export default class ResultsParser { endedAt: new Date( new Date(result.startTime).getTime() + result.duration, ).toISOString(), - reason: `${this.cleanseReason( - result.error?.message, - )} \n ${this.cleanseReason(result.error?.stack)}`, + reason: this.safelyDetermineFailure(result), attachments: result.attachments, }); } @@ -111,28 +106,16 @@ export default class ResultsParser { }); } - async parseTests(suiteName: any, tests: any) { - const testResults: testResult[] = []; - - for (const test of tests) { - for (const result of test.results) { - testResults.push({ - suiteName, - name: test.title, - status: result.status, - retry: result.retry, - startedAt: new Date(result.startTime).toISOString(), - endedAt: new Date( - new Date(result.startTime).getTime() + result.duration, - ).toISOString(), - reason: `${this.cleanseReason( - result.error?.message, - )} \n ${this.cleanseReason(result.error?.stack)}`, - attachments: result.attachments, - }); - } + safelyDetermineFailure(result: + { errors: any[]; error: { message: string; stack: string; }; + }) : string { + if (result.errors.length > 0) { + const fullError = result.errors.map((e) => `${e.message}\r\n${e.stack ? e.stack : ''}\r\n`).join(); + return this.cleanseReason(fullError); } - return testResults; + return `${this.cleanseReason( + result.error?.message, + )} \n ${this.cleanseReason(result.error?.stack)}`; } cleanseReason(rawReaseon: string): string { diff --git a/src/custom_block/my_block.ts b/src/custom_block/my_block.ts index f7a0a57..2c4b0d0 100644 --- a/src/custom_block/my_block.ts +++ b/src/custom_block/my_block.ts @@ -88,11 +88,7 @@ const generateCustomLayout = (summaryResults: SummaryResults):Array 0 ? `:fast_forward: *${summaryResults.skipped}* skipped` : '' - } \n\n ${ - summaryResults.aborted > 0 - ? `:exclamation: *${summaryResults.aborted}* aborted` - : '' - }`, + } \n\n `, }, }, { diff --git a/src/index.ts b/src/index.ts index 9ec6353..bd64434 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,6 @@ export type SummaryResults = { passed: number; failed: number; skipped: number; - aborted: number; failures: Array; meta?: Array<{ key: string; value: string }>; tests: Array<{ @@ -13,7 +12,7 @@ export type SummaryResults = { reason: string; retry: number; startedAt: string; - status: 'failed' | 'passed' | 'skipped' | 'aborted'; + status: 'passed' | 'failed' | 'timedOut' | 'skipped'; attachments?: { body: string | undefined | Buffer; contentType: string; diff --git a/tests/ResultsParser.spec.ts b/tests/ResultsParser.spec.ts index f0a8ae1..4aa55c2 100644 --- a/tests/ResultsParser.spec.ts +++ b/tests/ResultsParser.spec.ts @@ -100,12 +100,10 @@ test.describe('ResultsParser', () => { passed: 0, failed: 1, skipped: 0, - aborted: 0, failures: [ { test: 'basic test failure ', - failureReason: - 'expect(received).toHaveText(expected)\n\nExpected string: "Playwright Fail"\nReceived string: "Playwright"\nCall log:\n - expect.toHaveText with timeout 1000ms\n - waiting for selector ".navbar__inner .navbar__title"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n \n Error: expect(received).toHaveText(expected)\n\nExpected string: "Playwright Fail"\nReceived string: "Playwright"\nCall log:\n - expect.toHaveText with timeout 1000ms\n - waiting for selector ".navbar__inner .navbar__title"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n\n at /home/ry/_repo/playwright-slack-report/tests/t1.spec.ts:17:23', + failureReason: 'expect(received).toHaveText(expected)\n\nExpected string: "Playwright Fail"\nReceived string: "Playwright"\nCall log:\n - expect.toHaveText with timeout 1000ms\n - waiting for selector ".navbar__inner .navbar__title"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n\r\nError: expect(received).toHaveText(expected)\n\nExpected string: "Playwright Fail"\nReceived string: "Playwright"\nCall log:\n - expect.toHaveText with timeout 1000ms\n - waiting for selector ".navbar__inner .navbar__title"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n\n at /home/ry/_repo/playwright-slack-report/tests/t1.spec.ts:17:23\r\n', }, ], tests: [ @@ -116,18 +114,14 @@ test.describe('ResultsParser', () => { retry: 0, startedAt: '2021-12-18T09:43:16.000Z', endedAt: '2021-12-18T09:43:39.591Z', - reason: - 'expect(received).toHaveText(expected)\n\nExpected string: "Playwright Fail"\nReceived string: "Playwright"\nCall log:\n - expect.toHaveText with timeout 1000ms\n - waiting for selector ".navbar__inner .navbar__title"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n \n Error: expect(received).toHaveText(expected)\n\nExpected string: "Playwright Fail"\nReceived string: "Playwright"\nCall log:\n - expect.toHaveText with timeout 1000ms\n - waiting for selector ".navbar__inner .navbar__title"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n\n at /home/ry/_repo/playwright-slack-report/tests/t1.spec.ts:17:23', + reason: 'expect(received).toHaveText(expected)\n\nExpected string: "Playwright Fail"\nReceived string: "Playwright"\nCall log:\n - expect.toHaveText with timeout 1000ms\n - waiting for selector ".navbar__inner .navbar__title"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n\r\nError: expect(received).toHaveText(expected)\n\nExpected string: "Playwright Fail"\nReceived string: "Playwright"\nCall log:\n - expect.toHaveText with timeout 1000ms\n - waiting for selector ".navbar__inner .navbar__title"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n - selector resolved to Playwright\n - unexpected value "Playwright"\n\n at /home/ry/_repo/playwright-slack-report/tests/t1.spec.ts:17:23\r\n', attachments: [ { name: 'screenshot', path: undefined, contentType: 'text/plain', - body: new Uint8Array([ - 116, 104, 105, 115, 32, 105, 115, 32, 97, 32, 109, 101, 115, - 115, 97, 103, 101, 32, 97, 116, 116, 97, 99, 104, 101, 100, 32, - 116, 111, 32, 116, 104, 101, 32, 116, 101, 115, 116, - ]), + // eslint-disable-next-line max-len + body: new Uint8Array([116, 104, 105, 115, 32, 105, 115, 32, 97, 32, 109, 101, 115, 115, 97, 103, 101, 32, 97, 116, 116, 97, 99, 104, 101, 100, 32, 116, 111, 32, 116, 104, 101, 32, 116, 101, 115, 116]), }, { name: 'video', diff --git a/tests/SlackClient_generate_blocks.spec.ts b/tests/SlackClient_generate_blocks.spec.ts index 2036217..d85ec2f 100644 --- a/tests/SlackClient_generate_blocks.spec.ts +++ b/tests/SlackClient_generate_blocks.spec.ts @@ -4,7 +4,6 @@ import generateBlocks from '../src/LayoutGenerator'; test.describe('SlackClient.generateBlocks()', () => { test('creates blocks with correct stats summary', async () => { const generatedBlock = await generateBlocks({ - aborted: 1, failed: 1, passed: 1, skipped: 1, @@ -16,7 +15,7 @@ test.describe('SlackClient.generateBlocks()', () => { type: 'section', text: { type: 'mrkdwn', - text: ':white_check_mark: *1* Tests ran successfully \n\n :red_circle: *1* Tests failed \n\n :fast_forward: *1* skipped \n\n :exclamation: *1* aborted', + text: ':white_check_mark: *1* Tests ran successfully \n\n :red_circle: *1* Tests failed \n\n :fast_forward: *1* skipped \n\n ', }, }, { @@ -34,7 +33,6 @@ test.describe('SlackClient.generateBlocks()', () => { test('creates blocks when meta provided', async () => { const generatedBlock = await generateBlocks({ - aborted: 0, failed: 0, passed: 1, skipped: 1, @@ -70,7 +68,6 @@ test.describe('SlackClient.generateBlocks()', () => { test('creates blocks when test with attachment is provided', async () => { const generatedBlock = await generateBlocks({ - aborted: 0, failed: 1, passed: 0, skipped: 1, diff --git a/tests/fixtures.ts b/tests/fixtures.ts index 610e02c..13cc954 100644 --- a/tests/fixtures.ts +++ b/tests/fixtures.ts @@ -19,7 +19,6 @@ export const test = base.extend({ await use(fakeSlackClient); }, testSummaryAllTestsPassed: { - aborted: 0, failed: 0, passed: 1, skipped: 0, @@ -37,7 +36,6 @@ export const test = base.extend({ ], }, testSummaryAllTestsFailed: { - aborted: 0, failed: 1, passed: 0, skipped: 0,