Skip to content

Commit

Permalink
fix test suite for Vite 2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Mar 10, 2022
1 parent 5e9b29d commit 33acbd5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
19 changes: 12 additions & 7 deletions boilerplates/.testRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { page, run, partRegex, autoRetry, fetchHtml, urlBase, expectBrowserError

export { testRun }

function testRun(
cmd: 'npm run dev' | 'npm run prod',
{ skipTitleColorTest }: { skipTitleColorTest?: boolean } = {},
) {
function testRun(cmd: 'npm run dev' | 'npm run prod', { skipTitleColorTest }: { skipTitleColorTest?: boolean } = {}) {
run(cmd)

test('page content is rendered to HTML', async () => {
Expand All @@ -32,9 +29,17 @@ function testRun(
expect(html).toMatch(
partRegex`<script type="module" src="/assets/renderer/_default.page.client.${extRegexp}.${hashRegexp}.js">`,
)
expect(html).toMatch(
partRegex`<link rel="modulepreload" as="script" type="text/javascript" href="/assets/vendor.${hashRegexp}.js">`,
)
try {
// Vite 2.8
expect(html).toMatch(
partRegex`<link rel="modulepreload" as="script" type="text/javascript" href="/assets/vendor.${hashRegexp}.js">`,
)
} catch (err) {
// Vite 2.9
expect(html).toMatch(
partRegex`<link rel="modulepreload" as="script" type="text/javascript" href="/assets/renderer/_default.page.client.${extRegexp}.${hashRegexp}.js">`,
)
}
expect(html).not.toContain('<script type="module" src="/@vite/client"></script>')
} else {
expect(html).toContain('<script type="module" src="/@vite/client"></script>')
Expand Down
24 changes: 17 additions & 7 deletions examples/custom-server-render-integration/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,28 @@ function assert_pageAssets(pageAssets) {
assert(a1.assetType === 'style')
assert(a1.mediaType === 'text/css')
assert(a1.preloadType === 'style')
const a2 = pageAssets[1]
assert(partRegex`/assets/vendor.${/[a-z0-9]+/}.js`.test(a2.src))
assert(a2.assetType === 'preload')
assert(a2.mediaType === 'text/javascript')
assert(a2.preloadType === 'script')

let a2 = pageAssets[1]
let a3 = pageAssets[2]
let a4 = pageAssets[3]
if (a4) {
// Vite 2.8
assert(pageAssets.length === 4)
assert(partRegex`/assets/vendor.${/[a-z0-9]+/}.js`.test(a2.src))
assert(a2.assetType === 'preload')
assert(a2.mediaType === 'text/javascript')
assert(a2.preloadType === 'script')
} else {
// Vite 2.9
assert(pageAssets.length === 3)
a4 = a3
a3 = a2
}
const isClientAsset = (src) => partRegex`/assets/renderer/_default.page.client.jsx.${/[a-z0-9]+/}.js`.test(src)
const a3 = pageAssets[2]
assert(isClientAsset(a3.src))
assert(a3.assetType === 'preload')
assert(a3.mediaType === 'text/javascript')
assert(a3.preloadType === 'script')
const a4 = pageAssets[3]
assert(isClientAsset(a4.src))
assert(a4.assetType === 'script')
assert(a4.mediaType === 'text/javascript')
Expand Down

0 comments on commit 33acbd5

Please sign in to comment.