Skip to content

Commit

Permalink
test: add test case for module preload w/ credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
HipsterBrown committed Jun 6, 2024
1 parent 3e9b964 commit 6debed4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { describe, expect, test } from 'vitest'
import { browserLogs, isBuild, page } from '~utils'

test('should have no 404s', () => {
browserLogs.forEach((msg) => {
expect(msg).not.toMatch('404')
})
})

describe.runIf(isBuild)('build', () => {
test('dynamic import', async () => {
await page.waitForSelector('#done')
expect(await page.textContent('#done')).toBe('ran js')
})

test('dynamic import with crossorigin set to use-credentials', async () => {
await page.click('#hello .load')
await page.waitForSelector('#hello output')

const html = await page.content()
expect(html).toMatch(
/link rel="modulepreload" as="script" crossorigin="use-credentials".*?href=".*?\/hello-\w{8}\.js"/,
)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '../../vite.config-preload-credentials'
6 changes: 5 additions & 1 deletion playground/preload/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
"dev:preload-disabled": "vite --config vite.config-preload-disabled.ts",
"build:preload-disabled": "vite build --config vite.config-preload-disabled.ts",
"debug:preload-disabled": "node --inspect-brk ../../packages/vite/bin/vite --config vite.config-preload-disabled.ts",
"preview:preload-disabled": "vite preview --config vite.config-preload-disabled.ts"
"preview:preload-disabled": "vite preview --config vite.config-preload-disabled.ts",
"dev:preload-credentials": "vite --config vite.config-preload-credentials.ts",
"build:preload-credentials": "vite build --config vite.config-preload-credentials.ts",
"debug:preload-credentials": "node --inspect-brk ../../packages/vite/bin/vite --config vite.config-preload-credentials.ts",
"preview:preload-credentials": "vite preview --config vite.config-preload-credentials.ts"
},
"devDependencies": {
"terser": "^5.31.0",
Expand Down
20 changes: 20 additions & 0 deletions playground/preload/vite.config-preload-credentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { defineConfig } from 'vite'

export default defineConfig({
build: {
outDir: 'dist/preload-credentials',
minify: 'terser',
terserOptions: {
format: {
beautify: true,
},
compress: {
passes: 3,
},
},
modulePreload: {
crossOrigin: 'use-credentials',
},
},
cacheDir: 'node_modules/.vite-preload-credentials',
})

0 comments on commit 6debed4

Please sign in to comment.