playwright-slack-report 1.1.23 → 1.1.25

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.
@@ -2,4 +2,5 @@ import { KnownBlock, Block } from '@slack/types';
2
2
  import { SummaryResults } from '.';
3
3
  declare const generateBlocks: (summaryResults: SummaryResults, maxNumberOfFailures: number) => Promise<Array<KnownBlock | Block>>;
4
4
  declare const generateFailures: (summaryResults: SummaryResults, maxNumberOfFailures: number) => Promise<Array<KnownBlock | Block>>;
5
- export { generateBlocks, generateFailures };
5
+ declare const generateFallbackText: (summaryResults: SummaryResults) => string;
6
+ export { generateBlocks, generateFailures, generateFallbackText };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateFailures = exports.generateBlocks = void 0;
3
+ exports.generateFallbackText = exports.generateFailures = exports.generateBlocks = void 0;
4
4
  const generateBlocks = async (summaryResults, maxNumberOfFailures) => {
5
5
  const meta = [];
6
6
  const header = {
@@ -14,7 +14,9 @@ const generateBlocks = async (summaryResults, maxNumberOfFailures) => {
14
14
  type: 'section',
15
15
  text: {
16
16
  type: 'mrkdwn',
17
- text: `✅ *${summaryResults.passed}* | ❌ *${summaryResults.failed}* | ⏩ *${summaryResults.skipped}*`,
17
+ text: `✅ *${summaryResults.passed}* | ❌ *${summaryResults.failed}* |${summaryResults.flaky !== undefined
18
+ ? ` 🟡 *${summaryResults.flaky}* | `
19
+ : ' '}⏩ *${summaryResults.skipped}*`,
18
20
  },
19
21
  };
20
22
  const fails = await generateFailures(summaryResults, maxNumberOfFailures);
@@ -30,12 +32,7 @@ const generateBlocks = async (summaryResults, maxNumberOfFailures) => {
30
32
  });
31
33
  }
32
34
  }
33
- return [
34
- header,
35
- summary,
36
- ...meta,
37
- ...fails,
38
- ];
35
+ return [header, summary, ...meta, ...fails];
39
36
  };
40
37
  exports.generateBlocks = generateBlocks;
41
38
  const generateFailures = async (summaryResults, maxNumberOfFailures) => {
@@ -75,3 +72,5 @@ const generateFailures = async (summaryResults, maxNumberOfFailures) => {
75
72
  ];
76
73
  };
77
74
  exports.generateFailures = generateFailures;
75
+ const generateFallbackText = (summaryResults) => `✅ ${summaryResults.passed} ❌ ${summaryResults.failed} ${summaryResults.flaky !== undefined ? ` 🟡 ${summaryResults.flaky} ` : ' '}⏩ ${summaryResults.skipped}`;
76
+ exports.generateFallbackText = generateFallbackText;
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ import { TestCase } from '@playwright/test/reporter';
2
3
  import { failure, SummaryResults } from '.';
