playwright-slack-report 1.0.20 → 1.1.1
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 +9 -2
- package/dist/src/SlackClient.d.ts +4 -2
- package/dist/src/SlackReporter.d.ts +6 -4
- package/dist/src/SlackReporter.js +11 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ Modify your `playwright.config.ts` file to include the following:
|
|
|
43
43
|
],
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
Run your tests by providing your`
|
|
46
|
+
Run your tests by providing your `SLACK_BOT_USER_OAUTH_TOKEN` as an environment variable or specifying `slackOAuthToken` option in the config:
|
|
47
47
|
|
|
48
48
|
`SLACK_BOT_USER_OAUTH_TOKEN=[your Slack bot user OAUTH token] npx playwright test`
|
|
49
49
|
|
|
@@ -102,7 +102,7 @@ An example advanced configuration is shown below:
|
|
|
102
102
|
|
|
103
103
|
```typescript
|
|
104
104
|
import { generateCustomLayout } from "./my_custom_layout";
|
|
105
|
-
|
|
105
|
+
import { LogLevel } from '@slack/web-api';
|
|
106
106
|
...
|
|
107
107
|
|
|
108
108
|
reporter: [
|
|
@@ -127,6 +127,8 @@ An example advanced configuration is shown below:
|
|
|
127
127
|
value: '<https://your-build-artifacts.my.company.dev/pw/23887/playwright-report/index.html|📊>',
|
|
128
128
|
},
|
|
129
129
|
],
|
|
130
|
+
slackOAuthToken: 'YOUR_SLACK_OAUTH_TOKEN',
|
|
131
|
+
slackLogLevel: LogLevel.DEBUG
|
|
130
132
|
},
|
|
131
133
|
|
|
132
134
|
],
|
|
@@ -147,6 +149,11 @@ A function that returns a layout object, this configuration is optional. See se
|
|
|
147
149
|
Same as **layout** above, but asynchronous in that it returns a promise.
|
|
148
150
|
### **maxNumberOfFailuresToShow**
|
|
149
151
|
Limits the number of failures shown in the Slack message, defaults to 10.
|
|
152
|
+
### **slackOAuthToken**
|
|
153
|
+
Instead of providing an environment variable `SLACK_BOT_USER_OAUTH_TOKEN` you can specify the token in the config in the `slackOAuthToken` field.
|
|
154
|
+
### **slackLogLevel** (default LogLevel.DEBUG)
|
|
155
|
+
This option allows you to control slack client severity levels for log entries. It accepts a value from @slack/web-api `LogLevel` enum
|
|
156
|
+
|
|
150
157
|
|
|
151
158
|
**Examples:**
|
|
152
159
|
```typescript
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WebClient, KnownBlock, Block, ChatPostMessageResponse } from '@slack/web-api';
|
|
1
|
+
import { WebClient, KnownBlock, Block, ChatPostMessageResponse, LogLevel } from '@slack/web-api';
|
|
2
2
|
import { SummaryResults } from '.';
|
|
3
3
|
export declare type additionalInfo = Array<{
|
|
4
4
|
key: string;
|
|
@@ -10,11 +10,13 @@ export default class SlackClient {
|
|
|
10
10
|
sendMessage({ options, }: {
|
|
11
11
|
options: {
|
|
12
12
|
channelIds: Array<string>;
|
|
13
|
-
summaryResults: SummaryResults;
|
|
14
13
|
customLayout: Function | undefined;
|
|
15
14
|
customLayoutAsync: Function | undefined;
|
|
16
15
|
fakeRequest?: Function;
|
|
17
16
|
maxNumberOfFailures: number;
|
|
17
|
+
slackOAuthToken?: string;
|
|
18
|
+
slackLogLevel?: LogLevel;
|
|
19
|
+
summaryResults: SummaryResults;
|
|
18
20
|
};
|
|
19
21
|
}): Promise<Array<{
|
|
20
22
|
channel: string;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { FullConfig, Reporter, Suite, TestCase, TestResult } from '@playwright/test/reporter';
|
|
2
2
|
declare class SlackReporter implements Reporter {
|
|
3
|
-
private suite;
|
|
4
|
-
private sendResults;
|
|
5
|
-
private slackChannels;
|
|
6
|
-
private meta;
|
|
7
3
|
private customLayout;
|
|
8
4
|
private customLayoutAsync;
|
|
9
5
|
private maxNumberOfFailuresToShow;
|
|
6
|
+
private meta;
|
|
10
7
|
private resultsParser;
|
|
8
|
+
private sendResults;
|
|
9
|
+
private slackChannels;
|
|
10
|
+
private slackLogLevel;
|
|
11
|
+
private slackOAuthToken;
|
|
12
|
+
private suite;
|
|
11
13
|
logs: string[];
|
|
12
14
|
onBegin(fullConfig: FullConfig, suite: Suite): void;
|
|
13
15
|
onTestEnd(test: TestCase, result: TestResult): void;
|
|
@@ -4,14 +4,16 @@ const web_api_1 = require("@slack/web-api");
|
|
|
4
4
|
const ResultsParser_1 = require("./ResultsParser");
|
|
5
5
|
const SlackClient_1 = require("./SlackClient");
|
|
6
6
|
class SlackReporter {
|
|
7
|
-
suite;
|
|
8
|
-
sendResults = 'on-failure';
|
|
9
|
-
slackChannels = [];
|
|
10
|
-
meta = [];
|
|
11
7
|
customLayout;
|
|
12
8
|
customLayoutAsync;
|
|
13
9
|
maxNumberOfFailuresToShow;
|
|
10
|
+
meta = [];
|
|
14
11
|
resultsParser;
|
|
12
|
+
sendResults = 'on-failure';
|
|
13
|
+
slackChannels = [];
|
|
14
|
+
slackLogLevel;
|
|
15
|
+
slackOAuthToken;
|
|
16
|
+
suite;
|
|
15
17
|
logs = [];
|
|
16
18
|
onBegin(fullConfig, suite) {
|
|
17
19
|
this.suite = suite;
|
|
@@ -45,16 +47,16 @@ class SlackReporter {
|
|
|
45
47
|
this.log('⏩ Slack reporter - no failures found');
|
|
46
48
|
return;
|
|
47
49
|
}
|
|
48
|
-
const slackClient = new SlackClient_1.default(new web_api_1.WebClient(process.env.SLACK_BOT_USER_OAUTH_TOKEN, {
|
|
49
|
-
logLevel: web_api_1.LogLevel.DEBUG,
|
|
50
|
+
const slackClient = new SlackClient_1.default(new web_api_1.WebClient(this.slackOAuthToken || process.env.SLACK_BOT_USER_OAUTH_TOKEN, {
|
|
51
|
+
logLevel: this.slackLogLevel || web_api_1.LogLevel.DEBUG,
|
|
50
52
|
}));
|
|
51
53
|
const result = await slackClient.sendMessage({
|
|
52
54
|
options: {
|
|
53
55
|
channelIds: this.slackChannels,
|
|
54
|
-
summaryResults: resultSummary,
|
|
55
56
|
customLayout: this.customLayout,
|
|
56
57
|
customLayoutAsync: this.customLayoutAsync,
|
|
57
58
|
maxNumberOfFailures: this.maxNumberOfFailuresToShow,
|
|
59
|
+
summaryResults: resultSummary,
|
|
58
60
|
},
|
|
59
61
|
});
|
|
60
62
|
// eslint-disable-next-line no-console
|
|
@@ -64,10 +66,10 @@ class SlackReporter {
|
|
|
64
66
|
if (this.sendResults === 'off') {
|
|
65
67
|
return { okToProceed: false, message: '❌ Slack reporter is disabled' };
|
|
66
68
|
}
|
|
67
|
-
if (!process.env.SLACK_BOT_USER_OAUTH_TOKEN) {
|
|
69
|
+
if (!this.slackOAuthToken && !process.env.SLACK_BOT_USER_OAUTH_TOKEN) {
|
|
68
70
|
return {
|
|
69
71
|
okToProceed: false,
|
|
70
|
-
message: '❌ SLACK_BOT_USER_OAUTH_TOKEN
|
|
72
|
+
message: '❌ Neither slackOAuthToken nor process.env.SLACK_BOT_USER_OAUTH_TOKEN were found',
|
|
71
73
|
};
|
|
72
74
|
}
|
|
73
75
|
if (!this.sendResults
|
package/package.json
CHANGED