playwright-slack-report 1.0.14 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/ryanrosello-og/playwright-slack-report)
4
4
 
5
+ ![Main Logo](https://github.com/ryanrosello-og/playwright-slack-report/blob/main/assets/_logo.png?raw=true)
6
+
5
7
  Publish your Playwright test results to your favorite Slack channel(s).
6
8
 
7
9
  ![Gif](https://github.com/ryanrosello-og/playwright-slack-report/blob/main/assets/2022-08-15_20-22-59.png?raw=true)
@@ -4,9 +4,11 @@ export declare type testResult = {
4
4
  suiteName: string;
5
5
  name: string;
6
6
  browser?: string;
7
+ projectName: string;
7
8
  endedAt: string;
8
9
  reason: string;
9
10
  retry: number;
11
+ retries: number;
10
12
  startedAt: string;
11
13
  status: 'passed' | 'failed' | 'timedOut' | 'skipped';
12
14
  attachments?: {
@@ -28,10 +30,11 @@ export default class ResultsParser {
28
30
  constructor();
29
31
  getParsedResults(): Promise<SummaryResults>;
30
32
  getFailures(): Promise<Array<failure>>;
33
+ getTestName(failedTest: any): any;
31
34
  updateResults(data: {
32
35
  testSuite: any;
33
36
  }): void;
34
- addTestResult(suiteName: any, test: any): void;
37
+ addTestResult(suiteName: any, testCase: any): void;
35
38
  safelyDetermineFailure(result: {
36
39
  errors: any[];
37
40
  error: {
@@ -1,4 +1,6 @@
1
1
  "use strict";
2
+ /* eslint-disable no-shadow */
3
+ /* eslint-disable no-underscore-dangle */
2
4
  /* eslint-disable import/extensions */
3
5
  /* eslint-disable no-control-regex */
4
6
  /* eslint-disable class-methods-use-this */
@@ -36,12 +38,10 @@ class ResultsParser {
36
38
  for (const suite of this.result) {
37
39
  for (const test of suite.testSuite.tests) {
38
40
  if (test.status === 'failed' || test.status === 'timedOut') {
39
- // dont add duplicate results (retries)
40
- const failureExists = failures.find((f) => f.test === test.name
41
- && f.failureReason === test.reason);
42
- if (!failureExists) {
41
+ // only flag as failed if the last attempt has failed
42
+ if (test.retries === test.retry) {
43
43
  failures.push({
44
- test: test.name,
44
+ test: this.getTestName(test),
45
45
  failureReason: test.reason,
46
46
  });
47
47
  }
@@ -50,19 +50,38 @@ class ResultsParser {
50
50
  }
51
51
  return failures;
52
52
  }
53
+ getTestName(failedTest) {
54
+ const testName = failedTest.name;
55
+ if (failedTest.browser && failedTest.projectName) {
56
+ if (failedTest.browser === failedTest.projectName) {
57
+ return `${testName} [${failedTest.browser}]`;
58
+ }
59
+ return `${testName} [Project Name: ${failedTest.projectName}] using ${failedTest.browser}`;
60
+ }
61
+ return testName;
62
+ }
53
63
  updateResults(data) {
54
64
  if (data.testSuite.tests.length > 0) {
55
65
  this.result.push(data);
56
66
  }
57
67
  }
58
- addTestResult(suiteName, test) {
68
+ addTestResult(suiteName, testCase) {
59
69
  const testResults = [];
60
- for (const result of test.results) {
70
+ for (const result of testCase.results) {
61
71
  testResults.push({
62
72
  suiteName,
63
- name: test.title,
73
+ name: testCase.title,
64
74
  status: result.status,
75
+ // eslint-disable-next-line no-underscore-dangle
76
+ browser: testCase.parent?.parent?._projectConfig?.use?.defaultBrowserType
77
+ ? testCase.parent.parent._projectConfig.use.defaultBrowserType
78
+ : '',
79
+ // eslint-disable-next-line no-underscore-dangle
80
+ projectName: testCase.parent?.parent?._projectConfig?.name
81
+ ? testCase.parent.parent._projectConfig.name
82
+ : '',
65
83
  retry: result.retry,
84
+ retries: testCase.retries,
66
85
  startedAt: new Date(result.startTime).toISOString(),
67
86
  endedAt: new Date(new Date(result.startTime).getTime() + result.duration).toISOString(),
68
87
  reason: this.safelyDetermineFailure(result),
@@ -78,7 +97,9 @@ class ResultsParser {
78
97
  }
79
98
  safelyDetermineFailure(result) {
80
99
  if (result.errors.length > 0) {
81
- const fullError = result.errors.map((e) => `${e.message}\r\n${e.stack ? e.stack : ''}\r\n`).join();
100
+ const fullError = result.errors
101
+ .map((e) => `${e.message}\r\n${e.stack ? e.stack : ''}\r\n`)
102
+ .join();
82
103
  return this.cleanseReason(fullError);
83
104
  }
84
105
  return `${this.cleanseReason(result.error?.message)} \n ${this.cleanseReason(result.error?.stack)}`;
@@ -86,7 +107,12 @@ class ResultsParser {
86
107
  cleanseReason(rawReaseon) {
87
108
  // eslint-disable-next-line prefer-regex-literals
88
109
  const ansiRegex = new RegExp('([\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~])))', 'g');
89
- return rawReaseon ? rawReaseon.replace(ansiRegex, '') : '';
110
+ const ansiCleansed = rawReaseon ? rawReaseon.replace(ansiRegex, '') : '';
111
+ const logsStripped = ansiCleansed
112
+ .replace(/============================================================\n/g, '')
113
+ .replace(/============================================================\r\n/g, '')
114
+ .replace(/=========================== logs ===========================\n/g, '');
115
+ return logsStripped;
90
116
  }
91
117
  }
92
118
  exports.default = ResultsParser;
@@ -37,7 +37,7 @@ class SlackReporter {
37
37
  resultSummary.meta = this.meta;
38
38
  const maxRetry = Math.max(...resultSummary.tests.map((o) => o.retry));
39
39
  if (this.sendResults === 'on-failure'
40
- && resultSummary.tests.filter((z) => z.status === 'failed' && z.retry === maxRetry).length === 0) {
40
+ && resultSummary.tests.filter((z) => (z.status === 'failed' || z.status === 'timedOut') && z.retry === maxRetry).length === 0) {
41
41
  this.log('⏩ Slack reporter - no failures found');
42
42
  return;
43
43
  }
@@ -12,6 +12,7 @@ export declare type SummaryResults = {
12
12
  suiteName: string;
13
13
  name: string;
14
14
  browser?: string;
15
+ projectName?: string;
15
16
  endedAt: string;
16
17
  reason: string;
17
18
  retry: number;
package/package.json CHANGED
@@ -28,7 +28,7 @@
28
28
  "lint":"npx eslint . --ext .ts"
29
29
  },
30
30
  "name": "playwright-slack-report",
31
- "version": "1.0.14",
31
+ "version": "1.0.16",
32
32
  "main": "index.js",
33
33
  "types": "dist/index.d.ts",
34
34
  "repository": "git@github.com:ryanrosello-og/playwright-slack-report.git",