Skip to content

Commit cfb8b39

Browse files
committed
test(assets): add fixture for new URL(/..., import.meta.url)
This tests existing behavior for obtaining an asset's URL from the public base path.
1 parent 7f96b26 commit cfb8b39

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

packages/playground/assets/__tests__/assets.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ test('new URL(..., import.meta.url)', async () => {
234234
expect(await page.textContent('.import-meta-url')).toMatch(assetMatch)
235235
})
236236

237+
test('new URL(/..., import.meta.url)', async () => {
238+
expect(await page.textContent('.import-meta-url-base-path')).toMatch(
239+
iconMatch
240+
)
241+
})
242+
237243
test('new URL(`${dynamic}`, import.meta.url)', async () => {
238244
expect(await page.textContent('.dynamic-import-meta-url-1')).toMatch(
239245
isBuild ? 'data:image/png;base64' : '/foo/nested/icon.png'

packages/playground/assets/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ <h2>new URL('...', import.meta.url)</h2>
141141
<img class="import-meta-url-img" />
142142
<code class="import-meta-url"></code>
143143

144+
<h2>new URL('/...', import.meta.url)</h2>
145+
<img class="import-meta-url-base-path-img" />
146+
<code class="import-meta-url-base-path"></code>
147+
144148
<h2>new URL('...', import.meta.url,) (with comma)</h2>
145149
<img class="import-meta-url-img-comma" />
146150
<code class="import-meta-url-comma"></code>
@@ -276,6 +280,12 @@ <h3 class="raw-query"></h3>
276280
text('.import-meta-url', metaUrl)
277281
document.querySelector('.import-meta-url-img').src = metaUrl
278282

283+
// testing URLs for public assets served at the public base path
284+
// equivalent to `new URL(`${import.meta.env.BASE_URL}/icon.png`, self.location)
285+
const metaUrlBasePath = new URL('/icon.png', import.meta.url)
286+
text('.import-meta-url-base-path', metaUrlBasePath)
287+
document.querySelector('.import-meta-url-base-path-img').src = metaUrlBasePath
288+
279289
// prettier-ignore
280290
const metaUrlWithComma = new URL('./nested/asset.png', import.meta.url,)
281291
text('.import-meta-url-comma', metaUrlWithComma)

0 commit comments

Comments
 (0)