npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cypress-send-to-teams

v1.0.1

Published

A module to send cypress test results to a MS Teams webhook using Adaptive Cards.

Downloads

10

Readme

cypress-send-to-teams

A module to send Cypress test results to a Microsoft Teams webhook using Adaptive Cards.

Installation

You can install this module using npm:

npm install cypress-send-to-teams

Usage

Basic Usage

Import the module and call it with the required parameters:

const sendToTeams = require("cypress-send-to-teams");

// Example usage
sendToTeams(
  "https://your-webhook-url",
  "Test Results",
  [
    {
      title: ["Test 1", "Sub-test 1"],
      state: "failed",
      displayError: "An error occurred",
    },
    // More test results...
  ],
  {
    name: "test-file.js",
  }
);

Parameters

  • webhookUrl (string): The Microsoft Teams webhook URL.
  • title (string): The title of the message to be sent.
  • tests (Array): An array of test result objects. Each object should have:
    • title (Array): An array with two strings, the main title and sub-title.
    • state (string): The state of the test ('passed' or 'failed').
    • displayError (string): The error message if the test failed.
  • spec (object): An object representing the test file spec. It should have a name property.
  • isOnlySendingBugs (boolean, optional): Whether to send only failed tests. Default is true.
  • testItemTemplateHandler (function, optional): A function to customize the test item format. It defaults to defaultCreateTestItem.

Example

// cypress.config.ts

const { defineConfig } = require("cypress");
const sendToTeams = require('cypress-send-to-teams');

// Custom test item handler
const customTestItemHandler = (test, spec) => ({
  type: "Container",
  spacing: "Medium",
  items: [
    {
      type: "TextBlock",
      text: `Test: ${test.title[0]}`,
      wrap: true,
      size: "Medium",
      weight: "Bolder",
    },
    {
      type: "TextBlock",
      text: `File: ${spec.name}`,
      wrap: true,
      size: "Medium",
      weight: "Lighter",
    },
    {
      type: "TextBlock",
      text: `Status: ${test.state.toUpperCase()}`,
      wrap: true,
      size: "Medium",
      color: "Attention",
      weight: "Lighter",
    },
    {
      type: "TextBlock",
      text: test.displayError,
      wrap: true,
      size: "Medium",
      color: "Attention",
      weight: "Lighter",
    },
  ],
});

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      on("after:spec", async (spec, results) => {
        if (
          results &&
          results.stats &&
          results.stats.failures > 0
        ) {
          console.log("spec", spec);
          await sendToTeams(
              'https://your-webhook-url',
              'Custom Test Results',
              [
                {
                  title: ['Custom Test 1', 'Sub-test 1'],
                  state: 'failed',
                  displayError: 'Custom error message'
                },
                // More test results...
              ],
              {
                name: 'custom-test-file.js'
              },
              true, // only send bugs
              customTestItemHandler // custom handler
            );
            .then((response) => {
              console.log("Adaptive Card posted to Teams:", response.data);
            })
            .catch((error) => {
              console.error("Error posting Adaptive Card to Teams:", error);
            });
        }
      });
    },
  },
});

Dependencies

License

ISC License. See the LICENSE file for more details.

Author

John Patrick Valera


Feel free to adjust any part to better suit your needs or preferences!