Skip to content

Commit

Permalink
test: test output hash changes (#18898)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Dec 6, 2024
1 parent 1379bdb commit bfbb130
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/vite/src/node/__tests__/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ describe('build', () => {
buildProject('red'),
buildProject('blue'),
])
expect(getOutputHashChanges(result[0], result[1])).toMatchInlineSnapshot(`
{
"changed": [
"index",
"_subentry.css",
],
"unchanged": [
"undefined",
],
}
`)
assertOutputHashContentChange(result[0], result[1])
})

Expand Down Expand Up @@ -105,6 +116,21 @@ describe('build', () => {
buildProject('yellow'),
buildProject('blue'),
])
expect(getOutputHashChanges(result[0], result[1])).toMatchInlineSnapshot(`
{
"changed": [
"index",
"_foo",
"_bar",
"_baz.css",
],
"unchanged": [
"_foo.css",
"_bar.css",
"undefined",
],
}
`)
assertOutputHashContentChange(result[0], result[1])
})

Expand Down Expand Up @@ -750,3 +776,17 @@ function assertOutputHashContentChange(
}
}
}

function getOutputHashChanges(output1: RollupOutput, output2: RollupOutput) {
const map1 = Object.fromEntries(
output1.output.map((o) => [o.name, o.fileName]),
)
const map2 = Object.fromEntries(
output2.output.map((o) => [o.name, o.fileName]),
)
const names = Object.keys(map1).filter(Boolean)
return {
changed: names.filter((name) => map1[name] !== map2[name]),
unchanged: names.filter((name) => map1[name] === map2[name]),
}
}

0 comments on commit bfbb130

Please sign in to comment.