playwright-slack-report 1.1.1 → 1.1.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.
@@ -1,4 +1,4 @@
1
- import { KnownBlock, Block } from '@slack/types';
2
- import { SummaryResults } from '.';
3
- declare const generateBlocks: (summaryResults: SummaryResults, maxNumberOfFailures: number) => Promise<Array<KnownBlock | Block>>;
4
- export default generateBlocks;
1
+ import { KnownBlock, Block } from '@slack/types';
2
+ import { SummaryResults } from '.';
3
+ declare const generateBlocks: (summaryResults: SummaryResults, maxNumberOfFailures: number) => Promise<Array<KnownBlock | Block>>;
4
+ export default generateBlocks;
@@ -1,69 +1,69 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const generateBlocks = async (summaryResults, maxNumberOfFailures) => {
4
- const maxNumberOfFailureLength = 650;
5
- const fails = [];
6
- const meta = [];
7
- const header = {
8
- type: 'section',
9
- text: {
10
- type: 'mrkdwn',
11
- text: '🎭 *Playwright Results*',
12
- },
13
- };
14
- const summary = {
15
- type: 'section',
16
- text: {
17
- type: 'mrkdwn',
18
- text: `✅ *${summaryResults.passed}* | ❌ *${summaryResults.failed}* | ⏩ *${summaryResults.skipped}*`,
19
- },
20
- };
21
- for (let i = 0; i < summaryResults.failures.length; i += 1) {
22
- const { failureReason, test } = summaryResults.failures[i];
23
- const formattedFailure = failureReason
24
- .substring(0, maxNumberOfFailureLength)
25
- .split('\n')
26
- .map((l) => `>${l}`)
27
- .join('\n');
28
- fails.push({
29
- type: 'section',
30
- text: {
31
- type: 'mrkdwn',
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const generateBlocks = async (summaryResults, maxNumberOfFailures) => {
4
+ const maxNumberOfFailureLength = 650;
5
+ const fails = [];
6
+ const meta = [];
7
+ const header = {
8
+ type: 'section',
9
+ text: {
10
+ type: 'mrkdwn',
11
+ text: '🎭 *Playwright Results*',
12
+ },
13
+ };
14
+ const summary = {
15
+ type: 'section',
16
+ text: {
17
+ type: 'mrkdwn',
18
+ text: `✅ *${summaryResults.passed}* | ❌ *${summaryResults.failed}* | ⏩ *${summaryResults.skipped}*`,
19
+ },
20
+ };
21
+ for (let i = 0; i < summaryResults.failures.length; i += 1) {
22
+ const { failureReason, test } = summaryResults.failures[i];
23
+ const formattedFailure = failureReason
24
+ .substring(0, maxNumberOfFailureLength)
25
+ .split('\n')
26
+ .map((l) => `>${l}`)
27
+ .join('\n');
28
+ fails.push({
29
+ type: 'section',
30
+ text: {
31
+ type: 'mrkdwn',
32
32
  text: `*${test}*
33
- \n${formattedFailure}`,
34
- },
35
- });
36
- if (i > maxNumberOfFailures) {
37
- fails.push({
38
- type: 'section',
39
- text: {
40
- type: 'mrkdwn',
41
- text: `*There are too many failures to display - ${fails.length} out of ${summaryResults.failures.length} failures shown*`,
42
- },
43
- });
44
- break;
45
- }
46
- }
47
- if (summaryResults.meta) {
48
- for (let i = 0; i < summaryResults.meta.length; i += 1) {
49
- const { key, value } = summaryResults.meta[i];
50
- meta.push({
51
- type: 'section',
52
- text: {
53
- type: 'mrkdwn',
54
- text: `\n*${key}* :\t${value}`,
55
- },
56
- });
57
- }
58
- }
59
- return [
60
- header,
61
- summary,
62
- ...meta,
63
- {
64
- type: 'divider',
65
- },
66
- ...fails,
67
- ];
68
- };
69
- exports.default = generateBlocks;
33
+ \n${formattedFailure}`,
34
+ },
35
+ });
36
+ if (i > maxNumberOfFailures) {
37
+ fails.push({
38
+ type: 'section',
39
+ text: {
40
+ type: 'mrkdwn',
41
+ text: `*There are too many failures to display - ${fails.length} out of ${summaryResults.failures.length} failures shown*`,
42
+ },
43
+ });
44
+ break;
45
+ }
46
+ }
47
+ if (summaryResults.meta) {
48
+ for (let i = 0; i < summaryResults.meta.length; i += 1) {
49
+ const { key, value } = summaryResults.meta[i];
50
+ meta.push({
51
+ type: 'section',
52
+ text: {
53
+ type: 'mrkdwn',
54
+ text: `\n*${key}* :\t${value}`,
55
+ },
56
+ });
57
+ }
58
+ }
59
+ return [
60
+ header,
61
+ summary,
62
+ ...meta,
63
+ {
64
+ type: 'divider',
65
+ },
66
+ ...fails,
67
+ ];
68
+ };
69
+ exports.default = generateBlocks;
@@ -1,46 +1,50 @@
1
- /// <reference types="node" />
2
- import { failure, SummaryResults } from '.';
3
- export declare type testResult = {
4
- suiteName: string;
5
- name: string;
6
- browser?: string;
7
- projectName: string;
8
- endedAt: string;
9
- reason: string;
10
- retry: number;
11
- retries: number;
12
- startedAt: string;
13
- status: 'passed' | 'failed' | 'timedOut' | 'skipped';
14
- attachments?: {
15
- body: string | undefined | Buffer;
16
- contentType: string;
17
- name: string;
18
- path: string;
19
- }[];
20
- };
21
- export declare type testSuite = {
22
- testSuite: {
23
- title: string;
24
- tests: testResult[];
25
- testRunId?: number;
26
- };
27
- };
28
- export default class ResultsParser {
29
- private result;
30
- constructor();
31
- getParsedResults(): Promise<SummaryResults>;
32
- getFailures(): Promise<Array<failure>>;
33
- static getTestName(failedTest: any): any;
34
- updateResults(data: {
35
- testSuite: any;
36
- }): void;
37
- addTestResult(suiteName: any, testCase: any): void;
38
- safelyDetermineFailure(result: {
39
- errors: any[];
40
- error: {
41
- message: string;
42
- stack: string;
43
- };
44
- }): string;
45
- cleanseReason(rawReaseon: string): string;
46
- }
1
+ /// <reference types="node" />
2
+ import { failure, SummaryResults } from '.';
3
+ export declare type testResult = {
4
+ suiteName: string;
5
+ name: string;
6
+ browser?: string;
7
+ projectName: string;
8
+ endedAt: string;
9
+ reason: string;
10
+ retry: number;
11
+ retries: number;
12
+ startedAt: string;
13
+ status: 'passed' | 'failed' | 'timedOut' | 'skipped';
14
+ attachments?: {
15
+ body: string | undefined | Buffer;
16
+ contentType: string;
17
+ name: string;
18
+ path: string;
19
+ }[];
20
+ };
21
+ export declare type testSuite = {
22
+ testSuite: {
23
+ title: string;
24
+ tests: testResult[];
25
+ testRunId?: number;
26
+ };
27
+ };
28
+ export default class ResultsParser {
29
+ private result;
30
+ constructor();
31
+ getParsedResults(): Promise<SummaryResults>;
32
+ getFailures(): Promise<Array<failure>>;
33
+ static getTestName(failedTest: any): any;
34
+ updateResults(data: {
35
+ testSuite: any;
36
+ }): void;
37
+ addTestResult(suiteName: any, testCase: any): void;
38
+ safelyDetermineFailure(result: {
39
+ errors: any[];
40
+ error: {
41
+ message: string;
42
+ stack: string;
43
+ };
44
+ }): string;
45
+ cleanseReason(rawReaseon: string): string;
46
+ getParentConfigInformation(testCase: any): {
47
+ projectName: string;
48
+ browser: string;
49
+ };
50
+ }
@@ -1,118 +1,125 @@
1
- "use strict";
2
- /* eslint-disable no-shadow */
3
- /* eslint-disable no-underscore-dangle */
4
- /* eslint-disable import/extensions */
5
- /* eslint-disable no-control-regex */
6
- /* eslint-disable class-methods-use-this */
7
- /* eslint-disable no-param-reassign */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- class ResultsParser {
10
- result;
11
- constructor() {
12
- this.result = [];
13
- }
14
- async getParsedResults() {
15
- const failures = await this.getFailures();
16
- const summary = {
17
- passed: 0,
18
- failed: failures.length,
19
- skipped: 0,
20
- failures,
21
- tests: [],
22
- };
23
- for (const suite of this.result) {
24
- summary.tests = summary.tests.concat(suite.testSuite.tests);
25
- for (const test of suite.testSuite.tests) {
26
- if (test.status === 'passed') {
27
- summary.passed += 1;
28
- }
29
- else if (test.status === 'skipped') {
30
- summary.skipped += 1;
31
- }
32
- }
33
- }
34
- return summary;
35
- }
36
- async getFailures() {
37
- const failures = [];
38
- for (const suite of this.result) {
39
- for (const test of suite.testSuite.tests) {
40
- if (test.status === 'failed' || test.status === 'timedOut') {
41
- // only flag as failed if the last attempt has failed
42
- if (test.retries === test.retry) {
43
- failures.push({
44
- test: ResultsParser.getTestName(test),
45
- failureReason: test.reason,
46
- });
47
- }
48
- }
49
- }
50
- }
51
- return failures;
52
- }
53
- static 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
- }
63
- updateResults(data) {
64
- if (data.testSuite.tests.length > 0) {
65
- this.result.push(data);
66
- }
67
- }
68
- addTestResult(suiteName, testCase) {
69
- const testResults = [];
70
- for (const result of testCase.results) {
71
- testResults.push({
72
- suiteName,
73
- name: testCase.title,
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
- : '',
83
- retry: result.retry,
84
- retries: testCase.retries,
85
- startedAt: new Date(result.startTime).toISOString(),
86
- endedAt: new Date(new Date(result.startTime).getTime() + result.duration).toISOString(),
87
- reason: this.safelyDetermineFailure(result),
88
- attachments: result.attachments,
89
- });
90
- }
91
- this.updateResults({
92
- testSuite: {
93
- title: suiteName,
94
- tests: testResults,
95
- },
96
- });
97
- }
98
- safelyDetermineFailure(result) {
99
- if (result.errors.length > 0) {
100
- const fullError = result.errors
101
- .map((e) => `${e.message}\r\n${e.stack ? e.stack : ''}\r\n`)
102
- .join();
103
- return this.cleanseReason(fullError);
104
- }
105
- return `${this.cleanseReason(result.error?.message)} \n ${this.cleanseReason(result.error?.stack)}`;
106
- }
107
- cleanseReason(rawReaseon) {
108
- // eslint-disable-next-line prefer-regex-literals
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');
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;
116
- }
117
- }
118
- exports.default = ResultsParser;
1
+ "use strict";
2
+ /* eslint-disable no-shadow */
3
+ /* eslint-disable no-underscore-dangle */
4
+ /* eslint-disable import/extensions */
5
+ /* eslint-disable no-control-regex */
6
+ /* eslint-disable class-methods-use-this */
7
+ /* eslint-disable no-param-reassign */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ class ResultsParser {
10
+ result;
11
+ constructor() {
12
+ this.result = [];
13
+ }
14
+ async getParsedResults() {
15
+ const failures = await this.getFailures();
16
+ const summary = {
17
+ passed: 0,
18
+ failed: failures.length,
19
+ skipped: 0,
20
+ failures,
21
+ tests: [],
22
+ };
23
+ for (const suite of this.result) {
24
+ summary.tests = summary.tests.concat(suite.testSuite.tests);
25
+ for (const test of suite.testSuite.tests) {
26
+ if (test.status === 'passed') {
27
+ summary.passed += 1;
28
+ }
29
+ else if (test.status === 'skipped') {
30
+ summary.skipped += 1;
31
+ }
32
+ }
33
+ }
34
+ return summary;
35
+ }
36
+ async getFailures() {
37
+ const failures = [];
38
+ for (const suite of this.result) {
39
+ for (const test of suite.testSuite.tests) {
40
+ if (test.status === 'failed' || test.status === 'timedOut') {
41
+ // only flag as failed if the last attempt has failed
42
+ if (test.retries === test.retry) {
43
+ failures.push({
44
+ test: ResultsParser.getTestName(test),
45
+ failureReason: test.reason,
46
+ });
47
+ }
48
+ }
49
+ }
50
+ }
51
+ return failures;
52
+ }
53
+ static 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
+ }
63
+ updateResults(data) {
64
+ if (data.testSuite.tests.length > 0) {
65
+ this.result.push(data);
66
+ }
67
+ }
68
+ addTestResult(suiteName, testCase) {
69
+ const testResults = [];
70
+ const projectSettings = this.getParentConfigInformation(testCase);
71
+ for (const result of testCase.results) {
72
+ testResults.push({
73
+ suiteName,
74
+ name: testCase.title,
75
+ status: result.status,
76
+ browser: projectSettings.browser,
77
+ projectName: projectSettings.projectName,
78
+ retry: result.retry,
79
+ retries: testCase.retries,
80
+ startedAt: new Date(result.startTime).toISOString(),
81
+ endedAt: new Date(new Date(result.startTime).getTime() + result.duration).toISOString(),
82
+ reason: this.safelyDetermineFailure(result),
83
+ attachments: result.attachments,
84
+ });
85
+ }
86
+ this.updateResults({
87
+ testSuite: {
88
+ title: suiteName,
89
+ tests: testResults,
90
+ },
91
+ });
92
+ }
93
+ safelyDetermineFailure(result) {
94
+ if (result.errors.length > 0) {
95
+ const fullError = result.errors
96
+ .map((e) => `${e.message}\r\n${e.stack ? e.stack : ''}\r\n`)
97
+ .join();
98
+ return this.cleanseReason(fullError);
99
+ }
100
+ return `${this.cleanseReason(result.error?.message)} \n ${this.cleanseReason(result.error?.stack)}`;
101
+ }
102
+ cleanseReason(rawReaseon) {
103
+ // eslint-disable-next-line prefer-regex-literals
104
+ 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');
105
+ const ansiCleansed = rawReaseon ? rawReaseon.replace(ansiRegex, '') : '';
106
+ const logsStripped = ansiCleansed
107
+ .replace(/============================================================\n/g, '')
108
+ .replace(/============================================================\r\n/g, '')
109
+ .replace(/=========================== logs ===========================\n/g, '');
110
+ return logsStripped;
111
+ }
112
+ getParentConfigInformation(testCase) {
113
+ if (testCase._projectConfig !== undefined) {
114
+ return {
115
+ projectName: testCase._projectConfig.name || '',
116
+ browser: testCase._projectConfig.use?.defaultBrowserType || '',
117
+ };
118
+ }
119
+ if (testCase.parent) {
120
+ return this.getParentConfigInformation(testCase.parent);
121
+ }
122
+ return { projectName: '', browser: '' };
123
+ }
124
+ }
125
+ exports.default = ResultsParser;
@@ -1,26 +1,26 @@
1
- import { WebClient, KnownBlock, Block, ChatPostMessageResponse, LogLevel } from '@slack/web-api';
2
- import { SummaryResults } from '.';
3
- export declare type additionalInfo = Array<{
4
- key: string;
5
- value: string;
6
- }>;
7
- export default class SlackClient {
8
- private slackWebClient;
9
- constructor(slackClient: WebClient);
10
- sendMessage({ options, }: {
11
- options: {
12
- channelIds: Array<string>;
13
- customLayout: Function | undefined;
14
- customLayoutAsync: Function | undefined;
15
- fakeRequest?: Function;
16
- maxNumberOfFailures: number;
17
- slackOAuthToken?: string;
18
- slackLogLevel?: LogLevel;
19
- summaryResults: SummaryResults;
20
- };
21
- }): Promise<Array<{
22
- channel: string;
23
- outcome: string;
24
- }>>;
25
- doPostRequest(channel: string, blocks: Array<KnownBlock | Block>): Promise<ChatPostMessageResponse>;
26
- }
1
+ import { WebClient, KnownBlock, Block, ChatPostMessageResponse, LogLevel } from '@slack/web-api';
2
+ import { SummaryResults } from '.';
3
+ export declare type additionalInfo = Array<{
4
+ key: string;
5
+ value: string;
6
+ }>;
7
+ export default class SlackClient {
8
+ private slackWebClient;
9
+ constructor(slackClient: WebClient);
10
+ sendMessage({ options, }: {
11
+ options: {
12
+ channelIds: Array<string>;
13
+ customLayout: Function | undefined;
14
+ customLayoutAsync: Function | undefined;
15
+ fakeRequest?: Function;
16
+ maxNumberOfFailures: number;
17
+ slackOAuthToken?: string;
18
+ slackLogLevel?: LogLevel;
19
+ summaryResults: SummaryResults;
20
+ };
21
+ }): Promise<Array<{
22
+ channel: string;
23
+ outcome: string;
24
+ }>>;
25
+ doPostRequest(channel: string, blocks: Array<KnownBlock | Block>): Promise<ChatPostMessageResponse>;
26
+ }