Repository navigation
feat(storybook): adopt Storybook 10 with Vite framework and Vitest addon #924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
karelhala
merged 1 commit into
RedHatInsights:master
from
riccardo-forina:feat/storybook-adoption
Oct 23, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| name: Storybook | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [master] | ||
| push: | ||
| branches: [master] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| build: | ||
| name: Build Storybook | ||
| runs-on: ubuntu-24.04 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 | ||
| with: | ||
| node-version: 22 | ||
| cache: npm | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Build Storybook | ||
| run: npm run build-storybook | ||
|
|
||
| - name: Upload Storybook artifacts | ||
| uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4 | ||
| with: | ||
| name: storybook-static | ||
| path: storybook-static | ||
| retention-days: 7 | ||
|
|
||
| test: | ||
| name: Storybook interaction tests | ||
| runs-on: ubuntu-24.04 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 | ||
| with: | ||
| node-version: 22 | ||
| cache: npm | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Install Playwright browsers | ||
| run: npx playwright install --with-deps chromium | ||
|
|
||
| # The Vitest addon runs the stories directly in a browser through | ||
| # @vitest/browser-playwright — no built Storybook or HTTP server needed. | ||
| - name: Run Storybook tests | ||
| run: npm run test:storybook | ||
| env: | ||
| CI: true | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import path from 'path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { createMainConfig } from '@redhat-cloud-services/hcc-storybook-hub/config'; | ||
|
|
||
| const dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
|
|
||
| const config = createMainConfig({ | ||
| stories: ['../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'], | ||
| msw: true, | ||
| a11y: false, | ||
| extraAliases: { | ||
| '@redhat-cloud-services/chrome': path.resolve(dirname, 'mocks/chrome.ts'), | ||
| '@scalprum/react-core': path.resolve(dirname, 'mocks/scalprum.tsx'), | ||
| }, | ||
| }); | ||
|
|
||
| // The fec utilities mixins (frontend-components-utilities/styles/_mixins) | ||
| // use Sass global built-ins (round(), unit(), type-of()) that Dart Sass | ||
| // deprecates. That's library-internal — silence those IDs, keep ours loud. | ||
| const originalViteFinal = config.viteFinal; | ||
| config.viteFinal = async ( | ||
| viteConfig: Parameters<NonNullable<typeof originalViteFinal>>[0], | ||
| ) => { | ||
| const result = await originalViteFinal?.(viteConfig); | ||
| if (result) { | ||
| result.css = result.css ?? {}; | ||
| result.css.preprocessorOptions = { | ||
| ...(result.css.preprocessorOptions ?? {}), | ||
| scss: { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| ...((result.css.preprocessorOptions as any)?.scss ?? {}), | ||
| silenceDeprecations: ['global-builtin', 'import'], | ||
| }, | ||
| }; | ||
| } | ||
| return result; | ||
| }; | ||
|
|
||
| export default config; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Storybook mock for @redhat-cloud-services/chrome's useLastVisited. | ||
| // Wired through extraAliases in .storybook/main.ts (deterministic module | ||
| // replacement — stronger than per-story moduleMock in browser mode). | ||
| export const lastVisitedData = [ | ||
| { | ||
| bundle: 'Insights', | ||
| pathname: '/insights/advisor', | ||
| title: 'Advisor recommendations', | ||
| }, | ||
| { | ||
| bundle: 'OpenShift', | ||
| pathname: '/openshift/', | ||
| title: 'OpenShift cluster list', | ||
| }, | ||
| { bundle: 'Settings', pathname: '/settings/', title: 'Settings' }, | ||
| ]; | ||
|
|
||
| export const useLastVisited = () => lastVisitedData; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import React from 'react'; | ||
|
|
||
| /** | ||
| * Storybook stub for @scalprum/react-core's remote loader. | ||
| * | ||
| * The app is a federation host: the Landing route mounts widgetLayout's | ||
| * WidgetLayout module through ScalprumComponent. Stories exercise the | ||
| * app's own wiring (routing, prop passthrough, chrome navigation) — the | ||
| * stub renders what the federated module WOULD mount, labeled by | ||
| * scope/module, without loading real remotes. | ||
| */ | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| export const ScalprumComponent = ({ scope, module, layoutType }: any) => ( | ||
| <div | ||
| data-testid="scalprum-stub" | ||
| data-scope={scope} | ||
| data-module={module} | ||
| data-layout-type={layoutType} | ||
| > | ||
| Scalprum stub: {scope}/{module} | ||
| </div> | ||
| ); | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| export const ScalprumProvider = ({ children }: any) => <>{children}</>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import type { Preview } from '@storybook/react-vite'; | ||
| import '@patternfly/react-core/dist/styles/base.css'; | ||
| import '@redhat-cloud-services/hcc-storybook-hub/css/storybook.css'; | ||
| import React from 'react'; | ||
| import { MemoryRouter } from 'react-router-dom'; | ||
| import { | ||
| HccStorybookProvider, | ||
| hccPreviewDefaults, | ||
| } from '@redhat-cloud-services/hcc-storybook-hub'; | ||
|
|
||
| const preview: Preview = { | ||
| ...hccPreviewDefaults, | ||
| decorators: [ | ||
| (Story, { parameters }) => ( | ||
| <HccStorybookProvider | ||
| bundle="landing-page" | ||
| app="landing" | ||
| environment={parameters.chrome?.environment ?? 'production'} | ||
| featureFlags={parameters.featureFlags} | ||
| > | ||
| <MemoryRouter> | ||
| <Story /> | ||
| </MemoryRouter> | ||
| </HccStorybookProvider> | ||
| ), | ||
| ], | ||
| parameters: { | ||
| ...hccPreviewDefaults.parameters, | ||
| options: { | ||
| storySort: { | ||
| method: 'alphabetical', | ||
| order: ['Documentation', 'Widgets', 'Routes', 'Components', '*'], | ||
| }, | ||
| }, | ||
| chrome: { | ||
| environment: 'production', | ||
| }, | ||
| featureFlags: {}, | ||
| }, | ||
| }; | ||
|
|
||
| export default preview; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Vitest setup for unit tests (ported from config/setupTests.js — jest globals). | ||
| // Property assignment only: never replace `window` whole, prototype-bound | ||
| // methods (getComputedStyle etc.) must survive for react-jss/css-vendor. | ||
|
|
||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
|
||
| const insights = { | ||
| chrome: { | ||
| getEnvironment: () => 'prod', | ||
| }, | ||
| }; | ||
|
|
||
| (globalThis as any).insights = insights; | ||
| (globalThis as any).window.insights = insights; | ||
| (globalThis as any).window.__webpack_share_scopes__ = { | ||
| default: {}, | ||
| }; | ||
|
|
||
| // fix: `matchMedia` not present, jsdom/happy-dom require a polyfill | ||
| if (typeof (globalThis as any).matchMedia !== 'function') { | ||
| (globalThis as any).matchMedia = function () { | ||
| return { | ||
| matches: false, | ||
| addListener: function () {}, | ||
| removeListener: function () {}, | ||
| }; | ||
| }; | ||
| } |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.