Skip to content

Commit 2f51a3a

Browse files
authored
fix(test): improve stability by removing a log and vite cache (#894)
* fix(test): improve stability by removing an unexpected log and ensuring that vite cache isn't persisted * fix: remove log use * fix: wait 500ms after vite connected * increase timeout in ci * fix: remove workaround to mount test apps with svelte 4 or 5 * chore(docs): improve changelog about removal of svelte5 warning
1 parent 49324db commit 2f51a3a

File tree

20 files changed

+127
-188
lines changed

20 files changed

+127
-188
lines changed

.changeset/popular-islands-remain.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': patch
3+
---
4+
5+
Remove log about experimental status of Svelte 5. Note that breaking changes can still occur while vite-plugin-svelte 4 is in prerelease mode
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
import App from './App.svelte';
2-
3-
if (App.toString().startsWith('class ')) {
4-
new App({ target: document.body });
5-
} else {
6-
import('svelte').then(({ mount }) => mount(App, { target: document.body }));
7-
}
2+
import { mount } from 'svelte';
3+
mount(App, { target: document.body });
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
import App from './App.svelte';
2-
3-
if (App.toString().startsWith('class ')) {
4-
new App({ target: document.body });
5-
} else {
6-
import('svelte').then(({ mount }) => mount(App, { target: document.body }));
7-
}
2+
import { mount } from 'svelte';
3+
mount(App, { target: document.body });
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
import App from './App.svelte';
2-
3-
if (App.toString().startsWith('class ')) {
4-
new App({ target: document.body });
5-
} else {
6-
import('svelte').then(({ mount }) => mount(App, { target: document.body }));
7-
}
2+
import { mount } from 'svelte';
3+
mount(App, { target: document.body });
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
import App from './App.svelte';
2-
3-
if (App.toString().startsWith('class ')) {
4-
new App({ target: document.body });
5-
} else {
6-
import('svelte').then(({ mount }) => mount(App, { target: document.body }));
7-
}
2+
import { mount } from 'svelte';
3+
mount(App, { target: document.body });
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
import App from './App.svelte';
2-
3-
if (App.toString().startsWith('class ')) {
4-
new App({ target: document.body });
5-
} else {
6-
import('svelte').then(({ mount }) => mount(App, { target: document.body }));
7-
}
2+
import { mount } from 'svelte';
3+
mount(App, { target: document.body });

packages/e2e-tests/env/src/main.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
import App from './App.svelte';
2-
3-
if (App.toString().startsWith('class ')) {
4-
new App({ target: document.body });
5-
} else {
6-
import('svelte').then(({ mount }) => mount(App, { target: document.body }));
7-
}
2+
import { mount } from 'svelte';
3+
mount(App, { target: document.body });

packages/e2e-tests/hmr/src/index.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
import App from './App.svelte';
2-
3-
if (App.toString().startsWith('class ')) {
4-
new App({ target: document.body });
5-
} else {
6-
import('svelte').then(({ mount }) => mount(App, { target: document.body }));
7-
}
2+
import { mount } from 'svelte';
3+
mount(App, { target: document.body });
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
import App from './App.svelte';
2-
3-
if (App.toString().startsWith('class ')) {
4-
new App({ target: document.body });
5-
} else {
6-
import('svelte').then(({ mount }) => mount(App, { target: document.body }));
7-
}
2+
import { mount } from 'svelte';
3+
mount(App, { target: document.body });
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
import App from './App.svelte';
2-
3-
if (App.toString().startsWith('class ')) {
4-
new App({ target: document.getElementById('app') });
5-
} else {
6-
import('svelte').then(({ mount }) => mount(App, { target: document.getElementById('app') }));
7-
}
2+
import { mount } from 'svelte';
3+
mount(App, { target: document.body });
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
import App from './App.svelte';
2-
3-
if (App.toString().startsWith('class ')) {
4-
new App({ target: document.body });
5-
} else {
6-
import('svelte').then(({ mount }) => mount(App, { target: document.body }));
7-
}
2+
import { mount } from 'svelte';
3+
mount(App, { target: document.body });
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
import App from './App.svelte';
2-
3-
if (App.toString().startsWith('class ')) {
4-
new App({ target: document.body });
5-
} else {
6-
import('svelte').then(({ mount }) => mount(App, { target: document.body }));
7-
}
2+
import { mount } from 'svelte';
3+
mount(App, { target: document.body });
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import App from './App.svelte';
2-
32
import { Hello } from './types.js';
3+
import { mount } from 'svelte';
44

55
const hello: Hello = 'Hello';
66

@@ -10,8 +10,5 @@ const options = {
1010
hello
1111
}
1212
};
13-
if (App.toString().startsWith('class ')) {
14-
new App(options);
15-
} else {
16-
import('svelte').then(({ mount }) => mount(App, options));
17-
}
13+
14+
mount(App, options);
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
import App from './App.svelte';
2-
3-
if (App.toString().startsWith('class ')) {
4-
new App({ target: document.body });
5-
} else {
6-
import('svelte').then(({ mount }) => mount(App, { target: document.body }));
7-
}
2+
import { mount } from 'svelte';
3+
mount(App, { target: document.body });
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
import App from './App.svelte';
2-
3-
if (App.toString().startsWith('class ')) {
4-
new App({ target: document.getElementById('app') });
5-
} else {
6-
import('svelte').then(({ mount }) => mount(App, { target: document.getElementById('app') }));
7-
}
2+
import { mount } from 'svelte';
3+
mount(App, { target: document.body });
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
import type { Test } from './lib.js';
22
import { test } from './lib.js';
33
import App from './App.svelte';
4+
import { mount } from 'svelte';
45

