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

vitest-github-action

v1.3.16

Published

GitHub actions error and coverage reporter for vitest.

Downloads

1,083

Readme

Issues

Table of Contents

About The Project

GitHub actions error and coverage reporter for vitest.

Built With

Getting Started

To get a local copy up and running follow these simple steps.

Prerequisites

  • npm
npm install npm@latest -g

Installation

  1. Clone the Repo
git clone https://github.com/roerohan/vitest-github-action.git
  1. Install NPM packages
npm install

Usage

You can use vitest-github-action to report vitest errors (in the "Files" section of a Pull Request), and report the coverage of tests (as comments on a Pull Request).

This repository provides 2 ways of performing the above actions: 

  • A GitHub action that you can use directly from the marketplace to enable error and coverage reporting.
  • A npm module that exports the relevant classes so that you can use them in your vitest configuration. 

Github Action

You can directly use the GitHub action and pass configuration options to report errors and coverage on GitHub. The following sample action demonstrates how that can be done.

name: "Run vitest tests"
on:
  pull_request:
    branches:
      - main

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - uses: actions/setup-node@v3
        with:
          node-version: 18

      - name: Run `npm install`
        run: |
          npm install
          npm run build

      - name: Run vitest and report issues
        uses: roerohan/vitest-github-action@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          config: ./vitest.config.ts
          coverage: true

NPM Package

The package exports 2 classes:

  1. GithubReporter to report errors in the files section of a PR, and
  2. GithubIstanbulCoverageProviderModule to comment coverage reports on the PR.

You can use the GithubReporter exported by this package in your vite.config.ts or vitest.config.ts (or their JS equivalent) files to have your errors reported on your GitHub pull request.

import { defineConfig } from "vitest/config";
import { GithubReporter } from "vitest-github-action";

export default defineConfig({
  test: {
    reporters: process.env.GITHUB_ACTIONS
      ? ["default", new GithubReporter()]
      : "default",
  },
});

The GithubIstanbulCoverageProviderModule is a wrapper over the istanbul coverage provider that reports the coverage as a PR comment alongside the default reporting methods such as text, json, json-summary, etc.

To use the GithubIstanbulCoverageProviderModule, first, you need to create a file called vitest-github-coverage-provider.ts which has the following lines:

import { GithubIstanbulCoverageProviderModule } from "vitest-github-action";

export default GithubIstanbulCoverageProviderModule;

The customProviderModule configuration of vitest requires the coverage provider module to be a default export. This is why we are re-exporting it from a file as a default export. Additionally, it's easier to write the path to this file rather than the entire path from node_modules.

Then, you need to update your vitest configuration to the following.

import { defineConfig } from "vitest/config";
import { GithubReporter } from "vitest-github-action";

export default defineConfig({
  test: {
    coverage: {
      provider: "custom",
      customProviderModule: "vitest-github-coverage-provider",
      // @ts-expect-error github-summary is a custom reporter and is not recognized.
      reporter: ["github-summary"],
    },
  },
});

Upon adding this configuration, the coverage report will be generated and commented on the PR. To run this, just run npm run coverage in your action.

NOTE: Make sure that the GITHUB_TOKEN is set to ${{ secrets.GITHUB_TOKEN }} in the action where you run npm run coverage.

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'feat: Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

You are requested to follow the contribution guidelines specified in CONTRIBUTING.md while contributing to the project :smile:.

License

Distributed under the MIT License. See LICENSE for more information.