Christopher S. Dunham commited on
Commit ·
3b5dd0a
1
Parent(s): 4db03c5
Init proper
Browse files- example/.gitignore +24 -0
- example/.npmrc +1 -0
- example/.prettierignore +4 -0
- example/.prettierrc +15 -0
- example/README.md +38 -0
- example/e2e/demo.test.ts +6 -0
- example/eslint.config.js +39 -0
- example/package-lock.json +0 -0
- example/package.json +42 -0
- example/playwright.config.ts +10 -0
- example/src/app.d.ts +13 -0
- example/src/app.html +12 -0
- example/src/demo.spec.ts +7 -0
- example/src/lib/index.ts +1 -0
- example/src/routes/+page.svelte +2 -0
- example/src/routes/page.svelte.test.ts +11 -0
- example/static/favicon.png +0 -0
- example/svelte.config.js +15 -0
- example/tsconfig.json +19 -0
- example/vite.config.ts +35 -0
- example/vitest-setup-client.ts +18 -0
example/.gitignore
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
test-results
|
| 2 |
+
node_modules
|
| 3 |
+
|
| 4 |
+
# Output
|
| 5 |
+
.output
|
| 6 |
+
.vercel
|
| 7 |
+
.netlify
|
| 8 |
+
.wrangler
|
| 9 |
+
/.svelte-kit
|
| 10 |
+
/build
|
| 11 |
+
|
| 12 |
+
# OS
|
| 13 |
+
.DS_Store
|
| 14 |
+
Thumbs.db
|
| 15 |
+
|
| 16 |
+
# Env
|
| 17 |
+
.env
|
| 18 |
+
.env.*
|
| 19 |
+
!.env.example
|
| 20 |
+
!.env.test
|
| 21 |
+
|
| 22 |
+
# Vite
|
| 23 |
+
vite.config.js.timestamp-*
|
| 24 |
+
vite.config.ts.timestamp-*
|
example/.npmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
engine-strict=true
|
example/.prettierignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Package Managers
|
| 2 |
+
package-lock.json
|
| 3 |
+
pnpm-lock.yaml
|
| 4 |
+
yarn.lock
|
example/.prettierrc
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"useTabs": true,
|
| 3 |
+
"singleQuote": true,
|
| 4 |
+
"trailingComma": "none",
|
| 5 |
+
"printWidth": 100,
|
| 6 |
+
"plugins": ["prettier-plugin-svelte"],
|
| 7 |
+
"overrides": [
|
| 8 |
+
{
|
| 9 |
+
"files": "*.svelte",
|
| 10 |
+
"options": {
|
| 11 |
+
"parser": "svelte"
|
| 12 |
+
}
|
| 13 |
+
}
|
| 14 |
+
]
|
| 15 |
+
}
|
example/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# sv
|
| 2 |
+
|
| 3 |
+
Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).
|
| 4 |
+
|
| 5 |
+
## Creating a project
|
| 6 |
+
|
| 7 |
+
If you're seeing this, you've probably already done this step. Congrats!
|
| 8 |
+
|
| 9 |
+
```bash
|
| 10 |
+
# create a new project in the current directory
|
| 11 |
+
npx sv create
|
| 12 |
+
|
| 13 |
+
# create a new project in my-app
|
| 14 |
+
npx sv create my-app
|
| 15 |
+
```
|
| 16 |
+
|
| 17 |
+
## Developing
|
| 18 |
+
|
| 19 |
+
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
| 20 |
+
|
| 21 |
+
```bash
|
| 22 |
+
npm run dev
|
| 23 |
+
|
| 24 |
+
# or start the server and open the app in a new browser tab
|
| 25 |
+
npm run dev -- --open
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
## Building
|
| 29 |
+
|
| 30 |
+
To create a production version of your app:
|
| 31 |
+
|
| 32 |
+
```bash
|
| 33 |
+
npm run build
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
You can preview the production build with `npm run preview`.
|
| 37 |
+
|
| 38 |
+
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
|
example/e2e/demo.test.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { expect, test } from '@playwright/test';
|
| 2 |
+
|
| 3 |
+
test('home page has expected h1', async ({ page }) => {
|
| 4 |
+
await page.goto('/');
|
| 5 |
+
await expect(page.locator('h1')).toBeVisible();
|
| 6 |
+
});
|
example/eslint.config.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import prettier from 'eslint-config-prettier';
|
| 2 |
+
import js from '@eslint/js';
|
| 3 |
+
import { includeIgnoreFile } from '@eslint/compat';
|
| 4 |
+
import svelte from 'eslint-plugin-svelte';
|
| 5 |
+
import globals from 'globals';
|
| 6 |
+
import { fileURLToPath } from 'node:url';
|
| 7 |
+
import ts from 'typescript-eslint';
|
| 8 |
+
import svelteConfig from './svelte.config.js';
|
| 9 |
+
const gitignorePath = fileURLToPath(new URL('./.gitignore', import.meta.url));
|
| 10 |
+
|
| 11 |
+
export default ts.config(
|
| 12 |
+
includeIgnoreFile(gitignorePath),
|
| 13 |
+
js.configs.recommended,
|
| 14 |
+
...ts.configs.recommended,
|
| 15 |
+
...svelte.configs.recommended,
|
| 16 |
+
prettier,
|
| 17 |
+
...svelte.configs.prettier,
|
| 18 |
+
{
|
| 19 |
+
languageOptions: {
|
| 20 |
+
globals: {
|
| 21 |
+
...globals.browser,
|
| 22 |
+
...globals.node
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
files: ['**/*.svelte', '**/*.svelte.ts', '**/*.svelte.js'],
|
| 28 |
+
ignores: ['eslint.config.js', 'svelte.config.js'],
|
| 29 |
+
|
| 30 |
+
languageOptions: {
|
| 31 |
+
parserOptions: {
|
| 32 |
+
projectService: true,
|
| 33 |
+
extraFileExtensions: ['.svelte'],
|
| 34 |
+
parser: ts.parser,
|
| 35 |
+
svelteConfig
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
);
|
example/package-lock.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
example/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "example",
|
| 3 |
+
"private": true,
|
| 4 |
+
"version": "0.0.1",
|
| 5 |
+
"type": "module",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"dev": "vite dev",
|
| 8 |
+
"build": "vite build",
|
| 9 |
+
"preview": "vite preview",
|
| 10 |
+
"prepare": "svelte-kit sync || echo ''",
|
| 11 |
+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
| 12 |
+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
| 13 |
+
"format": "prettier --write .",
|
| 14 |
+
"lint": "prettier --check . && eslint .",
|
| 15 |
+
"test:unit": "vitest",
|
| 16 |
+
"test": "npm run test:unit -- --run && npm run test:e2e",
|
| 17 |
+
"test:e2e": "playwright test"
|
| 18 |
+
},
|
| 19 |
+
"devDependencies": {
|
| 20 |
+
"@eslint/compat": "^1.2.5",
|
| 21 |
+
"@eslint/js": "^9.18.0",
|
| 22 |
+
"@playwright/test": "^1.49.1",
|
| 23 |
+
"@sveltejs/adapter-node": "^5.2.11",
|
| 24 |
+
"@sveltejs/kit": "^2.16.0",
|
| 25 |
+
"@sveltejs/vite-plugin-svelte": "^5.0.0",
|
| 26 |
+
"@testing-library/jest-dom": "^6.6.3",
|
| 27 |
+
"@testing-library/svelte": "^5.2.4",
|
| 28 |
+
"eslint": "^9.18.0",
|
| 29 |
+
"eslint-config-prettier": "^10.0.1",
|
| 30 |
+
"eslint-plugin-svelte": "^3.0.0",
|
| 31 |
+
"globals": "^16.0.0",
|
| 32 |
+
"jsdom": "^26.0.0",
|
| 33 |
+
"prettier": "^3.4.2",
|
| 34 |
+
"prettier-plugin-svelte": "^3.3.3",
|
| 35 |
+
"svelte": "^5.0.0",
|
| 36 |
+
"svelte-check": "^4.0.0",
|
| 37 |
+
"typescript": "^5.0.0",
|
| 38 |
+
"typescript-eslint": "^8.20.0",
|
| 39 |
+
"vite": "^6.0.0",
|
| 40 |
+
"vitest": "^3.0.0"
|
| 41 |
+
}
|
| 42 |
+
}
|
example/playwright.config.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { defineConfig } from '@playwright/test';
|
| 2 |
+
|
| 3 |
+
export default defineConfig({
|
| 4 |
+
webServer: {
|
| 5 |
+
command: 'npm run build && npm run preview',
|
| 6 |
+
port: 4173
|
| 7 |
+
},
|
| 8 |
+
|
| 9 |
+
testDir: 'e2e'
|
| 10 |
+
});
|
example/src/app.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// See https://svelte.dev/docs/kit/types#app.d.ts
|
| 2 |
+
// for information about these interfaces
|
| 3 |
+
declare global {
|
| 4 |
+
namespace App {
|
| 5 |
+
// interface Error {}
|
| 6 |
+
// interface Locals {}
|
| 7 |
+
// interface PageData {}
|
| 8 |
+
// interface PageState {}
|
| 9 |
+
// interface Platform {}
|
| 10 |
+
}
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
export {};
|
example/src/app.html
ADDED
|
@@ -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, initial-scale=1" />
|
| 7 |
+
%sveltekit.head%
|
| 8 |
+
</head>
|
| 9 |
+
<body data-sveltekit-preload-data="hover">
|
| 10 |
+
<div style="display: contents">%sveltekit.body%</div>
|
| 11 |
+
</body>
|
| 12 |
+
</html>
|
example/src/demo.spec.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { describe, it, expect } from 'vitest';
|
| 2 |
+
|
| 3 |
+
describe('sum test', () => {
|
| 4 |
+
it('adds 1 + 2 to equal 3', () => {
|
| 5 |
+
expect(1 + 2).toBe(3);
|
| 6 |
+
});
|
| 7 |
+
});
|
example/src/lib/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
// place files you want to import through the `$lib` alias in this folder.
|
example/src/routes/+page.svelte
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<h1>Welcome to SvelteKit</h1>
|
| 2 |
+
<p>Visit <a href="https://svelte.dev/docs/kit">svelte.dev/docs/kit</a> to read the documentation</p>
|
example/src/routes/page.svelte.test.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { describe, test, expect } from 'vitest';
|
| 2 |
+
import '@testing-library/jest-dom/vitest';
|
| 3 |
+
import { render, screen } from '@testing-library/svelte';
|
| 4 |
+
import Page from './+page.svelte';
|
| 5 |
+
|
| 6 |
+
describe('/+page.svelte', () => {
|
| 7 |
+
test('should render h1', () => {
|
| 8 |
+
render(Page);
|
| 9 |
+
expect(screen.getByRole('heading', { level: 1 })).toBeInTheDocument();
|
| 10 |
+
});
|
| 11 |
+
});
|
example/static/favicon.png
ADDED
|
|
example/svelte.config.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import adapter from '@sveltejs/adapter-node';
|
| 2 |
+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
| 3 |
+
|
| 4 |
+
/** @type {import('@sveltejs/kit').Config} */
|
| 5 |
+
const config = {
|
| 6 |
+
// Consult https://svelte.dev/docs/kit/integrations
|
| 7 |
+
// for more information about preprocessors
|
| 8 |
+
preprocess: vitePreprocess(),
|
| 9 |
+
|
| 10 |
+
kit: {
|
| 11 |
+
adapter: adapter()
|
| 12 |
+
}
|
| 13 |
+
};
|
| 14 |
+
|
| 15 |
+
export default config;
|
example/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"extends": "./.svelte-kit/tsconfig.json",
|
| 3 |
+
"compilerOptions": {
|
| 4 |
+
"allowJs": true,
|
| 5 |
+
"checkJs": true,
|
| 6 |
+
"esModuleInterop": true,
|
| 7 |
+
"forceConsistentCasingInFileNames": true,
|
| 8 |
+
"resolveJsonModule": true,
|
| 9 |
+
"skipLibCheck": true,
|
| 10 |
+
"sourceMap": true,
|
| 11 |
+
"strict": true,
|
| 12 |
+
"moduleResolution": "bundler"
|
| 13 |
+
}
|
| 14 |
+
// Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
|
| 15 |
+
// except $lib which is handled by https://svelte.dev/docs/kit/configuration#files
|
| 16 |
+
//
|
| 17 |
+
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
|
| 18 |
+
// from the referenced tsconfig.json - TypeScript does not merge them in
|
| 19 |
+
}
|
example/vite.config.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { svelteTesting } from '@testing-library/svelte/vite';
|
| 2 |
+
import { sveltekit } from '@sveltejs/kit/vite';
|
| 3 |
+
import { defineConfig } from 'vite';
|
| 4 |
+
|
| 5 |
+
export default defineConfig({
|
| 6 |
+
plugins: [sveltekit()],
|
| 7 |
+
|
| 8 |
+
test: {
|
| 9 |
+
workspace: [
|
| 10 |
+
{
|
| 11 |
+
extends: './vite.config.ts',
|
| 12 |
+
plugins: [svelteTesting()],
|
| 13 |
+
|
| 14 |
+
test: {
|
| 15 |
+
name: 'client',
|
| 16 |
+
environment: 'jsdom',
|
| 17 |
+
clearMocks: true,
|
| 18 |
+
include: ['src/**/*.svelte.{test,spec}.{js,ts}'],
|
| 19 |
+
exclude: ['src/lib/server/**'],
|
| 20 |
+
setupFiles: ['./vitest-setup-client.ts']
|
| 21 |
+
}
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
extends: './vite.config.ts',
|
| 25 |
+
|
| 26 |
+
test: {
|
| 27 |
+
name: 'server',
|
| 28 |
+
environment: 'node',
|
| 29 |
+
include: ['src/**/*.{test,spec}.{js,ts}'],
|
| 30 |
+
exclude: ['src/**/*.svelte.{test,spec}.{js,ts}']
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
]
|
| 34 |
+
}
|
| 35 |
+
});
|
example/vitest-setup-client.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import '@testing-library/jest-dom/vitest';
|
| 2 |
+
import { vi } from 'vitest';
|
| 3 |
+
|
| 4 |
+
// required for svelte5 + jsdom as jsdom does not support matchMedia
|
| 5 |
+
Object.defineProperty(window, 'matchMedia', {
|
| 6 |
+
writable: true,
|
| 7 |
+
enumerable: true,
|
| 8 |
+
value: vi.fn().mockImplementation((query) => ({
|
| 9 |
+
matches: false,
|
| 10 |
+
media: query,
|
| 11 |
+
onchange: null,
|
| 12 |
+
addEventListener: vi.fn(),
|
| 13 |
+
removeEventListener: vi.fn(),
|
| 14 |
+
dispatchEvent: vi.fn()
|
| 15 |
+
}))
|
| 16 |
+
});
|
| 17 |
+
|
| 18 |
+
// add more mocks here if you need them
|