56
main();
67

78
export function main({ arg = true }: Test = {}): void {
89
if (arg && test()) {
9-
if (App.toString().startsWith('class ')) {
10-
new App({ target: document.body });
11-
} else {
12-
import('svelte').then(({ mount }) => {
13-
mount(App, { target: document.body });
14-
});
15-
}
10+
mount(App, { target: document.body });
1611
}
1712
}

packages/e2e-tests/vitestSetup.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ beforeAll(
137137
if (!stat.isSymbolicLink()) {
138138
console.error(`failed to symlink ${e2e_tests_node_modules} to ${temp_node_modules}`);
139139
}
140+
// ensure there is no leftover vite cache
141+
const tempViteCache = path.join(temp_node_modules, '.vite');
142+
if (fs.existsSync(tempViteCache)) {
143+
await fs.rm(tempViteCache, { force: true, recursive: true });
144+
}
145+
140146
await fs.mkdir(path.join(tempDir, 'logs'));
141147
const customServerScript = path.resolve(path.dirname(testPath), 'serve.js');
142148
const defaultServerScript = path.resolve(e2eTestsRoot, 'e2e-server.js');
@@ -215,7 +221,7 @@ async function goToUrlAndWaitForViteWSConnect(page: Page, url: string) {
215221
return Promise.all([page.goto(url), waitForViteConnect(page, 15000)]);
216222
}
217223

218-
export async function waitForViteConnect(page: Page, timeoutMS = 5000) {
224+
export async function waitForViteConnect(page: Page, timeoutMS = 10000) {
219225
if (isBuild) {
220226
return Promise.resolve(); // no vite websocket on build
221227
}

packages/vite-plugin-svelte/src/index.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'node:fs';
22
import { svelteInspector } from '@sveltejs/vite-plugin-svelte-inspector';
33
import { handleHotUpdate } from './handle-hot-update.js';
4-
import { log, logCompilerWarnings, logSvelte5Warning } from './utils/log.js';
4+
import { log, logCompilerWarnings } from './utils/log.js';
55
import { createCompileSvelte } from './utils/compile.js';
66
import { buildIdParser, buildModuleIdParser } from './utils/id.js';
77
import {
@@ -23,9 +23,6 @@ import * as svelteCompiler from 'svelte/compiler';
2323
* @returns {import('vite').Plugin[]}
2424
*/
2525
export function svelte(inlineOptions) {
26-
// TODO remove for v-p-s 4.0.0
27-
logSvelte5Warning();
28-
2926
if (process.env.DEBUG != null) {
3027
log.setLevel('debug');
3128
}

packages/vite-plugin-svelte/src/utils/log.js

-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable no-console */
22
import { cyan, red, yellow } from 'kleur/colors';
33
import debug from 'debug';
4-
import { VERSION } from 'svelte/compiler';
54

65
/** @type {import('../types/log.d.ts').LogLevel[]} */
76
const levels = ['debug', 'info', 'warn', 'error', 'silent'];
@@ -260,11 +259,3 @@ export function buildExtendedLogMessage(w) {
260259
export function isDebugNamespaceEnabled(namespace) {
261260
return debug.enabled(`${prefix}:${namespace}`);
262261
}
263-
264-
export function logSvelte5Warning() {
265-
const notice = `You are using Svelte ${VERSION}. Svelte 5 support is experimental, breaking changes can occur in any release until this notice is removed.`;
266-
const wip = ['svelte-inspector: loaded but requires additional metadata to work'];
267-
if (wip.length > 0) {
268-
log.warn(`${notice}\nwork in progress:\n - ${wip.join('\n - ')}\n`);
269-
}
270-
}

0 commit comments

Comments
 (0)