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

jest-package-audit

v5.0.4

Published

Filter and retry yarn/npm audit command with Jest.

Downloads

414

Readme

jest-package-audit

Filter and retry yarn/npm audit command with Jest.

ci status npm package license MIT auto tested with jest

The yarn audit, and npm audit commands are useful for detecting packages in use that have vulnerabilites. But they don't allow specific package filtering. For example you may have a vulnerability in a package you are only using in development, and the nature of that vulnerability is more often than not only unsafe when used in production. Updating the dependency to fix the vulnerability may break things. That is where jest-package-audit comes in, it wraps the yarn audit and npm audit commands and checks each vulnerabilty they flag against an array of allowed vulnerability names e.g. ['puppeteer'].

Another added benefit of jest-package-audit is the ability to retry tests if they fail. This is useful as the audit endpoints can sometimes timeout out or randomly give 503 HTTP Status codes back. Using jest.retryTimes you can overcome this by retrying say 5 times.

Usage

Important: jest-package-audit only works with Jest >= 23 as it depends on async matchers.

  1. Install jest-package-audit:
yarn add jest-package-audit --dev
# or
npm install jest-package-audit --save-dev
  1. Create a new test file for package auditing:
// audit.test.js
import { toPassPackageAudit } from 'jest-package-audit';
expect.extend({ toPassPackageAudit });

jest.retryTimes(5); // Optional
jest.setTimeout(15000); // The audit command can take a while...

test('packages do not have vunerabilities', async () => {
  await expect({/* Input options */}).toPassPackageAudit({ allow: ['puppeteer'] /* Output options */ });
});

test('packages do not have vunerabilities using predicate function', async () => {
  await expect({/* Input options */}).toPassPackageAudit({ allow: (options) => {
    if (options.packageName === 'puppeteer' && options.packageSeverity === 'low') {
      return true;
    } else {
      return false;
    }
  } /* Output options */ });
});

Options

Input Options

Input options should be passed to the expect function when using toPassPackageAudit, they define how the actual yarn audit or npm audit command is run.

Name | Description | Default --- | --- | --- cwd: (String) | Current working directory to run the audit command in. | The closest folder with a package.json above jest-package-audit. packageManager ('npm' or 'yarn' or 'pnpm') | Which package manager to use, this will be auto-detected if not specified, also it will determine how the audit output is parsed when using command. | Based on relevant lockfile existance level: ('info' or 'low' or 'moderate' or 'high' or 'critical') | Limit the vulnerabilities to the given level and above. (Note: npm and pnpm does not support info, so it will not be passed forward) | dependencyType: ('dependencies' or 'devDependencies') | Limit the vulnerabilities to the projects development or production dependencies. | command (String) | Custom command to use. This will override the yarn, level and dependencyType options. Use this with caution! |

Note: level and dependencyType are passed forward to yarn and npm in their respective formats. Unless, command is specified,

Output Options

Output options should be passed to the toPassPackageAudit function, they define how the output of yarn audit or npm audit is processed.

Name | Description | Default --- | --- | --- allow: (String[] | (vulnerability: {packageName: string; packageSeverity: string; packageData: Object}) => boolean) | An array of package names to allow if they have vulnerabilities or a single callback predicate function. | []

Disclaimer

Please be aware that we provide no liability for any security issues, or any other issues for that matter, encountered when using this package. It is provided as open-source software under the MIT license. So please read the source code and make sure you understand the implications of allowing vulnerable modules to pass through the audit commands!


LICENSE | CHANGELOG | ISSUES | CONTRIBUTING