playwright-slack-report 1.1.54 → 1.1.55

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
@@ -1,4 +1,5 @@
1
1
  # playwright-slack-report ![Builds](https://github.com/ryanrosello-og/playwright-slack-report/actions/workflows/playwright.yml/badge.svg) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ryanrosello-og/playwright-slack-report/blob/master/LICENSE) [![Coverage Status](https://coveralls.io/repos/github/ryanrosello-og/playwright-slack-report/badge.svg?branch=main)](https://coveralls.io/github/ryanrosello-og/playwright-slack-report?branch=main)
2
+ [code quatlity badge][![CodeQL](https://github.com/ryanrosello-og/playwright-slack-report/actions/workflows/github-code-scanning/codeql/badge.svg?branch=main)](https://github.com/ryanrosello-og/playwright-slack-report/actions/workflows/github-code-scanning/codeql)
2
3
 
3
4
  [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/ryanrosello-og/playwright-slack-report)
4
5
 
@@ -153,23 +154,74 @@ Next, you will need to configure the cli. See example below:
153
154
  "maxNumberOfFailures": 4,
154
155
  "disableUnfurl": true
155
156
  }
157
+ ```
158
+
159
+ The config file also supports the follow extra options:
160
+ * `proxy` - String representation of your proxy server.
161
+ * `sendUsingWebhook` - Object containing the webhook url to send the results to
156
162
 
157
- The config file also supports the follow extra options for using a proxy and sending results via a webhook:
158
163
 
159
164
 
160
165
  ```json
161
- ...
166
+ {
167
+ "sendResults": "always",
168
+ "slackLogLevel": "error",
162
169
  "proxy": "http://proxy.mycompany.com:8080",
163
170
  "sendUsingWebhook": {
164
171
  "webhookUrl": "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
165
172
  },
166
- ...
173
+ "showInThread": true,
174
+ "meta": [
175
+ { "key": "build", "value" : "1.0.0"},
176
+ { "key": "branch", "value" : "master"},
177
+ { "key": "commit", "value" : "1234567890"},
178
+ { "key": "results", "value" : "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"}
179
+ ],
180
+ "maxNumberOfFailures": 4,
181
+ "disableUnfurl": true
182
+ }
167
183
  ```
168
184
 
169
185
  Once you have generated the JSON report and defined your config file, you can send it to Slack using the following command:
170
186
 
171
187
  `SLACK_BOT_USER_OAUTH_TOKEN=[your Slack bot user OAUTH token] npx playwright-slack-report -c cli_config.json -j ./merged_tests_results.json`
172
188
 
189
+ Both the `-c` and `-j` options are required. The `-c` option is the path to your config file and the `-j` option is the path to your merged JSON report.
190
+
191
+ ### Additional notes
192
+ * The CLI currently does not support custom layouts 👎🥺
193
+ * The config file for the cli app is stand-alone, which means you no longer need to define the Playwright slack reporter in your `playwright.config.ts` file
194
+ * In order to handle dynamic meta data e.g. environment variables storing your build id, branch name etc, you can use the `meta` option in the config file and use the format: `{__ENV_VARIABLE_NAME}` as its value. This will be replaced with the actual value of the environment variable at runtime. See example below:
195
+
196
+ In your `cli_config.json` file:
197
+
198
+ `__ENV_BUILD_ID` is equivalent to `process.env.BUILD_ID`. This will be automatically handled for you.
199
+
200
+ You will encounter the following error if the environment variable is not defined:
201
+
202
+ ```bash
203
+ ❌ Environment variable [blah] was not set.
204
+ This variable was found in the [meta] section of the config file, ensure the variable is set in your environment.
205
+ ```
206
+
207
+ ```json
208
+ {
209
+ "sendResults": "always",
210
+ "slackLogLevel": "error",
211
+ "sendUsingBot": {
212
+ "channels": ["demo"]
213
+ },
214
+ "showInThread": true,
215
+ "meta": [
216
+ { "key": "build", "value" : "{__ENV_BUILD_ID}"},
217
+ { "key": "branch", "value" : "{__ENV_BRANCH_NAME}"},
218
+ { "key": "commit", "value" : "{__ENV_COMMIT_ID}"},
219
+ { "key": "results", "value" : "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"}
220
+ ],
221
+ "maxNumberOfFailures": 4,
222
+ "disableUnfurl": true
223
+ }
224
+ ```
173
225
 
174
226
  # ⚙️ Configuration
175
227
 
package/dist/cli.js CHANGED
@@ -54,12 +54,15 @@ program
54
54
  agent,
55
55
  });
56
56
  const slackWebhookClient = new SlackWebhookClient_1.default(webhook);
57
+ let summaryResults = resultSummary;
58
+ const meta = replaceEnvVars(config.meta);
59
+ summaryResults = { ...resultSummary, meta };
57
60
  const webhookResult = await slackWebhookClient.sendMessage({
58
61
  customLayout: undefined,
59
62
  customLayoutAsync: undefined,
60
63
  maxNumberOfFailures: config.maxNumberOfFailures,
61
64
  disableUnfurl: config.disableUnfurl,
62
- summaryResults: resultSummary,
65
+ summaryResults,
63
66
  });
64
67
  // eslint-disable-next-line no-console
65
68
  console.log(JSON.stringify(webhookResult, null, 2));
@@ -78,7 +81,8 @@ async function sendResultsUsingBot({ resultSummary, slackClient, config, }) {
78
81
  return true;
79
82
  }
80
83
  let summaryResults = resultSummary;
81
- summaryResults = { ...resultSummary, meta: config.meta };
84
+ const meta = replaceEnvVars(config.meta);
85
+ summaryResults = { ...resultSummary, meta };
82
86
  if (config.sendUsingBot) {
83
87
  const result = await slackClient.sendMessage({
84
88
  options: {
@@ -110,4 +114,25 @@ async function sendResultsUsingBot({ resultSummary, slackClient, config, }) {
110
114
  }
111
115
  throw new Error('sendUsingBot config is not set');
112
116
  }
117
+ function replaceEnvVars(originalMeta) {
118
+ const newMeta = [];
119
+ // eslint-disable-next-line no-restricted-syntax
120
+ for (const m of originalMeta) {
121
+ let metaValue = m.value;
122
+ if (m.value.startsWith('__ENV')) {
123
+ const environmentVarName = m.value.replace('__ENV_', '');
124
+ if (process.env[environmentVarName]) {
125
+ metaValue = process.env[environmentVarName];
126
+ }
127
+ else {
128
+ const warningMessage = `❌ Environment variable [${environmentVarName}] was not set.
129
+ This variable was found in the [meta] section of the config file, ensure the variable is set in your environment.`;
130
+ console.log(warningMessage);
131
+ metaValue = warningMessage;
132
+ }
133
+ }
134
+ newMeta.push({ key: m.key, value: metaValue });
135
+ }
136
+ return newMeta;
137
+ }
113
138
  //# sourceMappingURL=cli.js.map
@@ -5,10 +5,7 @@ export type SummaryResults = {
5
5
  flaky: number | undefined;
6
6
  skipped: number;
7
7
  failures: Array<failure>;
8
- meta?: Array<{
9
- key: string;
10
- value: string;
11
- }>;
8
+ meta?: Meta;
12
9
  tests: Array<{
13
10
  suiteName: string;
14
11
  name: string;
@@ -27,6 +24,10 @@ export type SummaryResults = {
27
24
  }[];
28
25
  }>;
29
26
  };
27
+ export type Meta = Array<{
28
+ key: string;
29
+ value: string;
30
+ }>;
30
31
  export type failure = {
31
32
  test: string;
32
33
  failureReason: string;
package/package.json CHANGED
@@ -32,10 +32,10 @@
32
32
  "lint": "npx eslint . --ext .ts",
33
33
  "lint-fix": "npx eslint . --ext .ts --fix",
34
34
  "cli": "yarn build && node dist/cli.js",
35
- "cli-debug": "yarn build && npx . -c ./tests/test_data/valid_cli_config.json -j ./tests/test_data/valid_test_results.json"
35
+ "cli-debug": "yarn build && npx . -c ./cli_config.json -j ./tests/test_data/valid_test_results.json"
36
36
  },
37
37
  "name": "playwright-slack-report",
38
- "version": "1.1.54",
38
+ "version": "1.1.55",
39
39
  "bin": {
40
40
  "playwright-slack-report": "dist/cli.js"
41
41
  },