Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
66 changes: 66 additions & 0 deletions packages/vite/src/node/__tests__/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,34 @@ describe('build', () => {
assertOutputHashContentChange(result[0], result[1])
})

test('file hash should change when renderBuiltUrl changes', async () => {
const createRenderBuiltUrl = (base: string) => (filename: string) =>
`${base}/${filename}`
const renderBuiltUrlA = createRenderBuiltUrl('/cdn-a')
const renderBuiltUrlB = createRenderBuiltUrl('/cdn-b')

expect(renderBuiltUrlA.toString()).toBe(renderBuiltUrlB.toString())

const result = await Promise.all([
buildProjectWithRenderBuiltUrl(renderBuiltUrlA),
buildProjectWithRenderBuiltUrl(renderBuiltUrlB),
])

expect(getOutputHashChanges(result[0], result[1])).toMatchInlineSnapshot(`
{
"changed": [
"index",
],
"unchanged": [
"_subentry",
"asset.txt",
"undefined",
],
}
`)
assertOutputHashContentChange(result[0], result[1])
})

test('top-level input is used as the default build entry', async () => {
const result = (await build({
root: resolve(dirname, 'packages/build-project'),
Expand Down Expand Up @@ -1512,6 +1540,44 @@ test('copies public directory after building same environment with write false f
).resolves.toBe('<svg></svg>')
})

async function buildProjectWithRenderBuiltUrl(
renderBuiltUrl: (filename: string) => string,
) {
return (await build({
root: resolve(dirname, 'packages/build-project'),
logLevel: 'silent',
build: {
write: false,
assetsInlineLimit: 0,
},
experimental: {
renderBuiltUrl,
},
plugins: [
{
name: 'test',
resolveId(id) {
if (id === 'entry.js' || id === 'subentry.js') {
return '\0' + id
}
},
load(id) {
if (id === '\0entry.js') {
return `
import assetUrl from '/asset.txt?url'
console.log(assetUrl)
window.addEventListener('click', () => { import('subentry.js') })
`
}
if (id === '\0subentry.js') {
return `export default 'subentry'`
}
},
},
],
})) as RolldownOutput
}

/**
* for each chunks in output1, if there's a chunk in output2 with the same fileName,
* ensure that the chunk code is the same. if not, the chunk hash should have changed.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asset
Loading