|
1 | 1 | import { basename, resolve } from 'node:path' |
2 | 2 | import { fileURLToPath } from 'node:url' |
3 | 3 | import { stripVTControlCharacters } from 'node:util' |
| 4 | +import fsp from 'node:fs/promises' |
4 | 5 | import colors from 'picocolors' |
5 | 6 | import { afterEach, describe, expect, test, vi } from 'vitest' |
6 | 7 | import type { |
@@ -1037,6 +1038,62 @@ describe('onRollupLog', () => { |
1037 | 1038 | ) |
1038 | 1039 | }) |
1039 | 1040 |
|
| 1041 | +test('watch rebuild manifest', async (ctx) => { |
| 1042 | + // this doesn't actually test watch rebuild |
| 1043 | + // but it simulates something similar by running two builds for the same environment |
| 1044 | + const root = resolve(__dirname, 'fixtures/watch-rebuild-manifest') |
| 1045 | + const builder = await createBuilder({ |
| 1046 | + root, |
| 1047 | + logLevel: 'error', |
| 1048 | + environments: { |
| 1049 | + client: { |
| 1050 | + build: { |
| 1051 | + rollupOptions: { |
| 1052 | + input: '/entry.js', |
| 1053 | + }, |
| 1054 | + }, |
| 1055 | + }, |
| 1056 | + }, |
| 1057 | + build: { |
| 1058 | + manifest: true, |
| 1059 | + }, |
| 1060 | + }) |
| 1061 | + |
| 1062 | + function getManifestKeys(output: RollupOutput) { |
| 1063 | + return Object.keys( |
| 1064 | + JSON.parse( |
| 1065 | + (output.output.find((o) => o.fileName === '.vite/manifest.json') as any) |
| 1066 | + .source, |
| 1067 | + ), |
| 1068 | + ) |
| 1069 | + } |
| 1070 | + |
| 1071 | + const result = await builder.build(builder.environments.client) |
| 1072 | + expect(getManifestKeys(result as RollupOutput)).toMatchInlineSnapshot(` |
| 1073 | + [ |
| 1074 | + "dep.js", |
| 1075 | + "entry.js", |
| 1076 | + ] |
| 1077 | + `) |
| 1078 | + |
| 1079 | + const entry = resolve(root, 'entry.js') |
| 1080 | + const content = await fsp.readFile(entry, 'utf-8') |
| 1081 | + await fsp.writeFile( |
| 1082 | + entry, |
| 1083 | + content.replace(`import('./dep.js')`, `'dep.js removed'`), |
| 1084 | + ) |
| 1085 | + ctx.onTestFinished(async () => { |
| 1086 | + await fsp.writeFile(entry, content) |
| 1087 | + }) |
| 1088 | + |
| 1089 | + const result2 = await builder.build(builder.environments.client) |
| 1090 | + expect(getManifestKeys(result2 as RollupOutput)).toMatchInlineSnapshot(` |
| 1091 | + [ |
| 1092 | + "entry.js", |
| 1093 | + ] |
| 1094 | + `) |
| 1095 | +}) |
| 1096 | + |
1040 | 1097 | /** |
1041 | 1098 | * for each chunks in output1, if there's a chunk in output2 with the same fileName, |
1042 | 1099 | * ensure that the chunk code is the same. if not, the chunk hash should have changed. |
|
0 commit comments