Skip to content

Commit

Permalink
Setup Storybook for player application
Browse files Browse the repository at this point in the history
I thrown away global-per-story approach, as it comes with delay between
the story loads and globals (styles) are applied. Even it's subtle and
will be diminished on subsequential accesses due to cache, this is not
acceptable.

By separating Storybook, CI time will be faster and no hack for
Storybook's sandbox limitation.
  • Loading branch information
pocka committed Aug 30, 2024
1 parent 4d910a0 commit c366899
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 18 deletions.
49 changes: 38 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- name: Check Gleam types
run: "gleam check"

build-storybook:
build-player-storybook:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -73,19 +73,44 @@ jobs:
- name: Install dependencies
run: "bun i"
- name: Build Storybook
run: "bun run build:storybook"
run: "bun run build:storybook/player"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: storybook
path: storybook-static
name: player-storybook
path: storybook-static/player

build-builder-storybook:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Gleam
uses: erlef/setup-beam@v1
with:
otp-version: "27"
gleam-version: "1.4"
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: "1.1"
- name: Install dependencies
run: "bun i"
- name: Build Storybook
run: "bun run build:storybook/builder"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: builder-storybook
path: storybook-static/builder

prep-artifact-for-pages:
# Deploy only on master branch
if: github.ref == 'refs/heads/master'
needs:
- build
- build-storybook
- build-player-storybook
- build-builder-storybook
runs-on: ubuntu-latest
steps:
- name: Download main artifacts
Expand Down Expand Up @@ -126,16 +151,16 @@ jobs:

test-storybook:
needs:
- build-storybook
- build-player-storybook
- build-builder-storybook
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download built Storybook
uses: actions/download-artifact@v4
with:
path: storybook-static
name: storybook
pattern: "*-storybook"
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
Expand All @@ -151,9 +176,11 @@ jobs:
run: "npx playwright install --with-deps"
- name: Run tests
run: |
npx concurrently -k -s first -n "SB,TEST" -c "magenta,blue" \
"npx http-server storybook-static --port 6006 --silent" \
"npx wait-on tcp:6006 && bun run test:storybook --browsers chromium,firefox,webkit"
npx concurrently -k -s first -n "SB_PLAYER,SB_BUILDER,TEST_PLAYER,TEST_BUILDER" \
"npx http-server player-storybook --port 6006 --silent" \
"npx http-server builder-storybook --port 6007 --silent" \
"npx wait-on tcp:6006 && bun run test:storybook/player --browsers chromium,firefox,webkit" \
"npx wait-on tcp:6007 && bun run test:storybook/builder --browsers chromium,firefox,webkit"
cleanup:
needs:
Expand Down
21 changes: 21 additions & 0 deletions .storybook/builder/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-FileCopyrightText: 2024 Shota FUJI <pockawoooh@gmail.com>
//
// SPDX-License-Identifier: Apache-2.0

import type { StorybookConfig } from "@storybook/html-vite";

export default {
framework: "@storybook/html-vite",
stories: ["../../src/builder/**/*.stories.ts"],
addons: ["@storybook/addon-essentials", "@storybook/addon-interactions"],
core: {
builder: {
name: "@storybook/builder-vite",
options: {
viteConfigPath: new URL("../../vite.config.js", import.meta.url).pathname,
},
},
disableTelemetry: true,
disableWhatsNewNotifications: true,
},
} satisfies StorybookConfig;
6 changes: 3 additions & 3 deletions .storybook/preview.ts → .storybook/builder/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
//
// SPDX-License-Identifier: Apache-2.0

import "../src/builder/main.css";
import * as lucide from "../src/builder/lucide";
import * as logo from "../src/builder/ui/logo";
import "../../src/builder/main.css";
import * as lucide from "../../src/builder/lucide";
import * as logo from "../../src/builder/ui/logo";

lucide.register();
logo.register();
8 changes: 7 additions & 1 deletion .storybook/main.ts → .storybook/player/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import type { StorybookConfig } from "@storybook/html-vite";

export default {
framework: "@storybook/html-vite",
stories: ["../src/**/*.stories.ts"],
stories: ["../../src/Player/**/*.stories.ts"],
addons: ["@storybook/addon-essentials", "@storybook/addon-interactions"],
core: {
builder: {
name: "@storybook/builder-vite",
options: {
viteConfigPath: new URL("../../vite.config.js", import.meta.url).pathname,
},
},
disableTelemetry: true,
disableWhatsNewNotifications: true,
},
Expand Down
7 changes: 7 additions & 0 deletions .storybook/player/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-FileCopyrightText: 2024 Shota FUJI <pockawoooh@gmail.com>
//
// SPDX-License-Identifier: Apache-2.0

import "../../src/inline.css";
import "../../src/vars.css";
import "../../src/custom_elements";
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
"scripts": {
"dev": "vite",
"build": "vite build",
"storybook": "storybook dev --no-open --port 6006",
"build:storybook": "storybook build",
"test:storybook": "test-storybook"
"storybook/player": "storybook dev --config-dir .storybook/player --no-open --port 6006",
"storybook/builder": "storybook dev --config-dir .storybook/builder --no-open --port 6007",
"build:storybook/player": "storybook build --config-dir .storybook/player --output-dir storybook-static/player",
"build:storybook/builder": "storybook build --config-dir .storybook/builder --output-dir storybook-static/builder",
"test:storybook/player": "test-storybook --config-dir .storybook/player",
"test:storybook/builder": "test-storybook --config-dir .storybook/builder --url http://localhost:6007"
},
"dependencies": {
"@diffusionstudio/vits-web": "^1.0.2",
Expand Down
40 changes: 40 additions & 0 deletions src/Player/test.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-FileCopyrightText: 2024 Shota FUJI <pockawoooh@gmail.com>
//
// SPDX-License-Identifier: Apache-2.0

import { type Meta, type StoryObj } from "@storybook/html";
import { expect, userEvent, waitFor } from "@storybook/test";

export default {
render() {
const container = document.createElement("div");
container.style.display = "flex";
container.style.flexDirection = "column";
container.style.gap = "8px";

const output = document.createElement("output");

const button = document.createElement("button");
button.textContent = "Button";
button.type = "button";
button.addEventListener("click", () => {
output.value = "Clicked";
});

container.appendChild(button);
container.appendChild(output);

return container;
},
} satisfies Meta;

type Story = StoryObj;

export const Static = {} satisfies Story;

export const Test = {
async play({ canvas }) {
await userEvent.click(canvas.getByRole("button"));
await waitFor(() => expect(canvas.getByRole("status")).toHaveValue("Clicked"));
},
} satisfies Story;

0 comments on commit c366899

Please sign in to comment.