Skip to content

Commit a6f2138

Browse files
committed
fix: split async test into separate project, adapt tests when running in baseline svelte version
1 parent d1fc2d3 commit a6f2138

File tree

25 files changed

+317
-65
lines changed

25 files changed

+317
-65
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595
# future test with rolldown-vite
9696
- node: 24
9797
os: ubuntu-latest
98-
vite: 'rolldown-vite',
98+
vite: 'rolldown-vite'
9999
svelte: 'current'
100100
steps:
101101
- uses: actions/checkout@v4

packages/e2e-tests/_test_dependencies/svelte-api-only/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
},
1616
"type": "module",
1717
"dependencies": {
18-
"svelte": "^5.36.0"
18+
"svelte": "^5.0.0"
1919
}
2020
}
Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,48 @@
1-
import { browserLogs, findAssetFile, getColor, getEl, getText, isBuild } from '~utils';
1+
import {
2+
browserLogs,
3+
findAssetFile,
4+
getColor,
5+
getEl,
6+
getText,
7+
IS_SVELTE_BASELINE,
8+
isBuild
9+
} from '~utils';
210
import { expect } from 'vitest';
311

4-
test('should not have failed requests', async () => {
5-
browserLogs.forEach((msg) => {
6-
expect(msg).not.toMatch('404');
12+
// support for treeshaking css was added after 5.0.0
13+
describe.skipIf(IS_SVELTE_BASELINE)('css-treeshake', () => {
14+
test('should not have failed requests', async () => {
15+
browserLogs.forEach((msg) => {
16+
expect(msg).not.toMatch('404');
17+
});
718
});
8-
});
9-
10-
test('should apply css from used components', async () => {
11-
expect(await getText('#app')).toBe('App');
12-
expect(await getColor('#app')).toBe('blue');
13-
expect(await getText('#a')).toBe('A');
14-
expect(await getColor('#a')).toBe('red');
15-
});
16-
17-
test('should apply css from unused components that contain global styles', async () => {
18-
expect(await getEl('head style[src]'));
19-
expect(await getColor('#test')).toBe('green'); // from B.svelte
20-
});
2119

22-
test('should not render unused components', async () => {
23-
expect(await getEl('#b')).toBeNull();
24-
expect(await getEl('#c')).toBeNull();
25-
});
20+
test('should apply css from used components', async () => {
21+
expect(await getText('#app')).toBe('App');
22+
expect(await getColor('#app')).toBe('blue');
23+
expect(await getText('#a')).toBe('A');
24+
expect(await getColor('#a')).toBe('red');
25+
});
2626

27-
if (isBuild) {
28-
test('should include unscoped global styles from unused components', async () => {
29-
const cssOutput = findAssetFile(/index-.*\.css/);
30-
expect(cssOutput).toContain('#test{color:green}'); // from B.svelte
27+
test('should apply css from unused components that contain global styles', async () => {
28+
expect(await getEl('head style[src]'));
29+
expect(await getColor('#test')).toBe('green'); // from B.svelte
3130
});
32-
test('should not include scoped styles from unused components', async () => {
33-
const cssOutput = findAssetFile(/index-.*\.css/);
34-
// from C.svelte
35-
expect(cssOutput).not.toContain('.unused');
31+
32+
test('should not render unused components', async () => {
33+
expect(await getEl('#b')).toBeNull();
34+
expect(await getEl('#c')).toBeNull();
3635
});
37-
}
36+
37+
if (isBuild) {
38+
test('should include unscoped global styles from unused components', async () => {
39+
const cssOutput = findAssetFile(/index-.*\.css/);
40+
expect(cssOutput).toContain('#test{color:green}'); // from B.svelte
41+
});
42+
test('should not include scoped styles from unused components', async () => {
43+
const cssOutput = findAssetFile(/index-.*\.css/);
44+
// from C.svelte
45+
expect(cssOutput).not.toContain('.unused');
46+
});
47+
}
48+
});

packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-5/raw.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
<script lang="ts">
2-
export let name: string;
3-
let clicks = 0;
2+
interface Props {
3+
name: string;
4+
}
5+
6+
let { name }: Props = $props();
7+
let clicks = $state(0);
48
</script>
59

610
<button
7-
on:click={() => {
11+
onclick={() => {
812
clicks++;
913
}}>{name} clicks: {clicks}</button
1014
>

packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-5/ssr-raw.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
<script lang="ts">
2-
export let name: string;
3-
let clicks = 0;
2+
interface Props {
3+
name: string;
4+
}
5+
6+
let { name }: Props = $props();
7+
let clicks = $state(0);
48
</script>
59

610
<button
7-
on:click={() => {
11+
onclick={() => {
812
clicks++;
913
}}>{name} clicks: {clicks}</button
1014
>

packages/e2e-tests/import-queries/src/Dummy.svelte

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
<script lang="ts">
2-
export let name: string;
3-
let clicks = 0;
2+
interface Props {
3+
name: string;
4+
}
5+
6+
let { name }: Props = $props();
7+
let clicks = $state(0);
48
</script>
59

610
<button
7-
on:click={() => {
11+
onclick={() => {
812
clicks++;
913
}}>{name} clicks: {clicks}</button
1014
>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
node_modules
2+
3+
# Output
4+
.output
5+
.vercel
6+
.netlify
7+
.wrangler
8+
/.svelte-kit
9+
/build
10+
11+
# OS
12+
.DS_Store
13+
Thumbs.db
14+
15+
# Env
16+
.env
17+
.env.*
18+
!.env.example
19+
!.env.test
20+
21+
# Vite
22+
vite.config.js.timestamp-*
23+
vite.config.ts.timestamp-*
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# sv
2+
3+
Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).
4+
5+
## Creating a project
6+
7+
If you're seeing this, you've probably already done this step. Congrats!
8+
9+
```bash
10+
# create a new project in the current directory
11+
npx sv create
12+
13+
# create a new project in my-app
14+
npx sv create my-app
15+
```
16+
17+
## Developing
18+
19+
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
20+
21+
```bash
22+
npm run dev
23+
24+
# or start the server and open the app in a new browser tab
25+
npm run dev -- --open
26+
```
27+
28+
## Building
29+
30+
To create a production version of your app:
31+
32+
```bash
33+
npm run build
34+
```
35+
36+
You can preview the production build with `npm run preview`.
37+
38+
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { getText, IS_SVELTE_BASELINE, sleep } from '~utils';
3+
4+
describe.skipIf(IS_SVELTE_BASELINE)('kit-async', async () => {
5+
it('works', async () => {
6+
expect(await getText('h1')).toBe('Hello async world!');
7+
expect(await getText('span')).toBe('Wait for it ...');
8+
// TODO ideally this would wait for the actual async settled but that requires a new util
9+
await sleep(700); // the async derived resolves after 500ms
10+
expect(await getText('span')).toBe('foo');
11+
});
12+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "e2e-tests-kit-async",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite dev",
8+
"build": "vite build",
9+
"preview": "vite preview",
10+
"prepare": "svelte-kit sync || echo ''",
11+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
12+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
13+
},
14+
"devDependencies": {
15+
"@sveltejs/adapter-node": "^5.2.12",
16+
"@sveltejs/kit": "^2.22.2",
17+
"@sveltejs/vite-plugin-svelte": "workspace:^",
18+
"svelte": "^5.36.0",
19+
"svelte-check": "^4.0.0",
20+
"typescript": "^5.8.3",
21+
"vite": "^7.0.2"
22+
}
23+
}

0 commit comments

Comments
 (0)