Skip to content

Commit

Permalink
Fix parser summary (#2)
Browse files Browse the repository at this point in the history
* remove aborted status

* version bump

* treat timedout as failure

* fix cleansing of errors

Co-authored-by: Ryan Rosello <[email protected]>
  • Loading branch information
ryanrosello-og and ryanrosello authored Aug 13, 2022
1 parent b386884 commit 270953f
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 59 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]:ryanrosello-og/playwright-slack-report.git",
Expand Down
6 changes: 1 addition & 5 deletions src/LayoutGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 `,
},
};

Expand Down
43 changes: 13 additions & 30 deletions src/ResultsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,7 +43,6 @@ export default class ResultsParser {
passed: 0,
failed: 0,
skipped: 0,
aborted: 0,
failures: await this.getFailures(),
tests: [],
};
Expand All @@ -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;
}
}
}
Expand All @@ -68,7 +65,7 @@ export default class ResultsParser {
const failures: Array<failure> = [];
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,
Expand Down Expand Up @@ -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,
});
}
Expand All @@ -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 {
Expand Down
6 changes: 1 addition & 5 deletions src/custom_block/my_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,7 @@ const generateCustomLayout = (summaryResults: SummaryResults):Array<KnownBlock |
summaryResults.skipped > 0
? `:fast_forward: *${summaryResults.skipped}* skipped`
: ''
} \n\n ${
summaryResults.aborted > 0
? `:exclamation: *${summaryResults.aborted}* aborted`
: ''
}`,
} \n\n `,
},
},
{
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export type SummaryResults = {
passed: number;
failed: number;
skipped: number;
aborted: number;
failures: Array<failure>;
meta?: Array<{ key: string; value: string }>;
tests: Array<{
Expand All @@ -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;
Expand Down
14 changes: 4 additions & 10 deletions tests/ResultsParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\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 <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\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 <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\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 <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n\n at /home/ry/_repo/playwright-slack-report/tests/t1.spec.ts:17:23\r\n',
},
],
tests: [
Expand All @@ -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 <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\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 <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\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 <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\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 <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\n - unexpected value "Playwright"\n - selector resolved to <b class="navbar__title text--truncate">Playwright</b>\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',
Expand Down
5 changes: 1 addition & 4 deletions tests/SlackClient_generate_blocks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 ',
},
},
{
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions tests/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const test = base.extend<SlackClientFixture>({
await use(fakeSlackClient);
},
testSummaryAllTestsPassed: {
aborted: 0,
failed: 0,
passed: 1,
skipped: 0,
Expand All @@ -37,7 +36,6 @@ export const test = base.extend<SlackClientFixture>({
],
},
testSummaryAllTestsFailed: {
aborted: 0,
failed: 1,
passed: 0,
skipped: 0,
Expand Down

0 comments on commit 270953f

Please sign in to comment.