Skip to content

Commit 7d1fd9e

Browse files
committed
test(e2e): Add tests to SvelteKit 2.x test application
1 parent 6173846 commit 7d1fd9e

File tree

27 files changed

+625
-80
lines changed

27 files changed

+625
-80
lines changed

packages/e2e-tests/test-applications/sveltekit-2/event-proxy-server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ async function registerCallbackServerPort(serverName: string, port: string): Pro
247247
await writeFile(tmpFilePath, port, { encoding: 'utf8' });
248248
}
249249

250-
async function retrieveCallbackServerPort(serverName: string): Promise<string> {
250+
function retrieveCallbackServerPort(serverName: string): Promise<string> {
251251
const tmpFilePath = path.join(os.tmpdir(), `${TEMP_FILE_PREFIX}${serverName}`);
252-
return await readFile(tmpFilePath, 'utf8');
252+
return readFile(tmpFilePath, 'utf8');
253253
}

packages/e2e-tests/test-applications/sveltekit-2/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
1111
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
1212
"test:prod": "TEST_ENV=production playwright test",
13-
"test:dev": "TEST_ENV=development playwright test",
1413
"test:build": "pnpm install && pnpm build",
15-
"test:assert": "pnpm -v"
14+
"test:assert": "pnpm test:prod"
1615
},
1716
"dependencies": {
1817
"@sentry/sveltekit": "latest || *"
1918
},
2019
"devDependencies": {
21-
"@playwright/test": "^1.27.1",
20+
"@playwright/test": "^1.36.2",
2221
"@sentry/types": "latest || *",
2322
"@sentry/utils": "latest || *",
2423
"@sveltejs/adapter-auto": "^3.0.0",

packages/e2e-tests/test-applications/sveltekit-2/playwright.config.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
import type { PlaywrightTestConfig } from '@playwright/test';
2-
import { devices } from '@playwright/test';
1+
import type { PlaywrightTestConfig } from "@playwright/test";
2+
import { devices } from "@playwright/test";
3+
4+
// Fix urls not resolving to localhost on Node v17+
5+
// See: https://github.com/axios/axios/issues/3821#issuecomment-1413727575
6+
import { setDefaultResultOrder } from "dns";
7+
setDefaultResultOrder("ipv4first");
38

49
const testEnv = process.env.TEST_ENV;
510

611
if (!testEnv) {
7-
throw new Error('No test env defined');
12+
throw new Error("No test env defined");
813
}
914

10-
const port = 3030;
15+
const svelteKitPort = 3030;
16+
const eventProxyPort = 3031;
1117

1218
/**
1319
* See https://playwright.dev/docs/test-configuration.
1420
*/
1521
const config: PlaywrightTestConfig = {
16-
testDir: './test',
22+
testDir: "./test",
1723
/* Maximum time one test can run for. */
1824
timeout: 150_000,
1925
expect: {
@@ -28,42 +34,44 @@ const config: PlaywrightTestConfig = {
2834
/* Fail the build on CI if you accidentally left test.only in the source code. */
2935
forbidOnly: !!process.env.CI,
3036
/* `next dev` is incredibly buggy with the app dir */
31-
retries: testEnv === 'development' ? 3 : 0,
37+
retries: testEnv === "development" ? 3 : 0,
3238
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
33-
reporter: 'list',
39+
reporter: "list",
3440
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
3541
use: {
3642
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
3743
actionTimeout: 0,
3844
/* Base URL to use in actions like `await page.goto('/')`. */
39-
baseURL: `http://localhost:${port}`,
45+
baseURL: `http://localhost:${svelteKitPort}`,
4046

4147
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
42-
trace: 'on-first-retry',
48+
trace: "on-first-retry",
4349
},
4450

4551
/* Configure projects for major browsers */
4652
projects: [
4753
{
48-
name: 'chromium',
54+
name: "chromium",
4955
use: {
50-
...devices['Desktop Chrome'],
56+
...devices["Desktop Chrome"],
5157
},
5258
},
5359
],
5460

5561
/* Run your local dev server before starting the tests */
5662
webServer: [
5763
{
58-
command: 'pnpm ts-node --esm start-event-proxy.ts',
59-
port: 3031,
64+
command: "pnpm ts-node-script start-event-proxy.ts",
65+
port: eventProxyPort,
66+
reuseExistingServer: false,
6067
},
6168
{
6269
command:
63-
testEnv === 'development'
64-
? `pnpm wait-port ${port} && pnpm dev --port ${port}`
65-
: `pnpm wait-port ${port} && pnpm preview --port ${port}`,
66-
port,
70+
testEnv === "development"
71+
? `pnpm wait-port ${eventProxyPort} && pnpm dev --port ${svelteKitPort}`
72+
: `pnpm wait-port ${eventProxyPort} && pnpm preview --port ${svelteKitPort}`,
73+
port: svelteKitPort,
74+
reuseExistingServer: false,
6775
},
6876
],
6977
};
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
import { E2E_TEST_DSN } from '$env/static/private';
2-
import * as Sentry from '@sentry/sveltekit';
1+
import { E2E_TEST_DSN } from "$env/static/private";
2+
import * as Sentry from "@sentry/sveltekit";
33

44
Sentry.init({
5-
environment: 'qa', // dynamic sampling bias to keep transactions
5+
environment: "qa", // dynamic sampling bias to keep transactions
66
dsn: E2E_TEST_DSN,
77
debug: true,
88
tunnel: `http://localhost:3031/`, // proxy server
99
tracesSampleRate: 1.0,
1010
});
1111

12-
const myErrorHandler = ({ error, event }: any) => {
13-
console.error('An error occurred on the server side:', error, event);
14-
};
15-
16-
export const handleError = Sentry.handleErrorWithSentry(myErrorHandler);
12+
// not logging anything to console to avoid noise in the test output
13+
export const handleError = Sentry.handleErrorWithSentry(() => {});
1714

1815
export const handle = Sentry.sentryHandle();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script lang="ts">
2+
import { onMount } from "svelte";
3+
4+
onMount(() => {
5+
// Indicate that the SvelteKit app was hydrated
6+
document.body.classList.add("hydrated");
7+
});
8+
</script>
9+
10+
<h1>Sveltekit E2E Test app</h1>
11+
<div data-sveltekit-preload-data="off">
12+
<slot></slot>
13+
</div>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
11
<h1>Welcome to SvelteKit</h1>
22
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>
3+
4+
<ul>
5+
<li>
6+
<a href="/client-error">Client error</a>
7+
</li>
8+
<li>
9+
<a href="/universal-load-error">Universal Load error</a>
10+
</li>
11+
<li>
12+
<a href="/server-load-error">Server Load error</a>
13+
</li>
14+
<li>
15+
<a href="/server-route-error">Server Route error</a>
16+
</li>
17+
<li>
18+
<a href="/users/123abc">Route with Params</a>
19+
</li>
20+
<li>
21+
<a href="/users">Route with Server Load</a>
22+
</li>
23+
<li>
24+
<a href="/universal-load-fetch">Route with fetch in universal load</a>
25+
</li>
26+
</ul>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const GET = () => {
2+
return new Response(JSON.stringify({ users: ["alice", "bob", "carol"] }));
3+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script lang="ts">
2+
function throwError() {
3+
throw new Error('Click Error');
4+
}
5+
</script>
6+
7+
<h1>Client error</h1>
8+
9+
<button on:click={throwError}>Throw error</button>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const load = async () => {
2+
throw new Error("Server Load Error");
3+
return {
4+
msg: "Hello World",
5+
};
6+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script lang="ts">
2+
export let data
3+
</script>
4+
5+
<h1>Server load error</h1>
6+
7+
<p>
8+
Message: {data.msg}
9+
</p>

0 commit comments

Comments
 (0)