Skip to content
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

build: fix storybook build #2659

Merged
merged 4 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading