Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(svelte): Add Svelte 5 E2E test app (#11814)
In #11807 I added a SvelteKit+Svelte 5 E2E test. Let's also add a small Svelte 5 standalone/SPA app ensure we cover such apps as well.
- Loading branch information
Showing
21 changed files
with
521 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
dev-packages/e2e-tests/test-applications/svelte-5/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@sentry:registry=http://127.0.0.1:4873 | ||
@sentry-internal:registry=http://127.0.0.1:4873 |
62 changes: 62 additions & 0 deletions
62
dev-packages/e2e-tests/test-applications/svelte-5/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Svelte + TS + Vite | ||
|
||
This template should help get you started developing with Svelte and TypeScript in Vite. | ||
|
||
## Recommended IDE Setup | ||
|
||
[VS Code](https://code.visualstudio.com/) + | ||
[Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode). | ||
|
||
## Need an official Svelte framework? | ||
|
||
Check out [SvelteKit](https://github.com/sveltejs/kit#readme), which is also powered by Vite. Deploy anywhere with its | ||
serverless-first approach and adapt to various platforms, with out of the box support for TypeScript, SCSS, and Less, | ||
and easily-added support for mdsvex, GraphQL, PostCSS, Tailwind CSS, and more. | ||
|
||
## Technical considerations | ||
|
||
**Why use this over SvelteKit?** | ||
|
||
- It brings its own routing solution which might not be preferable for some users. | ||
- It is first and foremost a framework that just happens to use Vite under the hood, not a Vite app. | ||
|
||
This template contains as little as possible to get started with Vite + TypeScript + Svelte, while taking into account | ||
the developer experience with regards to HMR and intellisense. It demonstrates capabilities on par with the other | ||
`create-vite` templates and is a good starting point for beginners dipping their toes into a Vite + Svelte project. | ||
|
||
Should you later need the extended capabilities and extensibility provided by SvelteKit, the template has been | ||
structured similarly to SvelteKit so that it is easy to migrate. | ||
|
||
**Why `global.d.ts` instead of `compilerOptions.types` inside `jsconfig.json` or `tsconfig.json`?** | ||
|
||
Setting `compilerOptions.types` shuts out all other types not explicitly listed in the configuration. Using triple-slash | ||
references keeps the default TypeScript setting of accepting type information from the entire workspace, while also | ||
adding `svelte` and `vite/client` type information. | ||
|
||
**Why include `.vscode/extensions.json`?** | ||
|
||
Other templates indirectly recommend extensions via the README, but this file allows VS Code to prompt the user to | ||
install the recommended extension upon opening the project. | ||
|
||
**Why enable `allowJs` in the TS template?** | ||
|
||
While `allowJs: false` would indeed prevent the use of `.js` files in the project, it does not prevent the use of | ||
JavaScript syntax in `.svelte` files. In addition, it would force `checkJs: false`, bringing the worst of both worlds: | ||
not being able to guarantee the entire codebase is TypeScript, and also having worse typechecking for the existing | ||
JavaScript. In addition, there are valid use cases in which a mixed codebase may be relevant. | ||
|
||
**Why is HMR not preserving my local component state?** | ||
|
||
HMR state preservation comes with a number of gotchas! It has been disabled by default in both `svelte-hmr` and | ||
`@sveltejs/vite-plugin-svelte` due to its often surprising behavior. You can read the details | ||
[here](https://github.com/rixo/svelte-hmr#svelte-hmr). | ||
|
||
If you have state that's important to retain within a component, consider creating an external store which would not be | ||
replaced by HMR. | ||
|
||
```ts | ||
// store.ts | ||
// An extremely simple external store | ||
import { writable } from 'svelte/store'; | ||
export default writable(0); | ||
``` |
13 changes: 13 additions & 0 deletions
13
dev-packages/e2e-tests/test-applications/svelte-5/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + Svelte + TS</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/src/main.ts"></script> | ||
</body> | ||
</html> |
32 changes: 32 additions & 0 deletions
32
dev-packages/e2e-tests/test-applications/svelte-5/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "svelte-5", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"preview": "vite preview", | ||
"check": "svelte-check --tsconfig ./tsconfig.json", | ||
"test:prod": "TEST_ENV=production playwright test", | ||
"test:build": "pnpm install && npx playwright install && pnpm build", | ||
"test:assert": "pnpm test:prod" | ||
}, | ||
"devDependencies": { | ||
"@playwright/test": "^1.43.1", | ||
"@sentry-internal/event-proxy-server": "link:../../../event-proxy-server", | ||
"@sentry/types": "latest || *", | ||
"@sentry/utils": "latest || *", | ||
"@sveltejs/vite-plugin-svelte": "^3.0.2", | ||
"@tsconfig/svelte": "^5.0.2", | ||
"svelte": "^5.0.0-next.115", | ||
"svelte-check": "^3.6.7", | ||
"tslib": "^2.6.2", | ||
"typescript": "^5.2.2", | ||
"vite": "^5.2.0", | ||
"wait-port": "1.0.4" | ||
}, | ||
"dependencies": { | ||
"@sentry/svelte": "latest || *" | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
dev-packages/e2e-tests/test-applications/svelte-5/playwright.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import type { PlaywrightTestConfig } from '@playwright/test'; | ||
import { devices } from '@playwright/test'; | ||
|
||
// Fix urls not resolving to localhost on Node v17+ | ||
// See: https://github.com/axios/axios/issues/3821#issuecomment-1413727575 | ||
import { setDefaultResultOrder } from 'dns'; | ||
setDefaultResultOrder('ipv4first'); | ||
|
||
const testEnv = process.env.TEST_ENV; | ||
|
||
if (!testEnv) { | ||
throw new Error('No test env defined'); | ||
} | ||
|
||
const sveltePort = 3030; | ||
const eventProxyPort = 3031; | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
const config: PlaywrightTestConfig = { | ||
testDir: './test', | ||
/* Maximum time one test can run for. */ | ||
timeout: 150_000, | ||
expect: { | ||
/** | ||
* Maximum time expect() should wait for the condition to be met. | ||
* For example in `await expect(locator).toHaveText();` | ||
*/ | ||
timeout: 10000, | ||
}, | ||
/* Run tests in files in parallel */ | ||
fullyParallel: false, | ||
workers: 1, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* `next dev` is incredibly buggy with the app dir */ | ||
retries: testEnv === 'development' ? 3 : 0, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: 'list', | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ | ||
actionTimeout: 0, | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
baseURL: `http://localhost:${sveltePort}`, | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: 'on-first-retry', | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { | ||
...devices['Desktop Chrome'], | ||
}, | ||
}, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
webServer: [ | ||
{ | ||
command: 'node ./start-event-proxy.cjs', | ||
port: eventProxyPort, | ||
reuseExistingServer: false, | ||
}, | ||
{ | ||
command: `pnpm wait-port ${eventProxyPort} && pnpm preview --port ${sveltePort}`, | ||
port: sveltePort, | ||
reuseExistingServer: false, | ||
}, | ||
], | ||
}; | ||
|
||
export default config; |
1 change: 1 addition & 0 deletions
1
dev-packages/e2e-tests/test-applications/svelte-5/public/vite.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions
52
dev-packages/e2e-tests/test-applications/svelte-5/src/App.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<script lang="ts"> | ||
import svelteLogo from './assets/svelte.svg' | ||
import viteLogo from '/vite.svg' | ||
import Counter from './lib/Counter.svelte' | ||
function throwError() { | ||
throw new Error('Error thrown from Svelte 5 E2E test app') | ||
} | ||
</script> | ||
|
||
<main> | ||
<div> | ||
<a href="https://vitejs.dev" target="_blank" rel="noreferrer"> | ||
<img src={viteLogo} class="logo" alt="Vite Logo" /> | ||
</a> | ||
<a href="https://svelte.dev" target="_blank" rel="noreferrer"> | ||
<img src={svelteLogo} class="logo svelte" alt="Svelte Logo" /> | ||
</a> | ||
</div> | ||
<h1>Vite + Svelte</h1> | ||
|
||
<div class="card"> | ||
<Counter /> | ||
<button id="errorBtn" onclick={() => throwError()}>Error</button> | ||
</div> | ||
|
||
<p> | ||
Check out <a href="https://github.com/sveltejs/kit#readme" target="_blank" rel="noreferrer">SvelteKit</a>, the official Svelte app framework powered by Vite! | ||
</p> | ||
|
||
<p class="read-the-docs"> | ||
Click on the Vite and Svelte logos to learn more | ||
</p> | ||
</main> | ||
|
||
<style> | ||
.logo { | ||
height: 6em; | ||
padding: 1.5em; | ||
will-change: filter; | ||
transition: filter 300ms; | ||
} | ||
.logo:hover { | ||
filter: drop-shadow(0 0 2em #646cffaa); | ||
} | ||
.logo.svelte:hover { | ||
filter: drop-shadow(0 0 2em #ff3e00aa); | ||
} | ||
.read-the-docs { | ||
color: #888; | ||
} | ||
</style> |
79 changes: 79 additions & 0 deletions
79
dev-packages/e2e-tests/test-applications/svelte-5/src/app.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
:root { | ||
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; | ||
line-height: 1.5; | ||
font-weight: 400; | ||
|
||
color-scheme: light dark; | ||
color: rgba(255, 255, 255, 0.87); | ||
background-color: #242424; | ||
|
||
font-synthesis: none; | ||
text-rendering: optimizeLegibility; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
} | ||
|
||
a { | ||
font-weight: 500; | ||
color: #646cff; | ||
text-decoration: inherit; | ||
} | ||
a:hover { | ||
color: #535bf2; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
display: flex; | ||
place-items: center; | ||
min-width: 320px; | ||
min-height: 100vh; | ||
} | ||
|
||
h1 { | ||
font-size: 3.2em; | ||
line-height: 1.1; | ||
} | ||
|
||
.card { | ||
padding: 2em; | ||
} | ||
|
||
#app { | ||
max-width: 1280px; | ||
margin: 0 auto; | ||
padding: 2rem; | ||
text-align: center; | ||
} | ||
|
||
button { | ||
border-radius: 8px; | ||
border: 1px solid transparent; | ||
padding: 0.6em 1.2em; | ||
font-size: 1em; | ||
font-weight: 500; | ||
font-family: inherit; | ||
background-color: #1a1a1a; | ||
cursor: pointer; | ||
transition: border-color 0.25s; | ||
} | ||
button:hover { | ||
border-color: #646cff; | ||
} | ||
button:focus, | ||
button:focus-visible { | ||
outline: 4px auto -webkit-focus-ring-color; | ||
} | ||
|
||
@media (prefers-color-scheme: light) { | ||
:root { | ||
color: #213547; | ||
background-color: #ffffff; | ||
} | ||
a:hover { | ||
color: #747bff; | ||
} | ||
button { | ||
background-color: #f9f9f9; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
dev-packages/e2e-tests/test-applications/svelte-5/src/assets/svelte.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions
17
dev-packages/e2e-tests/test-applications/svelte-5/src/lib/Counter.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script lang="ts"> | ||
let count = $state(0); | ||
function increment() { | ||
count += 1; | ||
} | ||
let doubled = $derived(count * 2); | ||
</script> | ||
|
||
<button onclick={increment}> | ||
count is {count} | ||
</button> | ||
|
||
<p> | ||
doubled: {doubled} | ||
</p> |
Oops, something went wrong.