You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

@storybook/addon-coverage

Package Overview
Dependencies
Maintainers
31
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@storybook/addon-coverage

Tools to support code coverage in Storybook

0.0.9
Source
npm
Version published
Weekly downloads
211K
-2.25%
Maintainers
31
Weekly downloads
 
Created
Source

Storybook Addon Coverage

Tools to support code coverage in Storybook and the Storybook test runner. It supports Storybook projects that use Babel or Vite.

Installation

Install this addon by adding the @storybook/addon-coverage dependency:

yarn add -D @storybook/addon-coverage

And by registering it in your .storybook/main.js:

module.exports = {
  addons: ["@storybook/addon-coverage"],
};

Configuring the addon

This addon instruments your code by using babel-plugin-istanbul if your project uses Babel or vite-plugin-istanbul if your project uses Vite. It provides some default configuration, but if you want to add yours, you can do so by setting the options in your .storybook/main.js:

module.exports = {
  addons: [
    {
      name: "@storybook/addon-coverage",
      options: {
        istanbul: {
          include: ["**/stories/**"],
        },
      },
    },
  ],
};

The available options if your project uses Babel are as follows:

Option nameDescriptionTypeDefault
cwdSet the working directoryStringprocess.cwd()
includeSee here for more infoArray<String>['**']
excludeSee here for more infoArray<String>list
extensionList of extensions that nyc should attempt to handle in addition to .jsArray<String>['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx', '.vue', '.svelte]
excludeNodeModulesWhether or not to exclude all node_module folders (i.e. /node_modules/) by defaultbooleantrue
ignoreClassMethodsClass method names to ignore for coverage`Array<String>[]
useInlineSourceMapsVariable to pass sourcemap explicitlyobject-
inputSourceMapScope to store the coverage variablestring-
nycrcPathPath to nyc config filestring-
onCoverHook used to track coverage for all files(fileName: string, fileCoverage: FileCoverage) => unknown-
fileNameFile name to use in onCover hookstring-

Note: If you're using typescript, you can import the type for the options like so:

import type { AddonOptionsBabel } from '@storybook/addon-coverage'

The available options if your project uses Vite are as follows:

Option nameDescriptionTypeDefault
cwdSet the working directoryStringprocess.cwd()
includeSee here for more infoArray<String> or string['**']
excludeSee here for more infoArray<String> or stringlist
extensionList of extensions that nyc should attempt to handle in addition to .jsArray<String> or string['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx', '.vue', '.svelte]
requireEnv Optional boolean to require the environment variable (defaults to VITE_COVERAGE) to equal true in order to instrument the code. Otherwise it will instrument even if env variable is not set. However if requireEnv is not set the instrumentation will stop if the environment variable is equal to false.boolean-
cypress Optional boolean to change the environment variable to CYPRESS_COVERAGE instead of VITE_COVERAGE. For ease of use with @cypress/code-coverage coverageboolean-
checkProd Optional boolean to enforce the plugin to skip instrumentation for production environments. Looks at Vite's isProduction key from the ResolvedConfig.boolean-
forceBuildInstrument Optional boolean to enforce the plugin to add instrumentation in build mode.booleanfalse
nycrcPath Path to specific nyc config to use instead of automatically searching for a nycconfig. This parameter is just passed down to @istanbuljs/load-nyc-config.string-

Note: If you're using typescript, you can import the type for the options like so:

import type { AddonOptionsVite } from '@storybook/addon-coverage'

Development scripts

  • yarn start runs babel in watch mode
  • yarn build build and package your addon code

To run the examples, choose one of the projects in the examples directory then run:

  • yarn to install dependencies and link the addon locally
  • yarn storybook to run Storybook
  • yarn test-storybook --coverage to test coverage report generation

License

MIT

Keywords

storybook-addons

FAQs

Package last updated on 20 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts