Skip to content

Commit ea253f6

Browse files
authored
Merge pull request #377 from chromaui/next
Release Visual Tests addon for Storybook 9
2 parents 296009e + c0ca974 commit ea253f6

File tree

206 files changed

+6340
-10418
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

206 files changed

+6340
-10418
lines changed

.eslintignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.eslintrc.cjs

Lines changed: 0 additions & 29 deletions
This file was deleted.

.github/workflows/chromatic.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Chromatic"
1+
name: 'Chromatic'
22
on: push
33
jobs:
44
chromatic:

.github/workflows/test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Test"
1+
name: 'Test'
22
on: push
33
jobs:
44
test:
@@ -13,6 +13,9 @@ jobs:
1313
- name: Lint
1414
run: yarn lint
1515

16+
- name: Check formatting
17+
run: yarn format --no-write --check
18+
1619
- name: Typecheck
1720
run: yarn typecheck
1821

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v18
1+
v20

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
.yarn
12
dist
3+
public
4+
src/gql
5+
src/utils/sha256.js

.prettierrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.prettierrc.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
printWidth: 100,
3+
tabWidth: 2,
4+
semi: true,
5+
singleQuote: true,
6+
trailingComma: 'es5',
7+
bracketSpacing: true,
8+
};

.storybook/main.ts

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,52 @@
1-
import type { StorybookConfig } from "@storybook/react-vite";
2-
import { mergeConfig } from "vite";
3-
import turbosnap from "vite-plugin-turbosnap";
1+
import type { StorybookConfig } from '@storybook/react-vite';
2+
import { mergeConfig } from 'vite';
3+
import turbosnap from 'vite-plugin-turbosnap';
44

5-
import { CHROMATIC_BASE_URL } from "../src/constants";
5+
import { CHROMATIC_BASE_URL } from '../src/constants';
66

7-
const useDistVersion = process.env.CHROMATIC_USE_DIST_VERSION === "true";
7+
const useDistVersion = process.env.CHROMATIC_USE_DIST_VERSION === 'true';
88

99
const configFileMap = {
10-
"https://www.chromatic.com": "production.config.json",
11-
"https://www.staging-chromatic.com": "staging.config.json",
12-
"https://www.dev-chromatic.com": "development.config.json",
10+
'https://www.chromatic.com': 'production.config.json',
11+
'https://www.staging-chromatic.com': 'staging.config.json',
12+
'https://www.dev-chromatic.com': 'development.config.json',
1313
};
1414

