|
| 1 | +import { expect, test } from 'vitest' |
| 2 | +import { |
| 3 | + editFile, |
| 4 | + findAssetFile, |
| 5 | + isBuild, |
| 6 | + notifyRebuildComplete, |
| 7 | + readManifest, |
| 8 | + watcher, |
| 9 | +} from '~utils' |
| 10 | + |
| 11 | +test.runIf(isBuild)('rebuilds styles only entry on change', async () => { |
| 12 | + expect(findAssetFile(/style-only-entry-.+\.css/, 'watch')).toContain( |
| 13 | + 'hotpink', |
| 14 | + ) |
| 15 | + expect(findAssetFile(/style-only-entry-legacy-.+\.js/, 'watch')).toContain( |
| 16 | + 'hotpink', |
| 17 | + ) |
| 18 | + expect(findAssetFile(/polyfills-legacy-.+\.js/, 'watch')).toBeTruthy() |
| 19 | + const numberOfManifestEntries = Object.keys(readManifest('watch')).length |
| 20 | + expect(numberOfManifestEntries).toBe(3) |
| 21 | + |
| 22 | + editFile( |
| 23 | + 'style-only-entry.css', |
| 24 | + (originalContents) => originalContents.replace('hotpink', 'lightpink'), |
| 25 | + true, |
| 26 | + ) |
| 27 | + await notifyRebuildComplete(watcher) |
| 28 | + |
| 29 | + const updatedManifest = readManifest('watch') |
| 30 | + expect(Object.keys(updatedManifest)).toHaveLength(numberOfManifestEntries) |
| 31 | + |
| 32 | + // We must use the file referenced in the manifest here, |
| 33 | + // since there'll be different versions of the file with different hashes. |
| 34 | + const reRenderedCssFile = findAssetFile( |
| 35 | + updatedManifest['style-only-entry.css']!.file.substring('assets/'.length), |
| 36 | + 'watch', |
| 37 | + ) |
| 38 | + expect(reRenderedCssFile).toContain('lightpink') |
| 39 | + const reRenderedCssLegacyFile = findAssetFile( |
| 40 | + updatedManifest['style-only-entry-legacy.css']!.file.substring( |
| 41 | + 'assets/'.length, |
| 42 | + ), |
| 43 | + 'watch', |
| 44 | + ) |
| 45 | + expect(reRenderedCssLegacyFile).toContain('lightpink') |
| 46 | + expect(findAssetFile(/polyfills-legacy-.+\.js/, 'watch')).toBeTruthy() |
| 47 | +}) |
0 commit comments