Skip to content

Commit

Permalink
build: fix storybook build (#2659)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Jeremias Peier <[email protected]>
  • Loading branch information
kyubisation and jeripeierSBB authored May 15, 2024
1 parent 05aac52 commit 19fa0c5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 27 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ jobs:
result-encoding: string
- name: Create versioned storybook for chromatic
run: STORYBOOK_COMPONENTS_VERSION=${{ steps.version.outputs.result }} yarn build:storybook
env:
CHROMATIC: true
- name: Publish to Chromatic
id: chromatic-publish
uses: chromaui/action@v1
Expand Down Expand Up @@ -192,7 +190,7 @@ jobs:
permissions:
packages: write
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: test
needs: lint
services:
visual-regression:
image: ghcr.io/${{ github.repository }}/visual-regression:baseline
Expand Down
20 changes: 1 addition & 19 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { StorybookConfig } from '@storybook/web-components-vite';
import { type BuildOptions, type UserConfig, mergeConfig } from 'vite';
import { type UserConfig, mergeConfig } from 'vite';

const config: StorybookConfig = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.ts'],
Expand All @@ -8,27 +8,9 @@ const config: StorybookConfig = {
name: '@storybook/web-components-vite',
options: {},
},
docs: {
autodocs: true,
},
async viteFinal(config) {
let build: BuildOptions = {};
if (process.env.CHROMATIC) {
build = {
sourcemap: false,
rollupOptions: {
output: {
manualChunks(_id) {
return 'main';
},
},
},
};
}

return mergeConfig(config, <UserConfig>{
assetsInclude: ['src/**/*.md'],
build,
});
},
};
Expand Down
17 changes: 13 additions & 4 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as tokens from '@sbb-esta/lyne-design-tokens';
import type { StoryContext } from '@storybook/types';
import type { Decorator } from '@storybook/web-components';
import type { Parameters, StoryContext } from '@storybook/types';
import type { Decorator, Preview } from '@storybook/web-components';
import isChromatic from 'chromatic/isChromatic';
import { html } from 'lit';

Expand Down Expand Up @@ -41,7 +41,7 @@ const storybookViewports = breakpoints.reduce(
{} as Record<string, number>,
);

export const parameters = {
const parameters: Parameters = {
// Set the viewports in Chromatic globally.
chromatic: {
delay: 2000,
Expand All @@ -52,6 +52,7 @@ export const parameters = {
breakpointNames,
debounceTimeout: 10,
},
tags: ['autodocs'],
docs: {
toc: {
ignoreSelector: '.docs-story h2',
Expand All @@ -70,11 +71,19 @@ export const parameters = {
},
};

export const decorators: Decorator[] = [
const decorators: Decorator[] = [
(story, context: StoryContext) =>
isChromatic() && context.parameters.layout !== 'fullscreen'
? html`<div style="padding: 2rem;min-height: 100vh">${story()}</div>`
: story(),
withBackgroundDecorator,
(story) => (isChromatic() ? html`<div class="sbb-disable-animation">${story()}</div>` : story()),
];

const preview: Preview = {
decorators,
parameters,
tags: ['autodocs'],
};

export default preview;
3 changes: 2 additions & 1 deletion tools/visual-regression-testing/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// and if it is not Linux, runs it in a container.

import { execSync, type ExecSyncOptionsWithStringEncoding } from 'child_process';
import { cpSync, existsSync, mkdirSync } from 'fs';
import { cpSync, existsSync, mkdirSync, writeFileSync } from 'fs';
import { platform } from 'os';

import { startTestRunner } from '@web/test-runner';
Expand All @@ -24,6 +24,7 @@ if (process.env.GITHUB_ACTIONS) {
const screenshotDir = new URL('../../dist/screenshots/', import.meta.url);
const artifactDir = new URL('../../dist/screenshots-artifact/', import.meta.url);
mkdirSync(artifactDir, { recursive: true });
writeFileSync(new URL('./.keep', artifactDir), '', 'utf8');

if (runner.passed) {
// Tests passed. Do nothing.
Expand Down

0 comments on commit 19fa0c5

Please sign in to comment.