Skip to content

Commit bd8262d

Browse files
chargomeclaude
andauthored
test(sveltekit): Add SvelteKit 3 Cloudflare Workers E2E app (#23294)
Adds `sveltekit-3-cloudflare-workers` (Kit 3, adapter-cloudflare 8) — our first SvelteKit-on-Workers app; the existing Cloudflare app is Pages on adapter 5. Runs `wrangler dev` against the built worker rather than `vite dev`, because the adapter's dev proxy still sets the legacy `context` alias and would hide the rename this guards against. Marked optional since Kit 3 and the adapter are prereleases. --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent f1cf43b commit bd8262d

19 files changed

Lines changed: 258 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.DS_Store
2+
node_modules
3+
/build
4+
/.svelte-kit
5+
/package
6+
.env
7+
.env.*
8+
!.env.example
9+
vite.config.js.timestamp-*
10+
vite.config.ts.timestamp-*
11+
12+
# Cloudflare
13+
.wrangler
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "sveltekit-3-cloudflare-workers",
3+
"version": "0.0.1",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite dev",
8+
"build": "vite build",
9+
"preview": "wrangler dev --port 4173",
10+
"proxy": "node start-event-proxy.mjs",
11+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
12+
"test:e2e": "playwright test",
13+
"test:build": "pnpm install && pnpm build",
14+
"test:assert": "pnpm test:e2e"
15+
},
16+
"dependencies": {
17+
"@sentry/sveltekit": "file:../../packed/sentry-sveltekit-packed.tgz"
18+
},
19+
"devDependencies": {
20+
"@playwright/test": "~1.56.0",
21+
"@sentry-internal/test-utils": "link:../../../test-utils",
22+
"@sveltejs/adapter-cloudflare": "next",
23+
"@sveltejs/kit": "next",
24+
"@sveltejs/vite-plugin-svelte": "^7.1.2",
25+
"cookie": "^2.0.1",
26+
"svelte": "^5.48.0",
27+
"typescript": "^6.0.0",
28+
"vite": "^8.0.0",
29+
"wrangler": "^4.118.0"
30+
},
31+
"volta": {
32+
"node": "22.20.0",
33+
"extends": "../../package.json"
34+
},
35+
"sentryTest": {
36+
"optional": true
37+
}
38+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { getPlaywrightConfig } from '@sentry-internal/test-utils';
2+
3+
// The bug this app guards against only reproduces against the *built* Worker:
4+
// `@sveltejs/adapter-cloudflare`'s dev platform proxy still sets the legacy
5+
// `platform.context` alias, while the emitted worker only sets `platform.ctx`.
6+
// So we serve the build output with `wrangler dev` rather than running `vite dev`.
7+
const config = getPlaywrightConfig({
8+
startCommand: 'pnpm preview',
9+
port: 4173,
10+
});
11+
12+
export default config;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// See https://svelte.dev/docs/kit/types#app.d.ts
2+
// `App.Platform` (including `platform.ctx`) is declared by `@sveltejs/adapter-cloudflare`.
3+
declare global {
4+
namespace App {
5+
// interface Error {}
6+
// interface Locals {}
7+
// interface PageData {}
8+
// interface PageState {}
9+
}
10+
}
11+
12+
export {};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
6+
<meta name="viewport" content="width=device-width" />
7+
%sveltekit.head%
8+
</head>
9+
<body data-sveltekit-preload-data="off">
10+
<div style="display: contents">%sveltekit.body%</div>
11+
</body>
12+
</html>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineEnvVars } from '@sveltejs/kit/env';
2+
3+
// SvelteKit 3 makes "explicit environment variables" the default and removes the
4+
// legacy `$env/*` virtual modules. Declared vars are imported from `$app/env/private`
5+
// (server only) and `$app/env/public` (client-safe).
6+
export const variables = defineEnvVars({
7+
// `static: true` inlines the value at build time. On Cloudflare there is no
8+
// `process.env` at runtime, so a dynamic var would never reach the SDK.
9+
E2E_TEST_DSN: { static: true },
10+
PUBLIC_E2E_TEST_DSN: { public: true, static: true },
11+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { PUBLIC_E2E_TEST_DSN } from '$app/env/public';
2+
import * as Sentry from '@sentry/sveltekit';
3+
4+
Sentry.init({
5+
environment: 'qa',
6+
dsn: PUBLIC_E2E_TEST_DSN,
7+
tunnel: 'http://localhost:3031/', // proxy server
8+
tracesSampleRate: 1.0,
9+
});
10+
11+
export const handleError = Sentry.handleErrorWithSentry();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { E2E_TEST_DSN } from '$app/env/private';
2+
import { handleErrorWithSentry, initCloudflareSentryHandle, sentryHandle } from '@sentry/sveltekit';
3+
import { sequence } from '@sveltejs/kit/hooks';
4+
5+
// not logging anything to console to avoid noise in the test output
6+
export const handleError = handleErrorWithSentry(() => {});
7+
8+
export const handle = sequence(
9+
initCloudflareSentryHandle({
10+
environment: 'qa', // dynamic sampling bias to keep spans
11+
dsn: E2E_TEST_DSN,
12+
debug: !!process.env.DEBUG,
13+
tunnel: 'http://localhost:3031/', // proxy server
14+
tracesSampleRate: 1.0,
15+
}),
16+
sentryHandle(),
17+
);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { PageServerLoad } from './$types';
2+
3+
// Opt the index route out of prerendering so it is served by the Worker and therefore
4+
// exercises `initCloudflareSentryHandle`.
5+
export const prerender = false;
6+
7+
export const load: PageServerLoad = async function load() {
8+
return { message: 'From server load function.' };
9+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>SvelteKit 3 on Cloudflare Workers</h1>

0 commit comments

Comments
 (0)