Storybook Addon
Status: Stable
@qs/storybook-addon-design-tests is a Storybook addon for @qs/design-tests. It publishes the build info of a Storybook as /git-metadata.json, so design-tests run records which app commit it captured. The addon has no user interface.
Requirements
- Storybook 7.6, 8.6 or 10. The addon uses
staticDirs, which does not depend on the builder. - Node.js 24 or later.
- The package ships ES modules only.
Installation
Install the package as a dev dependency of the app that owns the Storybook:
pnpm add -D @qs/storybook-addon-design-tests
Add the addon to the addons of the Storybook main config:
// .storybook/main.js
module.exports = {
addons: ["@qs/storybook-addon-design-tests"],
};
storybook dev and storybook build then serve /git-metadata.json at the root of the Storybook:
{
"gitHash": "abc123def456789...",
"createdAt": "2026-11-17T10:00:00.000Z"
}
The preset writes the file into node_modules/.cache/qs-storybook-addon-design-tests/ and adds that directory to staticDirs. The static build holds the file at its root. The file is public on every Storybook host, so it holds only these two fields. design-tests run derives its reference from gitHash. No generator script, no staticDirs entry and no .gitignore line are needed.
Options
Pass options with the object form of the addon:
module.exports = {
addons: [{ name: "@qs/storybook-addon-design-tests", options: { outputPath: "/meta/git-metadata.json" } }],
};
| Option | Default | Effect |
|---|---|---|
outputPath | /git-metadata.json | Where the file is served, relative to the Storybook root. A path that leaves the root falls back to the default with a warning. |
enabled | true | Set to false to turn the addon off, for example for a local build outside a git checkout. |
A path other than /git-metadata.json is not found by design-tests run, which reads /git-metadata.json.
Commit resolution
The addon resolves gitHash in this order and uses the first value it finds:
DESIGN_TESTS_GIT_HASH, an explicit override.- The commit variable of a common CI system:
GIT_COMMIT(Jenkins with the git plugin),GITHUB_SHA(GitHub Actions),CI_COMMIT_SHA(GitLab CI),BITBUCKET_COMMIT(Bitbucket Pipelines),BUILD_SOURCEVERSION(Azure Pipelines). git rev-parse HEADin the directory where Storybook runs. If none of these resolves, the Storybook build fails with a message that namesDESIGN_TESTS_GIT_HASH, the CI variables and the optionenabled: false.
DESIGN_TESTS_BUILD_TIME (ISO 8601) overrides createdAt. The default is the build time. A value that is not a date fails the build. The addon prints one line that names the source of the commit, for example gitHash … from GITHUB_SHA.
The build also fails when the addon cannot write the file, for example into a read-only node_modules. A warning would go unseen, and missing build info causes problems later. Fix the cause, or set enabled: false to turn the addon off.
Most pipelines already have the commit in the environment, so the addon needs no setting there. Set DESIGN_TESTS_GIT_HASH when a pipeline builds from a copy of the source without .git, or when the variable of the CI system is empty. Storybook git metadata has an example for each CI system.
Verification
Build the Storybook and read the file:
pnpm build-storybook
cat storybook-static/git-metadata.json
Then run the tests. The run prints Current metadata detected from /git-metadata.json. See Storybook git metadata.
Related Documentation
- Storybook git metadata: the file contract, CI examples and the generator script for a project that is not a Storybook.
- Baseline Management: how the commit of a baseline is recorded.