@allurereport/plugin-slack 3.20.0 → 3.21.0

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
@@ -48,7 +48,23 @@ export default defineConfig({
48
48
 
49
49
  The plugin accepts the following options:
50
50
 
51
- | Option | Description | Type |
52
- |-----------|----------------------------|----------|
53
- | `channel` | Name of the target channel | `string` |
54
- | `token` | Slack API token | `string` |
51
+ | Option | Description | Type | Env variable |
52
+ | --------- | -------------------------------------------------------------- | -------- | ---------------------- |
53
+ | `channel` | Name or ID of the target channel. Used together with `token` | `string` | `ALLURE_SLACK_CHANNEL` |
54
+ | `token` | Slack API token. Used together with `channel` | `string` | `ALLURE_SLACK_TOKEN` |
55
+ | `webhook` | Slack incoming webhook URL. Takes precedence over token/channel | `string` | `ALLURE_SLACK_WEBHOOK` |
56
+
57
+ The options can also be provided through the environment variables listed above. Use either a webhook or the
58
+ token/channel pair.
59
+
60
+ For example, to use an incoming webhook from the environment, no explicit credential option is required:
61
+
62
+ ```diff
63
+ export default defineConfig({
64
+ plugins: {
65
+ slack: {
66
+ + options: {},
67
+ },
68
+ },
69
+ });
70
+ ```
package/dist/plugin.d.ts CHANGED
@@ -2,6 +2,7 @@ import type { AllureStore, Plugin, PluginContext } from "@allurereport/plugin-ap
2
2
  export interface SlackPluginOptions {
3
3
  channel?: string;
4
4
  token?: string;
5
+ webhook?: string;
5
6
  }
6
7
  export declare class SlackPlugin implements Plugin {
7
8
  readonly options: SlackPluginOptions;
package/dist/plugin.js CHANGED
@@ -54,7 +54,20 @@ export class SlackPlugin {
54
54
  ],
55
55
  },
56
56
  ];
57
- const { token = process.env.ALLURE_SLACK_TOKEN, channel = process.env.ALLURE_SLACK_CHANNEL } = this.options;
57
+ const { token = process.env.ALLURE_SLACK_TOKEN, channel = process.env.ALLURE_SLACK_CHANNEL, webhook = process.env.ALLURE_SLACK_WEBHOOK, } = this.options;
58
+ if (webhook) {
59
+ const response = await fetch(webhook, {
60
+ method: "POST",
61
+ body: JSON.stringify({ blocks }),
62
+ headers: {
63
+ "Content-Type": "application/json;charset=utf-8",
64
+ },
65
+ });
66
+ if (!response.ok) {
67
+ throw new Error(`slack error: ${await response.text()}`);
68
+ }
69
+ return;
70
+ }
58
71
  const response = await fetch("https://slack.com/api/chat.postMessage", {
59
72
  method: "POST",
60
73
  body: JSON.stringify({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allurereport/plugin-slack",
3
- "version": "3.20.0",
3
+ "version": "3.21.0",
4
4
  "description": "Allure Plugin to Report results to Slack",
5
5
  "keywords": [
6
6
  "allure",
@@ -26,15 +26,18 @@
26
26
  "build": "run clean && tsc --project ./tsconfig.json",
27
27
  "clean": "rimraf ./dist",
28
28
  "test": "rimraf ./out && vitest run",
29
+ "test:unit": "yarn test",
29
30
  "lint": "oxlint --import-plugin src test features stories",
30
31
  "lint:fix": "oxlint --import-plugin --fix src test features stories"
31
32
  },
32
33
  "dependencies": {
33
- "@allurereport/core-api": "3.20.0",
34
- "@allurereport/plugin-api": "3.20.0"
34
+ "@allurereport/core-api": "3.21.0",
35
+ "@allurereport/plugin-api": "3.21.0"
35
36
  },
36
37
  "devDependencies": {
38
+ "@allurereport/test-config": "3.21.0",
37
39
  "@types/node": "^20",
40
+ "@vitest/coverage-istanbul": "^4.1.0",
38
41
  "@vitest/runner": "^2",
39
42
  "allure-js-commons": "^3",
40
43
  "allure-vitest": "^3",