Added storybook

This commit is contained in:
Nate Kelley 2025-08-12 22:05:05 -06:00
parent 0407be9acd
commit 7dc42159ba
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
8 changed files with 576 additions and 173 deletions

View File

@ -10,4 +10,6 @@ count.txt
.output .output
.vinxi .vinxi
todos.json todos.json
mcp-todos.json mcp-todos.json
*storybook.log
storybook-static

View File

@ -0,0 +1,28 @@
import type { StorybookConfig } from '@storybook/react-vite';
import { join, dirname } from "path"
/**
* This function is used to resolve the absolute path of a package.
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
*/
function getAbsolutePath(value: string): any {
return dirname(require.resolve(join(value, 'package.json')))
}
const config: StorybookConfig = {
"stories": [
"../src/**/*.mdx",
"../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"
],
"addons": [
getAbsolutePath('@chromatic-com/storybook'),
getAbsolutePath('@storybook/addon-docs'),
getAbsolutePath("@storybook/addon-a11y"),
getAbsolutePath("@storybook/addon-vitest")
],
"framework": {
"name": getAbsolutePath('@storybook/react-vite'),
"options": {}
}
};
export default config;

View File

@ -0,0 +1,25 @@
import type { Preview } from "@storybook/react-vite";
import "../src/styles/styles.css";
import { BusterStyleProvider } from "../src/context/BusterStyles";
const preview: Preview = {
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
},
decorators: [
(Story) => {
return (
<BusterStyleProvider>
<Story />
</BusterStyleProvider>
);
},
],
};
export default preview;

View File

@ -0,0 +1,7 @@
import * as a11yAddonAnnotations from "@storybook/addon-a11y/preview";
import { setProjectAnnotations } from '@storybook/react-vite';
import * as projectAnnotations from './preview';
// This is an important step to apply the right configuration when testing your stories.
// More info at: https://storybook.js.org/docs/api/portable-stories/portable-stories-vitest#setprojectannotations
setProjectAnnotations([a11yAddonAnnotations, projectAnnotations]);

View File

@ -10,7 +10,9 @@
"serve": "vite preview", "serve": "vite preview",
"test": "vitest run", "test": "vitest run",
"lint": "biome check --write", "lint": "biome check --write",
"typecheck": "tsc --noEmit" "typecheck": "tsc --noEmit",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
}, },
"dependencies": { "dependencies": {
"@buster/server-shared": "workspace:*", "@buster/server-shared": "workspace:*",
@ -86,6 +88,11 @@
}, },
"devDependencies": { "devDependencies": {
"@biomejs/biome": "2.1.4", "@biomejs/biome": "2.1.4",
"@chromatic-com/storybook": "^4.1.0",
"@storybook/addon-a11y": "^9.1.2",
"@storybook/addon-docs": "^9.1.2",
"@storybook/addon-vitest": "^9.1.2",
"@storybook/react-vite": "^9.1.2",
"@tanstack/devtools-event-client": "^0.2.1", "@tanstack/devtools-event-client": "^0.2.1",
"@testing-library/dom": "^10.4.1", "@testing-library/dom": "^10.4.1",
"@testing-library/react": "^16.3.0", "@testing-library/react": "^16.3.0",
@ -100,11 +107,15 @@
"@vitest/ui": "3.2.4", "@vitest/ui": "3.2.4",
"jsdom": "^26.1.0", "jsdom": "^26.1.0",
"sass": "^1.90.0", "sass": "^1.90.0",
"storybook": "^9.1.2",
"typescript": "^5.9.0", "typescript": "^5.9.0",
"vite": "^7.1.2", "vite": "^7.1.2",
"vite-plugin-checker": "^0.10.2", "vite-plugin-checker": "^0.10.2",
"vite-tsconfig-paths": "catalog:", "vite-tsconfig-paths": "catalog:",
"vitest": "^3.2.4", "vitest": "^3.2.4",
"web-vitals": "^5.1.0" "web-vitals": "^5.1.0",
"@vitest/browser": "3.2.4",
"playwright": "^1.54.2",
"@vitest/coverage-v8": "3.2.4"
} }
} }

View File