1515
const config: StorybookConfig = {
1616
addons: [
17+
'@storybook/addon-docs',
18+
'@storybook/addon-designs',
1719
{
18-
name: "@storybook/addon-essentials",
19-
options: {
20-
backgrounds: false,
21-
viewport: false,
22-
},
23-
},
24-
"@storybook/addon-interactions",
25-
"@storybook/addon-designs",
26-
{
27-
name: useDistVersion ? "../dist/preset.js" : "../src/dev.ts",
20+
name: useDistVersion ? '../dist/preset.js' : '../src/dev.ts',
2821
options: {
2922
configFile: configFileMap[CHROMATIC_BASE_URL || '"https://www.chromatic.com"'],
3023
},
3124
},
32-
"@storybook/addon-mdx-gfm",
3325
],
34-
docs: {
35-
autodocs: "tag",
36-
},
3726
framework: {
38-
name: "@storybook/react-vite",
27+
name: '@storybook/react-vite',
3928
options: {},
4029
},
41-
logLevel: "debug",
42-
staticDirs: ["../public"],
43-
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
30+
logLevel: 'debug',
31+
staticDirs: ['../public'],
32+
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
4433
refs: {
45-
"@storybook/components": {
46-
title: "Storybook Components",
47-
url: "https://next--635781f3500dd2c49e189caf.chromatic.com/",
34+
'storybook/internal/components': {
35+
title: 'Storybook Components',
36+
url: 'https://next--635781f3500dd2c49e189caf.chromatic.com/',
4837
expanded: false,
4938
},
50-
"@storybook/icons": {
51-
title: "Storybook Icons",
52-
url: "https://main--64b56e737c0aeefed9d5e675.chromatic.com/",
39+
'@storybook/icons': {
40+
title: 'Storybook Icons',
41+
url: 'https://main--64b56e737c0aeefed9d5e675.chromatic.com/',
5342
expanded: false,
5443
},
5544
},
5645
async viteFinal(config, { configType }) {
5746
const rootDir = config.root ?? process.cwd();
5847
return mergeConfig(config, {
59-
define: { "process.env": { CHROMATIC_API_URL: "/api" } },
60-
plugins: configType === "PRODUCTION" ? [turbosnap({ rootDir })] : [],
48+
define: { 'process.env': { CHROMATIC_API_URL: '/api' } },
49+
plugins: configType === 'PRODUCTION' ? [turbosnap({ rootDir })] : [],
6150
});
6251
},
6352
};

.storybook/preview.tsx

Lines changed: 58 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { action } from "@storybook/addon-actions";
2-
import { ManagerContext } from "@storybook/manager-api";
3-
import type { Decorator, Loader, Preview } from "@storybook/react";
4-
import { fn } from "@storybook/test";
1+
import { ManagerContext } from 'storybook/manager-api';
2+
import type { Decorator, Loader, Preview } from '@storybook/react-vite';
3+
import { fn } from 'storybook/test';
54
import {
65
Global,
76
ThemeProvider,
@@ -10,19 +9,20 @@ import {
109
styled,
1110
themes,
1211
useTheme,
13-
} from "@storybook/theming";
14-
import { HttpResponse, graphql } from "msw";
15-
import { initialize, mswLoader } from "msw-storybook-addon";
16-
import React from "react";
12+
} from 'storybook/theming';
13+
import { HttpResponse, graphql } from 'msw';
14+
import { initialize, mswLoader } from 'msw-storybook-addon';
15+
import React from 'react';
1716

18-
import { AuthProvider } from "../src/AuthContext";
19-
import { baseModes } from "../src/modes";
20-
import { UninstallProvider } from "../src/screens/Uninstalled/UninstallContext";
21-
import { RunBuildProvider } from "../src/screens/VisualTests/RunBuildContext";
22-
import { GraphQLClientProvider } from "../src/utils/graphQLClient";
23-
import { storyWrapper } from "../src/utils/storyWrapper";
24-
import { TelemetryProvider } from "../src/utils/TelemetryContext";
25-
import { useSessionState } from "../src/utils/useSessionState";
17+
import { AuthProvider } from '../src/AuthContext';
18+
import { baseModes } from '../src/modes';
19+
import { UninstallProvider } from '../src/screens/Uninstalled/UninstallContext';
20+
import { RunBuildProvider } from '../src/screens/VisualTests/RunBuildContext';
21+
import { GraphQLClientProvider } from '../src/utils/graphQLClient';
22+
import { storyWrapper } from '../src/utils/storyWrapper';
23+
import { TelemetryProvider } from '../src/utils/TelemetryContext';
24+
import { useSessionState } from '../src/utils/useSessionState';
25+
import { action } from 'storybook/actions';
2626

2727
// Initialize MSW
2828
initialize({
@@ -38,34 +38,34 @@ initialize({
3838
},
3939
});
4040

41-
const Panels = styled.div<{ orientation: "right" | "bottom" }>(
41+
const Panels = styled.div<{ orientation: 'right' | 'bottom' }>(
4242
({ orientation }) => ({
43-
flexDirection: orientation === "right" ? "row" : "column",
43+
flexDirection: orientation === 'right' ? 'row' : 'column',
4444
}),
4545
{
46-
display: "flex",
47-
justifyContent: "center",
48-
alignItems: "center",
46+
display: 'flex',
47+
justifyContent: 'center',
48+
alignItems: 'center',
4949
gap: 40,
5050
padding: 40,
5151
}
5252
);
5353

54-
const Panel = styled.div<{ orientation: "right" | "bottom" }>(
54+
const Panel = styled.div<{ orientation: 'right' | 'bottom' }>(
5555
({ orientation }) => ({
56-
width: orientation === "right" ? 420 : 880,
57-
height: orientation === "right" ? 640 : 300,
58-
overflow: "auto",
56+
width: orientation === 'right' ? 420 : 880,
57+
height: orientation === 'right' ? 640 : 300,
58+
overflow: 'auto',
5959
}),
6060
({ theme }) => ({
61-
containerType: "size",
62-
containerName: "storybookRoot",
63-
position: "relative",
61+
containerType: 'size',
62+
containerName: 'storybookRoot',
63+
position: 'relative',
6464
outline: `1px solid ${theme.appBorderColor}`,
6565
// Add a backdrop to the outline because appBorderColor is semi-transparent
6666
boxShadow: `0 0 0 1px ${theme.background.content}`,
6767
background: theme.background.content,
68-
color: theme.base === "light" ? theme.color.dark : theme.color.mediumlight,
68+
color: theme.base === 'light' ? theme.color.dark : theme.color.mediumlight,
6969
fontSize: theme.typography.size.s2,
7070
})
7171
);
@@ -83,17 +83,17 @@ const ThemedSetRoot = () => {
8383
// Render two panels side-by-side or stacked, depending on selected orientation
8484
// Note this assumes any play functions are equipped to deal with multiple canvases
8585
const withTheme = (StoryFn, { globals, parameters }) => {
86-
const theme = globals.theme || parameters.theme || "right";
87-
return theme === "light" || theme === "dark" ? (
86+
const theme = globals.theme || parameters.theme || 'right';
87+
return theme === 'light' || theme === 'dark' ? (
8888
<ThemeProvider theme={convert(themes[theme])}>
8989
<Global styles={createReset} />
9090
<Global
9191
styles={{
92-
"#storybook-root": {
93-
height: "100vh",
92+
'#storybook-root': {
93+
height: '100vh',
9494
padding: 0,
95-
containerType: "size",
96-
containerName: "storybookRoot",
95+
containerType: 'size',
96+
containerName: 'storybookRoot',
9797
},
9898
}}
9999
></Global>
@@ -125,27 +125,27 @@ const withTheme = (StoryFn, { globals, parameters }) => {
125125
const withGraphQLClient = storyWrapper(GraphQLClientProvider);
126126

127127
const withTelemetry = storyWrapper(TelemetryProvider, () => ({
128-
value: action("telemetry"),
128+
value: fn().mockName('telemetry'),
129129
}));
130130

131131
const withAuth = storyWrapper(AuthProvider, () => ({
132132
value: {
133-
accessToken: "token",
133+
accessToken: 'token',
134134
setAccessToken: fn(),
135-
subdomain: "www",
135+
subdomain: 'www',
136136
setSubdomain: fn(),
137137
},
138138
}));
139139

140140
const withManagerApi = storyWrapper(ManagerContext.Provider, ({ argsByTarget }) => ({
141141
value: {
142-
api: { ...argsByTarget["manager-api"] },
142+
api: { ...argsByTarget['manager-api'] },
143143
state: {},
144144
},
145145
}));
146146

147147
const withUninstall: Decorator = (Story) => {
148-
const [addonUninstalled, setAddonUninstalled] = useSessionState("addonUninstalled", false);
148+
const [addonUninstalled, setAddonUninstalled] = useSessionState('addonUninstalled', false);
149149
return (
150150
<UninstallProvider
151151
addonUninstalled={addonUninstalled}
@@ -160,9 +160,9 @@ const withRunBuild = storyWrapper(RunBuildProvider, ({ args }) => ({
160160
watchState: {
161161
isRunning:
162162
!!args.localBuildProgress &&
163-
!["aborted", "complete", "error"].includes(args.localBuildProgress.currentStep),
164-
startBuild: action("startBuild"),
165-
stopBuild: action("stopBuild"),
163+
!['aborted', 'complete', 'error'].includes(args.localBuildProgress.currentStep),
164+
startBuild: fn().mockName('startBuild'),
165+
stopBuild: fn().mockName('stopBuild'),
166166
},
167167
}));
168168

@@ -222,14 +222,15 @@ const preview: Preview = {
222222
loaders: [graphQLArgLoader],
223223
parameters: {
224224
actions: {
225-
argTypesRegex: "^on[A-Z].*",
225+
argTypesRegex: '^on[A-Z].*',
226226
},
227227
backgrounds: {
228228
disable: true,
229229
},
230230
viewport: {
231+
disable: true,
231232
viewports: {
232-
default: { name: "Default", styles: { width: "960px", height: "720px" } },
233+
default: { name: 'Default', styles: { width: '960px', height: '720px' } },
233234
},
234235
},
235236
chromatic: {
@@ -241,27 +242,27 @@ const preview: Preview = {
241242
date: /Date$/,
242243
},
243244
},
244-
layout: "fullscreen",
245+
layout: 'fullscreen',
245246
},
246247
argTypes: {
247-
$graphql: { target: "graphql" },
248-
getChannel: { type: "function", target: "manager-api" },
248+
$graphql: { target: 'graphql' },
249+
getChannel: { type: 'function', target: 'manager-api' },
249250
},
250251
args: {
251-
getChannel: () => ({ on: fn(), off: fn(), emit: action("channel.emit") }),
252+
getChannel: () => ({ on: fn(), off: fn(), emit: fn().mockName('channel.emit') }),
252253
},
253254
globalTypes: {
254255
theme: {
255-
name: "Theme",
256-
description: "Panel theme",
256+
name: 'Theme',
257+
description: 'Panel theme',
257258
toolbar: {
258-
icon: "sidebaralt",
259-
title: "Theme",
259+
icon: 'sidebaralt',
260+
title: 'Theme',
260261
items: [
261-
{ value: "light", icon: "circlehollow", title: "Light" },
262-
{ value: "dark", icon: "circle", title: "Dark" },
263-
{ value: "right", icon: "sidebaralt", title: "Right 2-up" },
264-
{ value: "bottom", icon: "bottombar", title: "Bottom 2-up" },
262+
{ value: 'light', icon: 'circlehollow', title: 'Light' },
263+
{ value: 'dark', icon: 'circle', title: 'Dark' },
264+
{ value: 'right', icon: 'sidebaralt', title: 'Right 2-up' },
265+
{ value: 'bottom', icon: 'bottombar', title: 'Bottom 2-up' },
265266
],
266267
},
267268
},

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"editor.formatOnSave": true,
77
"eslint.rules.customizations": [{ "rule": "*", "severity": "warn" }],
88
"typescript.tsdk": "node_modules/typescript/lib",
9+
"typescript.enablePromptUseWorkspaceTsdk": true,
910
"vite.port": 6006
1011
}

0 commit comments

Comments
 (0)