3
4
  export declare type testResult = {
4
5
  suiteName: string;
@@ -28,7 +29,7 @@ export declare type testSuite = {
28
29
  export default class ResultsParser {
29
30
  private result;
30
31
  constructor();
31
- getParsedResults(): Promise<SummaryResults>;
32
+ getParsedResults(allTests: Array<TestCase>): Promise<SummaryResults>;
32
33
  getFailures(): Promise<Array<failure>>;
33
34
  static getTestName(failedTest: any): any;
34
35
  updateResults(data: {
@@ -11,25 +11,26 @@ class ResultsParser {
11
11
  constructor() {
12
12
  this.result = [];
13
13
  }
14
- async getParsedResults() {
14
+ async getParsedResults(allTests) {
15
15
  const failures = await this.getFailures();
16
+ // use Playwright recommended way of extracting test stats:
17
+ // https://github.com/microsoft/playwright/issues/27498#issuecomment-1766766335
18
+ const stats = {
19
+ expected: 0, skipped: 0, unexpected: 0, flaky: 0,
20
+ };
21
+ // eslint-disable-next-line no-plusplus
22
+ for (const test of allTests)
23
+ ++stats[test.outcome()];
16
24
  const summary = {
17
- passed: 0,
18
- failed: failures.length,
19
- skipped: 0,
25
+ passed: stats.expected,
26
+ failed: stats.unexpected,
27
+ flaky: stats.flaky,
28
+ skipped: stats.skipped,
20
29
  failures,
21
30
  tests: [],
22
31
  };
23
32
  for (const suite of this.result) {
24
33
  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
  }
34
35
  return summary;
35
36
  }
@@ -33,5 +33,5 @@ export default class SlackClient {
33
33
  disableUnfurl?: boolean;
34
34
  fakeRequest?: Function;
35
35
  }): Promise<any[]>;
36
- static doPostRequest(slackWebClient: WebClient, channel: string, blocks: Array<KnownBlock | Block>, unfurl: boolean, threadTimestamp?: string): Promise<ChatPostMessageResponse>;
36
+ static doPostRequest(slackWebClient: WebClient, channel: string, fallbackText: string, blocks: Array<KnownBlock | Block>, unfurl: boolean, threadTimestamp?: string): Promise<ChatPostMessageResponse>;
37
37
  }
@@ -25,6 +25,7 @@ class SlackClient {
25
25
  if (!options.channelIds) {
26
26
  throw new Error(`Channel ids [${options.channelIds}] is not valid`);
27
27
  }
28
+ const fallbackText = (0, LayoutGenerator_1.generateFallbackText)(options.summaryResults);
28
29
  const result = [];
29
30
  const unfurl = !options.disableUnfurl;
30
31
  for (const channel of options.channelIds) {
@@ -36,7 +37,7 @@ class SlackClient {
36
37
  }
37
38
  else {
38
39
  // send request for reals
39
- chatResponse = await SlackClient.doPostRequest(this.slackWebClient, channel, blocks, unfurl);
40
+ chatResponse = await SlackClient.doPostRequest(this.slackWebClient, channel, fallbackText, blocks, unfurl);
40
41
  }
41
42
  if (chatResponse.ok) {
42
43
  result.push({
@@ -66,6 +67,7 @@ class SlackClient {
66
67
  async attachDetailsToThread({ channelIds, ts, summaryResults, maxNumberOfFailures, disableUnfurl, fakeRequest, }) {
67
68
  const result = [];
68
69
  const blocks = await (0, LayoutGenerator_1.generateFailures)(summaryResults, maxNumberOfFailures);
70
+ const fallbackText = (0, LayoutGenerator_1.generateFallbackText)(summaryResults);
69
71
  for (const channel of channelIds) {
70
72
  // under test
71
73
  let chatResponse;
@@ -73,7 +75,7 @@ class SlackClient {
73
75
  chatResponse = await fakeRequest();
74
76
  }
75
77
  else {
76
- chatResponse = await SlackClient.doPostRequest(this.slackWebClient, channel, blocks, disableUnfurl, ts);
78
+ chatResponse = await SlackClient.doPostRequest(this.slackWebClient, channel, fallbackText, blocks, disableUnfurl, ts);
77
79
  }
78
80
  if (chatResponse.ok) {
79
81
  // eslint-disable-next-line no-console
@@ -87,10 +89,10 @@ class SlackClient {
87
89
  }
88
90
  return result;
89
91
  }
90
- static async doPostRequest(slackWebClient, channel, blocks, unfurl, threadTimestamp) {
92
+ static async doPostRequest(slackWebClient, channel, fallbackText, blocks, unfurl, threadTimestamp) {
91
93
  const chatResponse = await slackWebClient.chat.postMessage({
92
94
  channel,
93
- text: ' ',
95
+ text: fallbackText,
94
96
  unfurl_link: unfurl,
95
97
  blocks,
96
98
  thread_ts: threadTimestamp,
@@ -66,7 +66,7 @@ class SlackReporter {
66
66
  this.log(message);
67
67
  return;
68
68
  }
69
- const resultSummary = await this.resultsParser.getParsedResults();
69
+ const resultSummary = await this.resultsParser.getParsedResults(this.suite.allTests());
70
70
  resultSummary.meta = this.meta;
71
71
  const maxRetry = Math.max(...resultSummary.tests.map((o) => o.retry));
72
72
  if (this.sendResults === 'on-failure'
@@ -2,6 +2,7 @@
2
2
  export declare type SummaryResults = {
3
3
  passed: number;
4
4
  failed: number;
5
+ flaky: number | undefined;
5
6
  skipped: number;
6
7
  failures: Array<failure>;
7
8
  meta?: Array<{
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "dependencies": {
3
- "@slack/web-api": "^6.8.1",
4
- "@slack/webhook": "^6.1.0",
3
+ "@slack/web-api": "^6.9.1",
4
+ "@slack/webhook": "^7.0.1",
5
5
  "https-proxy-agent": "^7.0.1"
6
6
  },
7
7
  "devDependencies": {
@@ -26,10 +26,11 @@
26
26
  "prettier": "prettier --write --loglevel warn \"**/**/*.ts\"",
27
27
  "pw": "nyc playwright test && nyc report --reporter=lcov",
28
28
  "build": "tsc -p ./tsconfig.json",
29
- "lint": "npx eslint . --ext .ts"
29
+ "lint": "npx eslint . --ext .ts",
30
+ "lint-fix": "npx eslint . --ext .ts --fix"
30
31
  },
31
32
  "name": "playwright-slack-report",
32
- "version": "1.1.23",
33
+ "version": "1.1.25",
33
34
  "main": "index.js",
34
35
  "types": "dist/index.d.ts",
35
36
  "repository": "git@github.com:ryanrosello-og/playwright-slack-report.git",
@@ -43,5 +44,14 @@
43
44
  "report",
44
45
  "playwright",
45
46
  "typescript"
46
- ]
47
+ ],
48
+ "nyc": {
49
+ "all": true,
50
+ "include": [
51
+ "src/**/*.ts"
52
+ ],
53
+ "exclude": [
54
+ "./src/custom_block/my_block.ts"
55
+ ]
56
+ }
47
57
  }