Skip to content

docs: update examples #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/__file_snapshots__/* filter=lfs diff=lfs merge=lfs -text
**/__image_snapshots__/* filter=lfs diff=lfs merge=lfs -text
**/__fixtures__/* filter=lfs diff=lfs merge=lfs -text
**/test.ts-snapshots/* filter=lfs diff=lfs merge=lfs -text
4 changes: 4 additions & 0 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
- "**/package.json"
- "**/pnpm-lock.yaml"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
audit:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Generate Coverage
on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
coverage:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
- '.github/workflows/lint.yml'
- 'packages/**'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ on:
push:
branches: ['main', 'next']

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
Expand Down
21 changes: 20 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Unit tests
on: pull_request

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -41,6 +45,9 @@ jobs:
with:
run_install: true

- name: Install Playwright
run: npx playwright install --with-deps

- name: Build packages
run: pnpm run build

Expand All @@ -51,4 +58,16 @@ jobs:
if: failure()
with:
name: image-diffs
path: packages/**/__image_snapshots__/__diff_output__/
path: packages/**/__image_snapshots__/__diff_output__/

- name: Run e2e tests
run: pnpm playwright test
working-directory: ./examples/full

- name: Upload test results
if: always()
uses: actions/upload-artifact@v2
with:
name: playwright-report
path: playwright-report
working-directory: ./examples/full
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ dist
coverage
yarn-error.log
**/debug
lerna-debug.log
lerna-debug.log
.svelte-kit
25 changes: 25 additions & 0 deletions examples/full/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "full",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
},
"devDependencies": {
"@playwright/test": "^1.25.0",
"@sveltejs/adapter-auto": "next",
"@sveltejs/kit": "next",
"svelte": "^3.44.0",
"svelte-check": "^2.7.1",
"svelte-preprocess": "^4.10.6",
"tslib": "^2.3.1",
"typescript": "^4.7.4",
"vite": "^3.1.0",
"vite-imagetools": "workspace:^4.0.10"
},
"type": "module"
}
10 changes: 10 additions & 0 deletions examples/full/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { PlaywrightTestConfig } from '@playwright/test'

const config: PlaywrightTestConfig = {
webServer: {
command: 'npm run build && npm run preview',
port: 4173
}
}

export default config
9 changes: 9 additions & 0 deletions examples/full/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
// and what to do when importing types
declare namespace App {
// interface Locals {}
// interface PageData {}
// interface Error {}
// interface Platform {}
}
12 changes: 12 additions & 0 deletions examples/full/src/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
</head>
<body>
<div>%sveltekit.body%</div>
</body>
</html>
43 changes: 43 additions & 0 deletions examples/full/src/images.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
declare module "*?w=500;900;1200&avif;webp;jpg&picture" {
const image: {
sources: Record<string, { src: string, w: string }[]>,
fallback: { src: string, w: string }
};
export default image;
}

declare module "*?width=300&webp&metadata" {
export const src: string;
export const width: string;
export const height: string;
}

declare module "*?w=500;900;1200&avif&source" {
const image: { src: string, w: string }[]

export default image
}

declare module "*?w=500;900;1200&webp&source" {
const image: { src: string, w: string }[]

export default image
}

declare module "*?w=700" {
const image: string

export default image
}

declare module "*?w=500;900;1200&avif&srcset" {
const image: string

export default image
}

declare module "*?w=500;900;1200&webp&srcset" {
const image: string

export default image
}
Binary file added examples/full/src/lib/assets/example.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions examples/full/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Welcome to SvelteKit</h1>
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>
5 changes: 5 additions & 0 deletions examples/full/src/routes/metadata/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script lang="ts">
import { src, width, height } from '$lib/assets/example.jpg?width=300&webp&metadata'
</script>

<img src={src} width={width} height={height} alt="">
5 changes: 5 additions & 0 deletions examples/full/src/routes/no-directives/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script lang="ts">
import exampleImage from '$lib/assets/example.jpg'
</script>

