-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test case for module preload w/ credentials
- Loading branch information
1 parent
3e9b964
commit 6debed4
Showing
4 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
playground/preload/__tests__/preload-credentials/preload-credentials.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,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"/, | ||
) | ||
}) | ||
}) |
1 change: 1 addition & 0 deletions
1
playground/preload/__tests__/preload-credentials/vite.config.js
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 @@ | ||
export { default } from '../../vite.config-preload-credentials' |
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
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 { 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', | ||
}) |