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

Svelte: Support v5 prereleases #24889

Merged
merged 29 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7a06c93
feat: Update packages to match Svelte 5 (Beta)
allozaur Nov 17, 2023
27c2b3c
feat: Update code for Svelte's `render.ts`
allozaur Nov 17, 2023
5ea0ac9
feat: Use `createRoot` function to render `PreviewRender`
allozaur Nov 20, 2023
67c4c63
refactor: Remove legacy `$on` event
allozaur Nov 20, 2023
acaf0ce
Merge branch 'release-8-0' of github.com:storybookjs/storybook into a…
JReinhold Nov 22, 2023
baf72a6
expand svelte dependency version ranges
JReinhold Nov 22, 2023
e1475b7
Merge branch 'next' of github.com:storybookjs/storybook into allozaur…
JReinhold Nov 29, 2023
7abeedf
remove event handler, fix types
JReinhold Nov 29, 2023
f012da8
add back Svelte 4 support
JReinhold Nov 30, 2023
af572b8
add Svelte 5 sandbox
JReinhold Nov 30, 2023
3fdca57
add temporary push event
JReinhold Nov 30, 2023
4281a88
try pull_request event
JReinhold Nov 30, 2023
f33e3c9
remove temp event
JReinhold Nov 30, 2023
ab5ff2c
update yarn.lock
JReinhold Nov 30, 2023
073d84d
cleanup
JReinhold Nov 30, 2023
79c17ec
cleanup
JReinhold Nov 30, 2023
f9d8358
upgrade to svelte@5.0.0-next.16
JReinhold Dec 1, 2023
a44a421
Merge branch 'next' into allozaur/#24886
JReinhold Dec 1, 2023
25f3a33
add svelte 5 resolution to sveltekit prerelease sandbox
JReinhold Dec 4, 2023
8144998
Merge branch 'next' of github.com:storybookjs/storybook into allozaur…
JReinhold Dec 4, 2023
e07105b
fix addWorkaroundResolutions call
JReinhold Dec 4, 2023
876cbde
disable peer error instead of using resolutions
JReinhold Dec 4, 2023
15fd3f5
use sandbox key instead of dir
JReinhold Dec 5, 2023
b362874
Merge branch 'next' of github.com:storybookjs/storybook into allozaur…
JReinhold Dec 5, 2023
2a7bd55
upgrade svelte typings
JReinhold Dec 5, 2023
ab31b0d
fix broken yarn.lock
JReinhold Dec 5, 2023
32a8d30
rebuild yarn.lock
JReinhold Dec 6, 2023
7192c90
add template stories for sveltekit prerelease
JReinhold Dec 6, 2023
71a4575
disable actions e2e test for svelte prerelease
JReinhold Dec 6, 2023
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
10 changes: 5 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -614,30 +614,30 @@ workflows:
requires:
- build
- create-sandboxes:
parallelism: 35
parallelism: 36
requires:
- build
# - smoke-test-sandboxes: # disabled for now
# requires:
# - create-sandboxes
- build-sandboxes:
parallelism: 35
parallelism: 36
requires:
- create-sandboxes
- chromatic-sandboxes:
parallelism: 32
parallelism: 33
requires:
- build-sandboxes
- e2e-production:
parallelism: 30
parallelism: 31
requires:
- build-sandboxes
- e2e-dev:
parallelism: 2
requires:
- create-sandboxes
- test-runner-production:
parallelism: 30
parallelism: 31
requires:
- build-sandboxes
# TODO: reenable once we find out the source of flakyness
Expand Down
7 changes: 7 additions & 0 deletions code/e2e-tests/addon-actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ import process from 'process';
import { SbPage } from './util';

const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001';
const templateName = process.env.STORYBOOK_TEMPLATE_NAME || '';