<img src={exampleImage} alt="">
10 changes: 10 additions & 0 deletions examples/full/src/routes/picture/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script lang="ts">
import image from '$lib/assets/example.jpg?w=500;900;1200&avif;webp;jpg&picture'
</script>

<picture>
{#each Object.entries(image.sources) as [format, images]}
<source srcset={images.map((i) => `${i.src}`).join(', ')} type={'image/' + format} />
{/each}
<img src={image.fallback.src} alt=""/>
</picture>`
11 changes: 11 additions & 0 deletions examples/full/src/routes/source/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script lang="ts">
import avif from '$lib/assets/example.jpg?w=500;900;1200&avif&srcset'
import webp from '$lib/assets/example.jpg?w=500;900;1200&webp&srcset'
import fallback from '$lib/assets/example.jpg?w=700'
</script>

<picture>
<source srcset={avif} type="image/avif" />
<source srcset={webp} type="image/webp" />
<img src="" alt="" />
</picture>
10 changes: 10 additions & 0 deletions examples/full/src/routes/srcset/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script lang="ts">
import avif from '$lib/assets/example.jpg?w=500;900;1200&avif&source'
import webp from '$lib/assets/example.jpg?w=500;900;1200&webp&source'
</script>

<picture>
<source srcset={avif.map(({ src, w }) => `${src} ${w}w`).join(',')} type="image/avif" />
<source srcset={webp.map(({ src, w }) => `${src} ${w}w`).join(',')} type="image/webp" />
<img src="" alt="" />
</picture>
5 changes: 5 additions & 0 deletions examples/full/src/routes/url/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script lang="ts">
import exampleImage from '$lib/assets/example.jpg?w=700'
</script>

<img src={exampleImage} alt="">
15 changes: 15 additions & 0 deletions examples/full/svelte.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import adapter from '@sveltejs/adapter-auto';
import preprocess from 'svelte-preprocess';

/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: preprocess(),

kit: {
adapter: adapter()
}
};

export default config;
60 changes: 60 additions & 0 deletions examples/full/tests/output-directives.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { expect, test } from '@playwright/test'

test('url', async ({ page }) => {
await page.goto('/url')

const img = page.locator('img')
await expect(img).toBeVisible()

await expect(page).toHaveScreenshot()
})

test('metadata', async ({ page }) => {
await Promise.all([page.waitForResponse((resp) => resp.url().endsWith('.webp')), page.goto('/metadata')])

const img = page.locator('img')
await expect(img).toBeVisible()

const boundingBox = await (await img.elementHandle())?.boundingBox()
expect(boundingBox?.width).toBe(300)
expect(boundingBox?.height).toBeCloseTo(449.77)

await expect(page).toHaveScreenshot()
})

test('picture', async ({ page }) => {
await page.goto('/picture')

const img = page.locator('img')
await expect(img).toBeVisible()

await expect(page).toHaveScreenshot()
})

test('source', async ({ page }) => {
await page.goto('/source')

const img = page.locator('img')
await expect(img).toBeVisible()

await expect(page).toHaveScreenshot()
})

test('srcset', async ({ page }) => {
await page.goto('/srcset')

const img = page.locator('img')
await expect(img).toBeVisible()

await expect(page).toHaveScreenshot()
})


test('no-directives', async ({ page }) => {
await page.goto('/no-directives')

const img = page.locator('img')
await expect(img).toBeVisible()

await expect(page).toHaveScreenshot()
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
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 examples/full/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true
}
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
//
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
// from the referenced tsconfig.json - TypeScript does not merge them in
}
9 changes: 9 additions & 0 deletions examples/full/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { sveltekit } from '@sveltejs/kit/vite';
import type { UserConfig } from 'vite';
import { imagetools } from 'vite-imagetools'

const config: UserConfig = {
plugins: [sveltekit(), imagetools()]
};

export default config;
Loading