Skip to content

Commit 13eddd1

Browse files
authored
Merge branch 'main' into fix-console-scroll
2 parents 8ff2154 + d382b43 commit 13eddd1

File tree

7 files changed

+57
-8
lines changed

7 files changed

+57
-8
lines changed

apps/svelte.dev/content/docs/kit/30-advanced/70-packaging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Setting the `sideEffects` field in `package.json` can help the bundler to be mor
140140
}
141141
```
142142

143-
> If the scripts in your library have side effects, ensure that you update the `sideEffects` field. All scripts are marked as side effect free by default in newly created projects. If a file with side effects is incorrectly marked as having no side effects, it can result in broken functionality.
143+
> [!NOTE] If the scripts in your library have side effects, ensure that you update the `sideEffects` field. All scripts are marked as side effect free by default in newly created projects. If a file with side effects is incorrectly marked as having no side effects, it can result in broken functionality.
144144
145145
If your package has files with side effects, you can specify them in an array:
146146

apps/svelte.dev/content/docs/svelte/07-misc/02-testing.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ export function logger(getValue) {
161161

162162
### Component testing
163163

164-
It is possible to test your components in isolation using Vitest.
164+
It is possible to test your components in isolation, which allows you to render them in a browser (real or simulated), simulate behavior, and make assertions, without spinning up your whole app.
165165

166-
> [!NOTE] Before writing component tests, think about whether you actually need to test the component, or if it's more about the logic _inside_ the component. If so, consider extracting out that logic to test it in isolation, without the overhead of a component
166+
> [!NOTE] Before writing component tests, think about whether you actually need to test the component, or if it's more about the logic _inside_ the component. If so, consider extracting out that logic to test it in isolation, without the overhead of a component.
167167
168168
To get started, install jsdom (a library that shims DOM APIs):
169169

@@ -247,6 +247,48 @@ test('Component', async () => {
247247

248248
When writing component tests that involve two-way bindings, context or snippet props, it's best to create a wrapper component for your specific test and interact with that. `@testing-library/svelte` contains some [examples](https://testing-library.com/docs/svelte-testing-library/example).
249249

250+
### Component testing with Storybook
251+
252+
[Storybook](https://storybook.js.org) is a tool for developing and documenting UI components, and it can also be used to test your components. They're run with Vitest's browser mode, which renders your components in a real browser for the most realistic testing environment.
253+
254+
To get started, first install Storybook ([using Svelte's CLI](/docs/cli/storybook)) in your project via `npx sv add storybook` and choose the recommended configuration that includes testing features. If you're already using Storybook, and for more information on Storybook's testing capabilities, follow the [Storybook testing docs](https://storybook.js.org/docs/writing-tests?renderer=svelte) to get started.
255+
256+
You can create stories for component variations and test interactions with the [play function](https://storybook.js.org/docs/writing-tests/interaction-testing?renderer=svelte#writing-interaction-tests), which allows you to simulate behavior and make assertions using the Testing Library and Vitest APIs. Here's an example of two stories that can be tested, one that renders an empty LoginForm component and one that simulates a user filling out the form:
257+
258+
```svelte
259+
/// file: LoginForm.stories.svelte
260+
<script module>
261+
import { defineMeta } from '@storybook/addon-svelte-csf';
262+
import { expect, fn } from 'storybook/test';
263+
264+
import LoginForm from './LoginForm.svelte';
265+
266+
const { Story } = defineMeta({
267+
component: LoginForm,
268+
args: {
269+
// Pass a mock function to the `onSubmit` prop
270+
onSubmit: fn(),
271+
}
272+
});
273+
</script>
274+
275+
<Story name="Empty Form" />
276+
277+
<Story
278+
name="Filled Form"
279+
play={async ({ args, canvas, userEvent }) => {
280+
// Simulate a user filling out the form
281+
await userEvent.type(canvas.getByTestId('email'), '[email protected]');
282+
await userEvent.type(canvas.getByTestId('password'), 'a-random-password');
283+
await userEvent.click(canvas.getByRole('button'));
284+
285+
// Run assertions
286+
await expect(args.onSubmit).toHaveBeenCalledTimes(1);
287+
await expect(canvas.getByText('You’re in!')).toBeInTheDocument();
288+
}}
289+
/>
290+
```
291+
250292
## E2E tests using Playwright
251293

252294
E2E (short for 'end to end') tests allow you to test your full application through the eyes of the user. This section uses [Playwright](https://playwright.dev/) as an example, but you can also use other solutions like [Cypress](https://www.cypress.io/) or [NightwatchJS](https://nightwatchjs.org/).

apps/svelte.dev/content/tutorial/04-advanced-sveltekit/03-link-options/01-preload/+assets/app-a/src/routes/+layout.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
if (navigating.to) {
1212
start = Date.now();
1313
end = null;
14-
previous = navigating;
14+
previous = { ...navigating };
1515
} else {
1616
end = Date.now();
1717
}

apps/svelte.dev/content/tutorial/04-advanced-sveltekit/03-link-options/01-preload/+assets/app-b/src/routes/+layout.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
if (navigating.to) {
1212
start = Date.now();
1313
end = null;
14-
previous = navigating;
14+
previous = { ...navigating };
1515
} else {
1616
end = Date.now();
1717
}

apps/svelte.dev/src/routes/(authed)/playground/[id]/gzip.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export async function compress_and_encode_text(input) {
66
const { done, value } = await reader.read();
77
if (done) {
88
reader.releaseLock();
9-
return btoa(buffer).replaceAll('+', '-').replaceAll('/', '_');
9+
// Some sites like discord don't like it when links end with =
10+
return btoa(buffer).replaceAll('+', '-').replaceAll('/', '_').replace(/=+$/, '');
1011
} else {
1112
for (let i = 0; i < value.length; i++) {
1213
// decoding as utf-8 will make btoa reject the string

packages/site-kit/src/lib/codemirror/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@ const logic_block_snippets = [
2525
label: '#await :then',
2626
type: 'keyword'
2727
}),
28-
snippetCompletion('#key ${}}\n\n{/key', { label: '#key', type: 'keyword' })
28+
snippetCompletion('#key ${}}\n\n{/key', { label: '#key', type: 'keyword' }),
29+
snippetCompletion('#snippet ${}()}\n\n{/snippet', {
30+
label: '#snippet',
31+
type: 'keyword'
32+
})
2933
];
3034

3135
const special_tag_snippets = [
3236
snippetCompletion('@html ${}', { label: '@html', type: 'keyword' }),
3337
snippetCompletion('@debug ${}', { label: '@debug', type: 'keyword' }),
34-
snippetCompletion('@const ${}', { label: '@const', type: 'keyword' })
38+
snippetCompletion('@const ${}', { label: '@const', type: 'keyword' }),
39+
snippetCompletion('@render ${}()', { label: '@render', type: 'keyword' })
3540
];
3641

3742
/**

packages/site-kit/src/lib/search/SearchBox.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ It appears when the user clicks on the `Search` component or presses the corresp
408408
.results {
409409
overflow: auto;
410410
overscroll-behavior-y: none;
411+
scrollbar-color: var(--sk-scrollbar) var(--sk-bg-2);
411412
}
412413
413414
.results-container {

0 commit comments

Comments
 (0)