-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
73 additions
and
1 deletion.
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions
20
playground/assets-sanitize/__tests__/assets-sanitize.spec.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,20 @@ | ||
import { expect, test } from 'vitest' | ||
import { getBg, isBuild, listAssets, page } from '~utils' | ||
|
||
if (!isBuild) { | ||
test('importing asset with special char in filename works', async () => { | ||
expect(await getBg('.circle-bg')).toContain('+circle.svg') | ||
expect(await page.textContent('.circle-bg')).toMatch('+circle.svg') | ||
}) | ||
} else { | ||
const expected_asset_name_RE = /_circle\.[\w]+\.svg/ | ||
test('importing asset with special char in filename works', async () => { | ||
expect(await getBg('.circle-bg')).toMatch(expected_asset_name_RE) | ||
expect(await page.textContent('.circle-bg')).toMatch(expected_asset_name_RE) | ||
}) | ||
test('asset with special char in filename gets sanitized', async () => { | ||
const svgs = listAssets().filter((a) => a.endsWith('.svg')) | ||
expect(svgs[0]).toMatch(expected_asset_name_RE) | ||
expect(svgs.length).toBe(1) | ||
}) | ||
} |
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,6 @@ | ||
<script type="module" src="./index.js"></script> | ||
<h1>test element below should show a circle and it's url</h1> | ||
<div | ||
class="circle-bg" | ||
style="background-repeat: no-repeat; padding-left: 2rem" | ||
></div> |
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,4 @@ | ||
import svg from './+circle.svg' | ||
const el = document.body.querySelector('.circle-bg') | ||
el.style.backgroundImage = `url(${svg})` | ||
el.textContent = svg |
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,11 @@ | ||
{ | ||
"name": "test-assets-sanitize", | ||
"private": true, | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"debug": "node --inspect-brk ../../packages/vite/bin/vite", | ||
"preview": "vite preview" | ||
} | ||
} |
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,11 @@ | ||
const { defineConfig } = require('vite') | ||
|
||
module.exports = defineConfig({ | ||
build: { | ||
//speed up build | ||
minify: false, | ||
target: 'esnext', | ||
assetsInlineLimit: 0, | ||
manifest: true | ||
} | ||
}) |