@allurereport/plugin-slack 3.0.0-beta.3
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 +54 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/plugin.d.ts +11 -0
- package/dist/plugin.js +76 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Slack Plugin
|
|
2
|
+
|
|
3
|
+
[<img src="https://allurereport.org/public/img/allure-report.svg" height="85px" alt="Allure Report logo" align="right" />](https://allurereport.org "Allure Report")
|
|
4
|
+
|
|
5
|
+
- Learn more about Allure Report at https://allurereport.org
|
|
6
|
+
- 📚 [Documentation](https://allurereport.org/docs/) – discover official documentation for Allure Report
|
|
7
|
+
- ❓ [Questions and Support](https://github.com/orgs/allure-framework/discussions/categories/questions-support) – get help from the team and community
|
|
8
|
+
- 📢 [Official announcements](https://github.com/orgs/allure-framework/discussions/categories/announcements) – be in touch with the latest updates
|
|
9
|
+
- 💬 [General Discussion ](https://github.com/orgs/allure-framework/discussions/categories/general-discussion) – engage in casual conversations, share insights and ideas with the community
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
The plugin sends notifications about failed tests to a given Slack channel.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
Use your favorite package manager to install the package:
|
|
20
|
+
|
|
21
|
+
```shell
|
|
22
|
+
npm add @allurereport/plugin-slack
|
|
23
|
+
yarn add @allurereport/plugin-slack
|
|
24
|
+
pnpm add @allurereport/plugin-slack
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then, add the plugin to the Allure configuration file:
|
|
28
|
+
|
|
29
|
+
```diff
|
|
30
|
+
import { defineConfig } from "allure";
|
|
31
|
+
|
|
32
|
+
export default defineConfig({
|
|
33
|
+
name: "Allure Report",
|
|
34
|
+
output: "./allure-report",
|
|
35
|
+
historyPath: "./history.jsonl",
|
|
36
|
+
plugins: {
|
|
37
|
+
+ slack: {
|
|
38
|
+
+ options: {
|
|
39
|
+
+ channel: "my_channel",
|
|
40
|
+
+ token: "my_token",
|
|
41
|
+
+ },
|
|
42
|
+
+ },
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Options
|
|
48
|
+
|
|
49
|
+
The plugin accepts the following options:
|
|
50
|
+
|
|
51
|
+
| Option | Description | Type |
|
|
52
|
+
|-----------|----------------------------|----------|
|
|
53
|
+
| `channel` | Name of the target channel | `string` |
|
|
54
|
+
| `token` | Slack API token | `string` |
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AllureStore, Plugin, PluginContext } from "@allurereport/plugin-api";
|
|
2
|
+
interface SlackPluginOptions {
|
|
3
|
+
channel?: string;
|
|
4
|
+
token?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class SlackPlugin implements Plugin {
|
|
7
|
+
readonly options: SlackPluginOptions;
|
|
8
|
+
constructor(options?: SlackPluginOptions);
|
|
9
|
+
done: (context: PluginContext, store: AllureStore) => Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const defaultSort = (a, b) => (a.fullName ?? "").localeCompare(b.fullName ?? "");
|
|
2
|
+
export class SlackPlugin {
|
|
3
|
+
constructor(options = {}) {
|
|
4
|
+
this.options = options;
|
|
5
|
+
this.done = async (context, store) => {
|
|
6
|
+
const { reportFiles } = context;
|
|
7
|
+
const statistic = await store.testsStatistic();
|
|
8
|
+
if (statistic.total === 0) {
|
|
9
|
+
throw new Error("no test results found");
|
|
10
|
+
}
|
|
11
|
+
const stat = (status) => {
|
|
12
|
+
if (statistic[status]) {
|
|
13
|
+
return [
|
|
14
|
+
{
|
|
15
|
+
type: "text",
|
|
16
|
+
text: `${status} tests: `,
|
|
17
|
+
style: {
|
|
18
|
+
bold: true,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
type: "text",
|
|
23
|
+
text: `${statistic[status]}\n`,
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
return [];
|
|
28
|
+
};
|
|
29
|
+
const t = (result) => {
|
|
30
|
+
return {
|
|
31
|
+
type: "rich_text_section",
|
|
32
|
+
elements: [
|
|
33
|
+
{
|
|
34
|
+
type: "text",
|
|
35
|
+
text: result.fullName ?? "unknown test",
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
const testResults = await store.failedTestResults();
|
|
41
|
+
const tests = testResults.sort(defaultSort).map(t);
|
|
42
|
+
const blocks = [
|
|
43
|
+
{
|
|
44
|
+
type: "rich_text",
|
|
45
|
+
elements: [
|
|
46
|
+
{
|
|
47
|
+
type: "rich_text_section",
|
|
48
|
+
elements: [...stat("failed"), ...stat("broken"), ...stat("passed"), ...stat("skipped"), ...stat("unknown")],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
type: "rich_text_list",
|
|
52
|
+
style: "bullet",
|
|
53
|
+
elements: [...tests],
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
const { token = process.env.ALLURE_SLACK_TOKEN, channel = process.env.ALLURE_SLACK_CHANNEL } = this.options;
|
|
59
|
+
const response = await fetch("https://slack.com/api/chat.postMessage", {
|
|
60
|
+
method: "POST",
|
|
61
|
+
body: JSON.stringify({
|
|
62
|
+
channel,
|
|
63
|
+
blocks,
|
|
64
|
+
}),
|
|
65
|
+
headers: {
|
|
66
|
+
"Content-Type": "application/json;charset=utf-8",
|
|
67
|
+
Authorization: `Bearer ${token}`,
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
const { ok, error } = (await response.json());
|
|
71
|
+
if (!ok) {
|
|
72
|
+
throw new Error(`slack error: ${error}`);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@allurereport/plugin-slack",
|
|
3
|
+
"version": "3.0.0-beta.3",
|
|
4
|
+
"description": "Allure Plugin to Report results to Slack",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"allure",
|
|
7
|
+
"testing",
|
|
8
|
+
"report",
|
|
9
|
+
"plugin",
|
|
10
|
+
"slack"
|
|
11
|
+
],
|
|
12
|
+
"repository": "https://github.com/allure-framework/allure3",
|
|
13
|
+
"license": "Apache-2.0",
|
|
14
|
+
"author": "Qameta Software",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"main": "./dist/index.js",
|
|
20
|
+
"module": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"files": [
|
|
23
|
+
"./dist"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "run clean && tsc --project ./tsconfig.json",
|
|
27
|
+
"clean": "rimraf ./dist",
|
|
28
|
+
"test": "rimraf ./out && vitest run"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@allurereport/core-api": "3.0.0-beta.3",
|
|
32
|
+
"@allurereport/plugin-api": "3.0.0-beta.3"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@stylistic/eslint-plugin": "^2.6.1",
|
|
36
|
+
"@types/eslint": "^8.56.11",
|
|
37
|
+
"@types/node": "^20.17.9",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
39
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
40
|
+
"@vitest/runner": "^2.1.8",
|
|
41
|
+
"allure-vitest": "^3.0.7",
|
|
42
|
+
"eslint": "^8.57.0",
|
|
43
|
+
"eslint-config-prettier": "^9.1.0",
|
|
44
|
+
"eslint-plugin-import": "^2.29.1",
|
|
45
|
+
"eslint-plugin-jsdoc": "^50.0.0",
|
|
46
|
+
"eslint-plugin-n": "^17.10.1",
|
|
47
|
+
"eslint-plugin-no-null": "^1.0.2",
|
|
48
|
+
"eslint-plugin-prefer-arrow": "^1.2.3",
|
|
49
|
+
"rimraf": "^6.0.1",
|
|
50
|
+
"typescript": "^5.6.3",
|
|
51
|
+
"vitest": "^2.1.8"
|
|
52
|
+
}
|
|
53
|
+
}
|