playwright-slack-report 1.0.12 → 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 +3 -1
- package/dist/src/ResultsParser.d.ts +4 -1
- package/dist/src/ResultsParser.js +36 -10
- package/dist/src/SlackClient.js +3 -0
- package/dist/src/SlackReporter.js +4 -2
- package/dist/src/index.d.ts +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
# playwright-slack-report  [](https://github.com/ryanrosello-og/playwright-slack-report/blob/master/LICENSE)
|
|
1
|
+
# playwright-slack-report  [](https://github.com/ryanrosello-og/playwright-slack-report/blob/master/LICENSE) [](https://coveralls.io/github/ryanrosello-og/playwright-slack-report?branch=main)
|
|
2
2
|
|
|
3
3
|
[](https://gitpod.io/#https://github.com/ryanrosello-og/playwright-slack-report)
|
|
4
4
|
|
|
5
|
+

|
|
6
|
+
|
|
5
7
|
Publish your Playwright test results to your favorite Slack channel(s).
|
|
6
8
|
|
|
7
9
|

|
|
@@ -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,
|
|
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
|
-
//
|
|
40
|
-
|
|
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
|
|
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,
|
|
68
|
+
addTestResult(suiteName, testCase) {
|
|
59
69
|
const testResults = [];
|
|
60
|
-
for (const result of
|
|
70
|
+
for (const result of testCase.results) {
|
|
61
71
|
testResults.push({
|
|
62
72
|
suiteName,
|
|
63
|
-
name:
|
|
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
|
|
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
|
-
|
|
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;
|
package/dist/src/SlackClient.js
CHANGED
|
@@ -34,6 +34,9 @@ class SlackClient {
|
|
|
34
34
|
// eslint-disable-next-line no-console
|
|
35
35
|
console.log(`✅ Message sent to ${channel}`);
|
|
36
36
|
}
|
|
37
|
+
else {
|
|
38
|
+
result.push({ channel, outcome: `❌ Message not sent to ${channel} \r\n ${JSON.stringify(chatResponse, null, 2)}` });
|
|
39
|
+
}
|
|
37
40
|
}
|
|
38
41
|
catch (error) {
|
|
39
42
|
result.push({
|
|
@@ -37,20 +37,22 @@ 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
|
}
|
|
44
44
|
const slackClient = new SlackClient_1.default(new web_api_1.WebClient(process.env.SLACK_BOT_USER_OAUTH_TOKEN, {
|
|
45
45
|
logLevel: web_api_1.LogLevel.DEBUG,
|
|
46
46
|
}));
|
|
47
|
-
await slackClient.sendMessage({
|
|
47
|
+
const result = await slackClient.sendMessage({
|
|
48
48
|
options: {
|
|
49
49
|
channelIds: this.slackChannels,
|
|
50
50
|
summaryResults: resultSummary,
|
|
51
51
|
customLayout: this.customLayout,
|
|
52
52
|
},
|
|
53
53
|
});
|
|
54
|
+
// eslint-disable-next-line no-console
|
|
55
|
+
console.log(JSON.stringify(result, null, 2));
|
|
54
56
|
}
|
|
55
57
|
preChecks() {
|
|
56
58
|
if (this.sendResults === 'off') {
|
package/dist/src/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"prettier": "prettier --write --loglevel warn \"**/**/*.ts\"",
|
|
26
|
-
"pw": "nyc playwright test",
|
|
26
|
+
"pw": "nyc playwright test && nyc report --reporter=lcov",
|
|
27
27
|
"build": "tsc -p ./tsconfig.json",
|
|
28
28
|
"lint":"npx eslint . --ext .ts"
|
|
29
29
|
},
|
|
30
30
|
"name": "playwright-slack-report",
|
|
31
|
-
"version": "1.0.
|
|
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",
|