Skip to content

Commit c625f67

Browse files
committed
fix: add testcase for failing dev reload
1 parent 81d0cf3 commit c625f67

File tree

9 files changed

+75
-24
lines changed

9 files changed

+75
-24
lines changed

packages/e2e-tests/build-watch/__tests__/build-watch.spec.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
sleep,
99
getColor,
1010
browserLogs,
11-
e2eServer
11+
e2eServer,
12+
getWatchErrors
1213
} from '~utils';
1314

1415
import * as vite from 'vite';
@@ -63,17 +64,6 @@ describe.runIf(isBuildWatch)('build-watch', () => {
6364
const updateApp = editFileAndWaitForBuildWatchComplete.bind(null, 'src/App.svelte');
6465
const updateStore = editFileAndWaitForBuildWatchComplete.bind(null, 'src/stores/hmr-stores.js');
6566

66-
const getWatchErrors = () =>
67-
isRolldownVite
68-
? e2eServer.logs.watch.err.filter(
69-
(m) =>
70-
![
71-
'Support for rolldown-vite in vite-plugin-svelte is experimental',
72-
'See https://github.com/sveltejs/vite-plugin-svelte/issues/1143'
73-
].some((s) => m.includes(s))
74-
)
75-
: e2eServer.logs.watch.err;
76-
7767
test('should have expected initial state', async () => {
7868
// initial state, both counters 0, both labels red
7969
expect(await getText('#hmr-test-1 .counter')).toBe('0');

packages/e2e-tests/kit-node/__tests__/kit.spec.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
fetchPageText,
1313
reloadPage,
1414
readFileContent,
15-
IS_SVELTE_BASELINE
15+
IS_SVELTE_BASELINE,
16+
getServerErrors
1617
} from '~utils';
1718

1819
import glob from 'tiny-glob';
@@ -95,6 +96,11 @@ describe('kit-node', () => {
9596
expect(browserLogs.some((x) => x === 'onMount dynamic imported isSSR: false')).toBe(true);
9697
});
9798

99+
it('should load dynamic import with css', async () => {
100+
expect(await getText('#dynamic-imported')).toBe("i'm blue");
101+
expect(await getColor('#css-transform')).toBe('blue');
102+
});
103+
98104
it('should respect transforms', async () => {
99105
expect(await getText('#js-transform')).toBe('Hello world');
100106
expect(await getColor('#css-transform')).toBe('red');
@@ -197,6 +203,12 @@ describe('kit-node', () => {
197203
expect(await getText('#hmr-test2')).toBe('bar');
198204
});
199205

206+
it('should not have errors on reload', async () => {
207+
expect(getServerErrors(), 'error log of `vite dev` is not empty before reload').toEqual([]);
208+
await reloadPage();
209+
expect(getServerErrors(), 'error log of `vite dev` is not empty after reload').toEqual([]);
210+
});
211+
200212
describe('child component update', () => {
201213
const updateChild = editFileAndWaitForHmrComplete.bind(null, 'src/lib/Child.svelte');
202214
const updateCounter = editFileAndWaitForHmrComplete.bind(null, 'src/lib/Counter.svelte');

packages/e2e-tests/kit-node/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
"@sveltejs/package": "^2.4.1",
1919
"@sveltejs/vite-plugin-svelte": "workspace:^",
2020
"e2e-test-dep-svelte-api-only": "file:../_test_dependencies/svelte-api-only",
21-
"e2e-test-dep-vite-plugins": "file:../_test_dependencies/vite-plugins",
2221
"e2e-test-dep-svelte-nested-workspace-devdep": "../_test_dependencies/svelte-nested-workspace-devdep",
22+
"e2e-test-dep-vite-plugins": "file:../_test_dependencies/vite-plugins",
23+
"sass": "^1.90.0",
2324
"svelte": "^5.38.0",
2425
"svelte-check": "^4.3.1",
2526
"svelte-i18n": "^4.0.1",

packages/e2e-tests/kit-node/src/routes/+page.svelte

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import Counter from '$lib/Counter.svelte';
55
import Child from '$lib/Child.svelte';
66
import { setSomeContext } from 'e2e-test-dep-svelte-api-only';
7+
import { browser } from '$app/environment';
8+
79
export let data = {};
810
$: load_status = data?.load_status ?? 'NOT_LOADED';
911
const jsTransform = '__JS_TRANSFORM_1__';
@@ -38,6 +40,13 @@
3840
<p id="js-transform">{jsTransform}</p>
3941
<!-- to be transformed into "hello-world" class -->
4042
<p id="css-transform">Hello world</p>
43+
{#if browser}
44+
{#await import('./DynamicImported.svelte').then((m) => m.default)}
45+
loading...
46+
{:then DynamicImported}
47+
<DynamicImported />
48+
{/await}
49+
{/if}
4150
</main>
4251
4352
<!-- HMR-TEMPLATE-INJECT -->
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div id="dynamic-imported">i'm blue</div>
2+
3+
<style lang="postcss">
4+
#dynamic-import {
5+
color: blue;
6+
}
7+
</style>

packages/e2e-tests/kit-node/svelte.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import node from '@sveltejs/adapter-node';
2+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
3+
24
/** @type {import('@sveltejs/kit').Config} */
35
const config = {
6+
preprocess: vitePreprocess(),
47
kit: {
58
adapter: node()
69
}

packages/e2e-tests/kit-node/vite.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ export default {
1919
optimizeDeps: {
2020
// eagerly include these, otherwise vite optimizer might interfere with restarting while the test is running
2121
include: ['svelte-i18n', 'e2e-test-dep-svelte-api-only']
22+
},
23+
css: {
24+
postcss: {
25+
plugins: [{ postcssPlugin: 'noop' }]
26+
}
2227
}
2328
};

packages/e2e-tests/testUtils.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import {
1818
waitForViteConnect
1919
} from './vitestSetup.js';
2020

21+
import * as vite from 'vite';
22+
//@ts-ignore
23+
const isRolldownVite = !!vite.rolldownVersion;
24+
2125
import { VERSION } from 'svelte/compiler';
2226

2327
export const IS_SVELTE_BASELINE = VERSION === '5.0.0';
@@ -354,3 +358,28 @@ export function readVitePrebundleMetadata() {
354358
}
355359
throw new Error('Unable to find vite prebundle metadata');
356360
}
361+
362+
export function getServerErrors() {
363+
return filterMessages(e2eServer.logs.server.err);
364+
}
365+
366+
export function getWatchErrors() {
367+
return filterMessages(e2eServer.logs.watch.err);
368+
}
369+
function filterMessages(arr) {
370+
if (arr.length === 0) {
371+
return arr;
372+
}
373+
const excludes = [];
374+
if (isRolldownVite) {
375+
excludes.push(
376+
'Support for rolldown-vite in vite-plugin-svelte is experimental',
377+
'See https://github.com/sveltejs/vite-plugin-svelte/issues/1143'
378+
);
379+
}
380+
if (excludes.length > 0) {
381+
return arr.filter((m) => excludes.some((e) => m.includes(e)));
382+
} else {
383+
return arr;
384+
}
385+
}

pnpm-lock.yaml

Lines changed: 5 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)