Skip to content

Commit 67a6d6e

Browse files
Only add default directives if run is present (#13)
1 parent c118285 commit 67a6d6e

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/lib/vite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function lqip(cfg, ctx) {
1818

1919
function main(overrides = {}) {
2020
return imagetools({
21-
defaultDirectives: () => new URLSearchParams('width=480;1024;1920&format=avif;webp;jpg'),
21+
defaultDirectives: (url) => url.searchParams.has('run') ? new URLSearchParams('width=480;1024;1920&format=avif;webp;jpg') : new URLSearchParams(''),
2222
extendTransforms: (builtins) => [...builtins, lqip],
2323
extendOutputFormats: (builtinOutputFormats) => ({
2424
...builtinOutputFormats,

src/routes/test/+page.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
import testBasic from '../cat01.jpg?run'
33
import testNoLqip from '../cat01.jpg?lqip=0&run'
44
import testWidthOverride from '../cat01.jpg?width=480;1024&run'
5+
import testDefault from '../cat01.jpg'
56
67
const s = (obj = {}) => JSON.stringify(obj)
78
89
const tests = [
910
{ id: 'basic', name: 'default variants are generated', view: s(testBasic) },
1011
{ id: 'nolqip', name: 'no lqip', view: s(testNoLqip) },
11-
{ id: 'width', name: 'width override', view: s(testWidthOverride) }
12+
{ id: 'width', name: 'width override', view: s(testWidthOverride) },
13+
{ id: 'default', name: 'returns a path by default', view: s(testDefault) }
1214
]
1315
</script>
1416

tests/test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ test('width override', async ({ page }) => {
2828
expect(data.filter((i) => i.width === 480).length).toBe(3)
2929
expect(data.filter((i) => i.width === 1024).length).toBe(3)
3030
})
31+
32+
test('returns a path by default', async ({ page }) => {
33+
await page.goto('/test')
34+
const data = JSON.parse((await page.getByTestId('default').textContent()) || '')
35+
expect(data).toBe(`/src/routes/cat01.jpg`)
36+
})

0 commit comments

Comments
 (0)