Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test: fix test and add test
  • Loading branch information
sapphi-red committed Feb 18, 2025
commit c2f99b51bb82f11d9806c1c0ec593edd550e131f
35 changes: 35 additions & 0 deletions playground/assets/__tests__/assets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,41 @@ describe('asset imports from js', () => {
'[success] Raw js from /public loaded'
"
`)
expect(await page.textContent('.public-js-import-content-type')).toMatch(
'text/javascript',
)
})

test('from /public (ts)', async () => {
expect(await page.textContent('.public-ts-import')).toMatch(
'/foo/bar/raw.ts',
)
expect(await page.textContent('.public-ts-import-content'))
.toMatchInlineSnapshot(`
"export default function other() {
return 1 + 2
}
"
`)
expect(await page.textContent('.public-ts-import-content-type')).toMatch(
'text/javascript',
)
})

test('from /public (mts)', async () => {
expect(await page.textContent('.public-mts-import')).toMatch(
'/foo/bar/raw.mts',
)
expect(await page.textContent('.public-mts-import-content'))
.toMatchInlineSnapshot(`
"export default function foobar() {
return 1 + 2
}
"
`)
expect(await page.textContent('.public-mts-import-content-type')).toMatch(
'text/javascript',
)
})
})

Expand Down
57 changes: 38 additions & 19 deletions playground/assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,18 @@ <h2>Asset Imports from JS</h2>
</li>
<li>
From publicDir (js): <code class="public-js-import"></code> Content:
<code class="public-js-import-content"></code>
<code class="public-js-import-content"></code> Content-Type:
<code class="public-js-import-content-type"></code>
</li>
<li>
From publicDir (ts): <code class="public-ts-import"></code> Content:
<code class="public-ts-import-content"></code> Content-Type:
<code class="public-ts-import-content-type"></code>
</li>
<li>
From publicDir (mts): <code class="public-mts-import"></code> Content:
<code class="public-mts-import-content"></code> Content-Type:
<code class="public-mts-import-content-type"></code>
</li>
</ul>

Expand Down Expand Up @@ -471,24 +482,6 @@ <h3>assets in template</h3>
import './css/icons.css'
import './css/manual-chunks.css'

import mts from './static/index.mts'
console.log('import.mts', mts)

import ts from './static/index.ts'
console.log('import.ts', ts)

fetch('/foo/bar/index.mts')
.then((res) => res.text())
.then((text) => {
console.log('fetch.mts', text)
})

fetch('/foo/bar/index.ts')
.then((res) => res.text())
.then((text) => {
console.log('fetch.ts', text)
})

text('.base', `import.meta.${``}env.BASE_URL: ${import.meta.env.BASE_URL}`)

import url from './nested/asset.png'
Expand All @@ -512,6 +505,32 @@ <h3>assets in template</h3>
;(async () => {
const res = await fetch(publicJsUrl)
text('.public-js-import-content', await res.text())
text(
'.public-js-import-content-type',
await res.headers.get('Content-Type'),
)
})()

import publicTsUrl from '/raw.ts?url'
text('.public-ts-import', publicTsUrl)
;(async () => {
const res = await fetch(publicTsUrl)
text('.public-ts-import-content', await res.text())
text(
'.public-ts-import-content-type',
await res.headers.get('Content-Type'),
)
})()

import publicMtsUrl from '/raw.mts?url'
text('.public-mts-import', publicMtsUrl)
;(async () => {
const res = await fetch(publicMtsUrl)
text('.public-mts-import-content', await res.text())
text(
'.public-mts-import-content-type',
await res.headers.get('Content-Type'),
)
})()

import svgFrag from './nested/fragment.svg'
Expand Down
File renamed without changes.
File renamed without changes.