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

SvelteKit: Introduce portable stories support #28918

Merged
merged 4 commits into from
Aug 19, 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
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ workflows:
requires:
- build-sandboxes
- vitest-integration:
parallelism: 4
parallelism: 5
requires:
- create-sandboxes
- bench:
Expand Down Expand Up @@ -789,7 +789,7 @@ workflows:
requires:
- build-sandboxes
- vitest-integration:
parallelism: 4
parallelism: 5
requires:
- create-sandboxes
- test-portable-stories:
Expand Down Expand Up @@ -856,7 +856,7 @@ workflows:
requires:
- build-sandboxes
- vitest-integration:
parallelism: 8
parallelism: 11
requires:
- create-sandboxes
- test-portable-stories:
Expand Down
10 changes: 8 additions & 2 deletions code/frameworks/sveltekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"exports": {
".": {
"types": "./dist/index.d.ts",
"node": "./dist/index.js",
"import": "./dist/index.mjs",
"node": "./dist/index.js",
"require": "./dist/index.js"
},
"./dist/preview.mjs": {
Expand All @@ -36,6 +36,11 @@
"types": "./dist/preset.d.ts",
"require": "./dist/preset.js"
},
"./vite": {
"types": "./dist/vite.d.ts",
"require": "./dist/vite.js",
"import": "./dist/vite.mjs"
},
"./package.json": "./package.json"
},
"main": "dist/index.js",
Expand Down Expand Up @@ -78,7 +83,8 @@
"entries": [
"./src/index.ts",
"./src/preview.ts",
"./src/preset.ts"
"./src/preset.ts",
"./src/vite.ts"
],
"platform": "node"
},
Expand Down
1 change: 1 addition & 0 deletions code/frameworks/sveltekit/src/portable-stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {

import type { SvelteRenderer } from '@storybook/svelte';
import { INTERNAL_DEFAULT_PROJECT_ANNOTATIONS as svelteAnnotations } from '@storybook/svelte';

import * as svelteKitAnnotations from './preview';

/**
Expand Down
5 changes: 5 additions & 0 deletions code/frameworks/sveltekit/src/vite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { mockSveltekitStores } from './plugins/mock-sveltekit-stores';

export const storybookSveltekitPlugin = () => {
return [mockSveltekitStores()];
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
import { enhance } from '$app/forms';
</script>

<form use:enhance>
<form use:enhance method="post">
<button>enhance</button>
</form>
8 changes: 3 additions & 5 deletions code/lib/cli-storybook/src/sandbox-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,7 @@ const baseTemplates = {
renderer: '@storybook/svelte',
builder: '@storybook/builder-vite',
},
// TODO: remove vitest-integration filter once project annotations exist for sveltekit
skipTasks: ['e2e-tests-dev', 'bench', 'vitest-integration'],
skipTasks: ['e2e-tests-dev', 'bench'],
},
'svelte-kit/skeleton-ts': {
name: 'SvelteKit Latest (Vite | TypeScript)',
Expand All @@ -461,8 +460,7 @@ const baseTemplates = {
renderer: '@storybook/svelte',
builder: '@storybook/builder-vite',
},
// TODO: remove vitest-integration filter once project annotations exist for sveltekit
skipTasks: ['e2e-tests-dev', 'bench', 'vitest-integration'],
skipTasks: ['e2e-tests-dev', 'bench'],
},
'svelte-kit/prerelease-ts': {
name: 'SvelteKit Prerelease (Vite | TypeScript)',
Expand All @@ -473,7 +471,7 @@ const baseTemplates = {
renderer: '@storybook/svelte',
builder: '@storybook/builder-vite',
},
skipTasks: ['e2e-tests-dev', 'bench', 'vitest-integration'],
skipTasks: ['e2e-tests-dev', 'bench'],
},
'lit-vite/default-js': {
name: 'Lit Latest (Vite | JavaScript)',
Expand Down
37 changes: 26 additions & 11 deletions scripts/tasks/sandbox-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,17 +360,40 @@ async function linkPackageStories(
);
}

const getVitestPluginInfo = (details: TemplateDetails) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding a type annotation for the return value of getVitestPluginInfo

let frameworkPluginImport = '';
let frameworkPluginCall = '';

const framework = details.template.expected.framework;
const isNextjs = framework.includes('nextjs');
const isSveltekit = framework.includes('sveltekit');

if (isNextjs) {
frameworkPluginImport = "import vitePluginNext from 'vite-plugin-storybook-nextjs'";
frameworkPluginCall = 'vitePluginNext()';
}

if (isSveltekit) {
frameworkPluginImport = "import { storybookSveltekitPlugin } from '@storybook/sveltekit/vite'";
frameworkPluginCall = 'storybookSveltekitPlugin()';
}

return { frameworkPluginImport, frameworkPluginCall };
};

export async function setupVitest(details: TemplateDetails, options: PassedOptionValues) {
const { sandboxDir, template } = details;

const isVue = template.expected.renderer === '@storybook/vue3';
const isNextjs = template.expected.framework.includes('nextjs');
const { frameworkPluginCall, frameworkPluginImport } = getVitestPluginInfo(details);
// const isAngular = template.expected.framework === '@storybook/angular';

const portableStoriesFrameworks = [
'@storybook/nextjs',
'@storybook/experimental-nextjs-vite',
// TODO: add sveltekit and angular once we enable their sandboxes
'@storybook/sveltekit',
// TODO: add angular once we enable their sandboxes
];
const storybookPackage = portableStoriesFrameworks.includes(template.expected.framework)
? template.expected.framework
Expand Down Expand Up @@ -409,7 +432,7 @@ export async function setupVitest(details: TemplateDetails, options: PassedOptio
dedent`
import { defineWorkspace, defaultExclude } from "vitest/config";
import { storybookTest } from "@storybook/experimental-addon-vitest/plugin";
${isNextjs ? "import vitePluginNext from 'vite-plugin-storybook-nextjs'" : ''}
${frameworkPluginImport}

export default defineWorkspace([
{
Expand All @@ -421,7 +444,7 @@ export async function setupVitest(details: TemplateDetails, options: PassedOptio
include: ["vitest"],
},
}),
${isNextjs ? 'vitePluginNext(),' : ''}
${frameworkPluginCall}
],
${
isNextjs
Expand Down Expand Up @@ -452,14 +475,6 @@ export async function setupVitest(details: TemplateDetails, options: PassedOptio
...defaultExclude,
// TODO: investigate TypeError: Cannot read properties of null (reading 'useContext')
"**/*argtypes*",
// TODO (SVELTEKIT): Failures related to missing framework annotations
"**/frameworks/sveltekit_svelte-kit-skeleton-ts/navigation.stories*",
"**/frameworks/sveltekit_svelte-kit-skeleton-ts/hrefs.stories*",
// TODO (SVELTEKIT): Investigate Error: use:enhance can only be used on <form> fields with method="POST"
"**/frameworks/sveltekit_svelte-kit-skeleton-ts/forms.stories*",
// TODO (SVELTE|SVELTEKIT): Typescript preprocessor issue
"**/frameworks/svelte-vite_svelte-vite-default-ts/ts-docs.stories.*",
"**/frameworks/sveltekit_svelte-kit-skeleton-ts/ts-docs.stories.*",
],
/**
* TODO: Either fix or acknowledge limitation of:
Expand Down