test.describe('addon-actions', () => {
test('should trigger an action', async ({ page }) => {
// eslint-disable-next-line jest/no-disabled-tests
test.skip(
// eslint-disable-next-line jest/valid-title
templateName.includes('svelte') && templateName.includes('prerelease'),
'Svelte 5 prerelase does not support automatic actions with our current example components yet'
);
await page.goto(storybookUrl);
const sbPage = new SbPage(page);
sbPage.waitUntilLoaded();
Expand Down
6 changes: 3 additions & 3 deletions code/frameworks/svelte-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@
"@storybook/svelte": "workspace:*",
"@sveltejs/vite-plugin-svelte": "^2.4.2",
"magic-string": "^0.30.0",
"svelte-preprocess": "^5.0.4",
"svelte-preprocess": "^5.1.1",
"sveltedoc-parser": "^4.2.1",
"ts-dedent": "^2.2.0"
},
"devDependencies": {
"@types/node": "^18.0.0",
"svelte": "^4.0.0",
"svelte": "^5.0.0-next.16",
"typescript": "^5.3.2",
"vite": "^4.0.0"
},
"peerDependencies": {
"svelte": "^3.0.0 || ^4.0.0",
"svelte": "^4.0.0 || ^5.0.0-next.16",
"vite": "^3.0.0 || ^4.0.0 || ^5.0.0"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion code/frameworks/svelte-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},
"peerDependencies": {
"@babel/core": "*",
"svelte": "^3.48.0 || ^4.0.0",
"svelte": "^4.0.0 || ^5.0.0-next.16",
"svelte-loader": "*"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion code/frameworks/sveltekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"vite": "^4.0.0"
},
"peerDependencies": {
"svelte": "^3.0.0 || ^4.0.0",
"svelte": "^4.0.0 || ^5.0.0-next.16",
"vite": "^4.0.0"
},
"engines": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<script lang="ts">
/**
* @component Button TypeScript
* @wrapper
*/
import { global as globalThis } from '@storybook/global';
// @ts-ignore
const Button = globalThis.Components?.Button;

/**
* Rounds the button
*/
export let primary: boolean = false;

/**
* Displays the count
*/
export let count: number = 0;

/**
* Button text
* @slot
*/
export let text: string = 'You clicked';

function handleClick(_event: MouseEvent) {
count += 1;
}
</script>

<h1>Button TypeScript</h1>

<Button {primary} on:click on:click={handleClick} label="{text}: {count}" />

<p>A little text to show this is a view.</p>
<p>If we need to test components in a Svelte environment, for instance to test slot behaviour,</p>
<p>then wrapping the component up in a view</p>
<p>made just for the story is the simplest way to achieve this.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
import { enhance } from '$app/forms';
</script>

<form use:enhance>
<button>enhance</button>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<ul>
<li><a href="/basic-href">Link to <code>/basic-href</code></a></li>
<li>
<a href="/deep/nested/link?with=true&multiple-params=200#and-an-id"
>Link to <code>/deep/nested/link?with=true&multiple-params=200#and-an-id</code></a
>
</li>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script>
import { goto, invalidate, invalidateAll, afterNavigate } from '$app/navigation';

export let afterNavigateFn;

afterNavigate(afterNavigateFn);
</script>

<button
on:click={() => {
goto('/storybook-goto');
}}>goto</button
>

<button
on:click={() => {
invalidate('/storybook-invalidate');
}}>invalidate</button
>

<button
on:click={() => {
invalidateAll();
}}>invalidateAll</button
>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script>
import { page, navigating, updated, getStores } from '$app/stores';

let { navigating: navigatingStore, page: pageStore, updated: updatedStore } = getStores();

updated.check();
</script>

<p>Directly importing</p>
<pre>{JSON.stringify($page, null, 2)}</pre>
<pre>{JSON.stringify($navigating, null, 2)}</pre>
<pre>{JSON.stringify($updated, null, 2)}</pre>

<p>With getStores</p>
<pre>{JSON.stringify($pageStore, null, 2)}</pre>
<pre>{JSON.stringify($navigatingStore, null, 2)}</pre>
<pre>{JSON.stringify($updatedStore, null, 2)}</pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { expect, fn, within } from '@storybook/test';
import Forms from './Forms.svelte';

export default {
title: 'stories/sveltekit/modules/forms',
component: Forms,
tags: ['autodocs'],
};

const enhance = fn();

export const Enhance = {
async play({ canvasElement }) {
const canvas = within(canvasElement);
const button = canvas.getByText('enhance');
button.click();
expect(enhance).toHaveBeenCalled();
},
parameters: {
sveltekit_experimental: {
forms: {
enhance,
},
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { expect, fn, within } from '@storybook/test';
import Hrefs from './Hrefs.svelte';

export default {
title: 'stories/sveltekit/modules/hrefs',
component: Hrefs,
tags: ['autodocs'],
};

export const DefaultActions = {
async play({ canvasElement }) {
const canvas = within(canvasElement);
// eslint-disable-next-line no-undef
const initialUrl = window.location.toString();

const basicHref = canvas.getByText('/basic-href');
basicHref.click();

const complexHref = canvas.getByText(
'/deep/nested/link?with=true&multiple-params=200#and-an-id'
);
complexHref.click();

// eslint-disable-next-line no-undef
const finalUrl = window.location.toString();
expect(finalUrl).toBe(initialUrl);
},
};

const basicStringMatch = fn();
const noMatch = fn();
const exactStringMatch = fn();
const regexMatch = fn();

export const Callbacks = {
parameters: {
sveltekit_experimental: {
hrefs: {
'/basic-href': basicStringMatch,
'/basic': noMatch,
'/deep/nested/link?with=true&multiple-params=200#and-an-id': exactStringMatch,
'nested/link\\?with': { callback: regexMatch, asRegex: true },
},
},
},
play: async (ctx) => {
await DefaultActions.play(ctx);
expect(basicStringMatch).toHaveBeenCalledTimes(1);
expect(noMatch).not.toHaveBeenCalled();
expect(exactStringMatch).toHaveBeenCalledTimes(1);
expect(regexMatch).toHaveBeenCalledTimes(1);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { expect, fn, within } from '@storybook/test';
import Navigation from './Navigation.svelte';

export default {
title: 'stories/sveltekit/modules/navigation',
component: Navigation,
tags: ['autodocs'],
};

const goto = fn();

export const Goto = {
async play({ canvasElement }) {
const canvas = within(canvasElement);
const button = canvas.getByText('goto');
button.click();
expect(goto).toHaveBeenCalledWith('/storybook-goto');
},
parameters: {
sveltekit_experimental: {
navigation: {
goto,
},
},
},
};

export const DefaultActions = {};

const invalidate = fn();

export const Invalidate = {
async play({ canvasElement }) {
const canvas = within(canvasElement);
const button = canvas.getByText('invalidate', { exact: true });
button.click();
expect(invalidate).toHaveBeenCalledWith('/storybook-invalidate');
},
parameters: {
sveltekit_experimental: {
navigation: {
invalidate,
},
},
},
};

const invalidateAll = fn();

export const InvalidateAll = {
async play({ canvasElement }) {
const canvas = within(canvasElement);
const button = canvas.getByText('invalidateAll');
button.click();
expect(invalidateAll).toHaveBeenCalledWith();
},
parameters: {
sveltekit_experimental: {
navigation: {
invalidateAll,
},
},
},
};

const afterNavigateFn = fn();

export const AfterNavigate = {
async play() {
expect(afterNavigateFn).toHaveBeenCalledWith({ test: 'passed' });
},
args: {
afterNavigateFn,
},
parameters: {
sveltekit_experimental: {
navigation: {
afterNavigate: {
test: 'passed',
},
},
},
},
};
Loading
Loading