ryanrosello-og / playwright-slack-report

Publish your Playwright test results to your favourite Slack channel(s).
MIT License
95 stars 28 forks source link

How do I merge flaky tests number with passed tests number? #100

Closed aakashgupt closed 7 months ago

aakashgupt commented 7 months ago

Hi,

I want to achieve the following with Slack notification:

  1. merge flaky tests number with passed tests number
  2. don't show skipped tests in result

Context: CleanShot 2024-02-29 at 20 11 10@2x

ryanrosello-og commented 7 months ago

hi @aakashgupt

You can use a custom layout to achieve this.

For example:

playwright.config.ts

import { defineConfig } from "@playwright/test";
import generateCustomLayout from "./custom_layout";

export default defineConfig({
  testDir: "./tests",
  reporter: [
    [
      "./node_modules/playwright-slack-report/dist/src/SlackReporter.js",
      {
        channels: ["pw"],
        sendResults: "always",
        layout: generateCustomLayout,
        slackLogLevel: "INFO",
        disableUnfurl: false,
        showInThread: false,
      },
    ],
  ],
});

Place this file in the root of your project ...

custom_layout.ts

import { Block, KnownBlock } from "@slack/types";

type SummaryResults = {
  passed: number;
  failed: number;
  flaky: number | undefined;
  skipped: number;
  failures: Array<{
    suite: string;
    test: string;
    failureReason: string;
  }>;
  meta?: Array<{ key: string; value: string }>;
  tests: Array<{
    suiteName: string;
    name: string;
    browser?: string;
    projectName?: string;
    endedAt: string;
    reason: string;
    retry: number;
    startedAt: string;
    status: "passed" | "failed" | "timedOut" | "skipped";
    attachments?: {
      body: string | undefined | Buffer;
      contentType: string;
      name: string;
      path: string;
    }[];
  }>;
};

export default function generateCustomLayout(
  summaryResults: SummaryResults
): Array<Block | KnownBlock> {
  return [
    {
      type: "section",
      text: {
        type: "mrkdwn",
        text: "🎭 *Playwright Results*",
      },
    },
    {
      type: "section",
      text: {
        type: "mrkdwn",
        text: `✅ *${
          summaryResults.flaky
            ? summaryResults.flaky + summaryResults.passed
            : summaryResults.passed
        }* | ❌ *${summaryResults.failed}* `,
      },
    },
  ];
}

This is the result:

2024-03-02_09-11-14
aakashgupt commented 7 months ago

I am closing this question, i haven't used your solution though. just stuck with some work