0.11.0 • Published 10 months ago

@storybook/test-runner v0.11.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Storybook Test Runner

Storybook test runner turns all of your stories into executable tests.

It's currently a prototype that configures Jest to run smoke tests on your stories in either:

  • JSDOM - render stories to JSDOM using TestingLibrary
  • Playwright - render stories in a browser using Playwright

The goal of this prototype is to help evaluate both approaches: primarily for performance, but also to understand the general strengths and weaknesses.

Install

The package has not yet been published so you'll have to link it for now.

In the test-runner package:

yarn && yarn build
yarn link

In your project directory:

yarn link @storybook/test-runner
yarn add jest babel-jest @testing-library/react @storybook/testing-react --dev

For JSDOM (React-only for now):

yarn add jest-environment-jsdom --dev

For Playwright:

yarn add jest-playwright-preset playwright --dev

This simply installs the package in node_modules. Using the package is fully manual at this point.

Configure

To use the addon, you need to manually configure it:

  • Create a script in package.json
  • Create a jest config for your use case

JSDOM

Add a script to package.json:

{
  "scripts": {
    "test-storybook:jsdom": "jest --config ./jsdom-jest.config.js"
  }
}

Then create a config file jsdom-jest.config.js that sets up your environment. For example:

module.exports = {
  cacheDirectory: '.cache/jest',
  testMatch: ['**/*.stories.[jt]s?(x)'],
  moduleNameMapper: {
    // non-js files
    '\\.(jpg|jpeg|png|apng|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
      '@storybook/test-runner/mocks/fileMock.js',
    '\\.(css|scss|stylesheet)$': '@storybook/test-runner/mocks/styleMock.js',
  },
  transform: {
    '^.+\\.stories\\.[jt]sx?$': '@storyboook/test-runner/jsdom/transform',
    '^.+\\.[jt]sx?$': 'babel-jest',
  },
  testEnvironment: 'jest-environment-jsdom',
};

Playwright

Add a script to package.json:

{
  "scripts": {
    "test-storybook:playwright": "jest --config ./playwright-jest.config.js"
  }
}

Then create a config file playwright-jest.config.js that sets up your environment. For example:

module.exports = {
  cacheDirectory: '.cache/jest',
  testMatch: ['**/*.stories.[jt]s?(x)'],
  moduleNameMapper: {
    // non-js files
    '\\.(jpg|jpeg|png|apng|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
      '@storybook/test-runner/mocks/fileMock.js',
    '\\.(css|scss|stylesheet)$': '@storybook/test-runner/mocks/styleMock.js',
  },
  transform: {
    '^.+\\.stories\\.[jt]sx?$': '@storybook/test-runner/playwright/transform',
    '^.+\\.[jt]sx?$': 'babel-jest',
  },
  preset: 'jest-playwright-preset',
  testEnvironment: '@storybook/test-runner/playwright/custom-environment.js',
};

NOTE: The code currently assumes that your Storybook is ALREADY running on process.env.STORYBOOK_PORT which defaults to 6006.

Running against a deployed Storybook

By default, the playwright assumes that you're running it against a locally served Storybook. If you want to define a target url so it runs against deployed Storybooks, you can do so by passing the TARGET_URL environment variable:

{
  "scripts": {
    "test-storybook:playwright": "TARGET_URL=the-storybook-url-here jest --config ./playwright-jest.config.js"
  }
}

Future work

In the future it will support the following features:

  • 💨 Smoke test all stories
  • ▶️ Test CSF3 play functions
  • 🧪 Custom test functions
  • 📄 Run addon reports
  • ⚡️ Zero config setup
0.11.0-next.1

10 months ago

0.11.0

10 months ago

0.11.0-future.4

10 months ago

0.11.0-future.5

10 months ago

0.11.0-future.2

11 months ago

0.11.0-future.3

11 months ago

0.10.0-next.11

1 year ago

0.10.0-next.10

1 year ago

0.10.0-next.13

1 year ago

0.10.0-next.12

1 year ago

0.10.0

1 year ago

0.11.0-next.0

1 year ago

0.10.0-next.9

1 year ago

0.11.0-future.0

1 year ago

0.11.0-future.1

1 year ago

0.9.4

1 year ago

0.10.0-next.7

1 year ago

0.10.0-next.8

1 year ago

0.10.0-next.6

1 year ago

0.9.3

1 year ago

0.7.3-canary.0

1 year ago

0.10.0-next.5

1 year ago

0.10.0-next.3

1 year ago

0.10.0-next.4

1 year ago

0.9.2

1 year ago

0.9.0-next.0

2 years ago

0.8.0

2 years ago

0.8.0-next.0

2 years ago

0.8.0-next.1

2 years ago

0.10.0-next.1

2 years ago

0.10.0-next.2

1 year ago

0.10.0-next.0

2 years ago

0.9.1-next.0

2 years ago

0.8.1-next.0

2 years ago

0.8.1-next.1

2 years ago

0.9.0

2 years ago

0.9.1

1 year ago

0.7.1-next.0

2 years ago

0.7.2

2 years ago

0.7.1

2 years ago

0.7.0

2 years ago

0.6.4-next.0

2 years ago

0.6.3

2 years ago

0.6.2

2 years ago

0.6.2-next.0

2 years ago

0.6.4

2 years ago

0.7.2-next.0

2 years ago

0.6.3-next.0

2 years ago

0.6.0-next.3

2 years ago

0.6.0-next.2

2 years ago

0.6.0-next.4

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.7.0-next.0

2 years ago

0.2.0-next.0

2 years ago

0.3.0-next.1

2 years ago

0.3.0-next.0

2 years ago

0.5.0

2 years ago

0.6.0-next.1

2 years ago

0.6.0-next.0

2 years ago

0.4.0-next.2

2 years ago

0.4.0-next.3

2 years ago

0.4.0-next.0

2 years ago

0.4.0-next.1

2 years ago

0.5.1-next.0

2 years ago

0.3.0

2 years ago

0.4.0

2 years ago

0.5.0-next.0

2 years ago

0.2.0

2 years ago

0.1.1-next.0

2 years ago

0.1.0

2 years ago

0.1.1

2 years ago

0.1.2-next.1

2 years ago

0.1.2-next.0

2 years ago

0.1.0-next.0

2 years ago

0.0.8

2 years ago

0.0.5

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.7-next.0

2 years ago

0.0.8-next.0

2 years ago

0.0.8-next.1

2 years ago

0.0.5-next.3

2 years ago

0.0.6-next.0

2 years ago

0.0.5-next.1

2 years ago

0.0.5-next.2

2 years ago

0.0.5-next.0

2 years ago

0.0.3-next.10

2 years ago

0.0.1

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.4

2 years ago

0.0.3-next.9

2 years ago

0.0.3-next.7

2 years ago

0.0.2-next.7

2 years ago

0.0.3-next.8

2 years ago

0.0.2-next.6

2 years ago

0.0.3-next.5

2 years ago

0.0.2-next.5

2 years ago

0.0.3-next.6

2 years ago

0.0.2-next.4

2 years ago

0.0.1-next.0

2 years ago

0.0.3-next.3

2 years ago

0.0.2-next.3

2 years ago

0.0.3-next.4

2 years ago

0.0.2-next.2

2 years ago

0.0.3-next.1

2 years ago

0.0.2-next.1

2 years ago

0.0.3-next.2

2 years ago

0.0.2-next.0

2 years ago

0.0.3-next.0

2 years ago

0.0.4-next.0

2 years ago