@ -1,69 +1,65 @@
/// <reference types="vitest/config" />
import { resolve } from 'node:path'; import { resolve } from 'node:path';
import tsconfigPaths from 'vite-tsconfig-paths'; import tsconfigPaths from 'vite-tsconfig-paths';
import { defineConfig } from 'vitest/config'; import { defineConfig } from 'vitest/config';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { storybookTest } from '@storybook/addon-vitest/vitest-plugin';
const dirname = typeof __dirname !== 'undefined' ? __dirname : path.dirname(fileURLToPath(import.meta.url));
// More info at: https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon
export default defineConfig({ export default defineConfig({
plugins: [ plugins: [tsconfigPaths({
tsconfigPaths({ root: resolve(__dirname),
root: resolve(__dirname), projects: [resolve(__dirname, 'tsconfig.json')]
projects: [resolve(__dirname, 'tsconfig.json')], }) as unknown as Plugin],
}) as unknown as Plugin,
],
esbuild: { esbuild: {
jsx: 'automatic', jsx: 'automatic'
}, },
test: { test: {
globals: true, globals: true,
environment: 'jsdom', // For React components environment: 'jsdom',
// For React components
setupFiles: ['./vitest.setup.ts'], setupFiles: ['./vitest.setup.ts'],
pool: 'forks', pool: 'forks',
poolOptions: { poolOptions: {
forks: { forks: {
maxForks: process.env.CI ? 1 : 8, maxForks: process.env.CI ? 1 : 8,
minForks: process.env.CI ? 1 : 8, minForks: process.env.CI ? 1 : 8
}, }
}, },
include: ['**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], include: ['**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
exclude: [ exclude: ['**/node_modules/**', '**/dist/**', '**/.next/**', '**/playwright-tests/**', '**/coverage/**'],
'**/node_modules/**',
'**/dist/**',
'**/.next/**',
'**/playwright-tests/**',
'**/coverage/**',
],
coverage: { coverage: {
provider: 'v8', provider: 'v8',
reporter: ['text', 'json', 'html'], reporter: ['text', 'json', 'html'],
exclude: [ exclude: ['coverage/**', 'dist/**', '**/node_modules/**', '**/[.]**', 'packages/*/test{,s}/**', '**/*.d.ts', '**/virtual:*', '**/__x00__*', '**/\x00*', 'cypress/**', 'test{,s}/**', 'test{,-*}.{js,cjs,mjs,ts,tsx,jsx}', '**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx}', '**/*{.,-}spec.{js,cjs,mjs,ts,tsx,jsx}', '**/tests/**', '**/__tests__/**', '**/.{eslint,mocha,prettier}rc.{js,cjs,yml}', '**/vitest.{workspace,projects}.[jt]s?(on)', '**/vitest.config.[jt]s', '**/playwright.config.[jt]s', '**/.storybook/**', '**/storybook-static/**']
'coverage/**',
'dist/**',
'**/node_modules/**',
'**/[.]**',
'packages/*/test{,s}/**',
'**/*.d.ts',
'**/virtual:*',
'**/__x00__*',
'**/\x00*',
'cypress/**',
'test{,s}/**',
'test{,-*}.{js,cjs,mjs,ts,tsx,jsx}',
'**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx}',
'**/*{.,-}spec.{js,cjs,mjs,ts,tsx,jsx}',
'**/tests/**',
'**/__tests__/**',
'**/.{eslint,mocha,prettier}rc.{js,cjs,yml}',
'**/vitest.{workspace,projects}.[jt]s?(on)',
'**/vitest.config.[jt]s',
'**/playwright.config.[jt]s',
'**/.storybook/**',
'**/storybook-static/**',
],
}, },
projects: [{
extends: true,
plugins: [
// The plugin will run tests for the stories defined in your Storybook config
// See options at: https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon#storybooktest
storybookTest({
configDir: path.join(dirname, '.storybook')
})],
test: {
name: 'storybook',
browser: {
enabled: true,
headless: true,
provider: 'playwright',
instances: [{
browser: 'chromium'
}]
},
setupFiles: ['.storybook/vitest.setup.ts']
}
}]
}, },
css: { css: {
postcss: { postcss: {
plugins: [], plugins: []
}, }
}, }
}); });

1
apps/web-tss/vitest.shims.d.ts vendored Normal file
View File

@ -0,0 +1 @@
/// <reference types="@vitest/browser/providers/playwright" />

File diff suppressed because it is too large Load Diff