Skip to content

Commit

Permalink
test(playground/legacy): update case
Browse files Browse the repository at this point in the history
  • Loading branch information
jiadesen committed Nov 23, 2023
1 parent 1b50187 commit 8ee38dd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
32 changes: 20 additions & 12 deletions playground/legacy/__tests__/legacy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ describe.runIf(isBuild)('build', () => {
'../../vite/legacy-polyfills-legacy',
)
expect(manifest['custom0-legacy.js'].file).toMatch(
/chunk-X-legacy\.[-\w]{8}.js/,
/chunk-X\.[-\w]{8}-legacy\.js/,
)
expect(manifest['custom1-legacy.js'].file).toMatch(
/chunk-X-legacy-[-\w]{8}.js/,
/chunk-X-[-\w]{8}-legacy\.js/,
)
expect(manifest['custom2-legacy.js'].file).toMatch(
/chunk-X-legacy[-\w]{8}.js/,
/chunk-X[-\w]{8}-legacy\.js/,
)
// modern polyfill
expect(manifest['../../vite/legacy-polyfills']).toBeDefined()
Expand All @@ -119,15 +119,19 @@ describe.runIf(isBuild)('build', () => {
// esbuild-minified) does not!
const terserPattern = /^(?:!function|System.register)/

expect(findAssetFile(/chunk-async-legacy/)).toMatch(terserPattern)
expect(findAssetFile(/chunk-async(?!-legacy)/)).not.toMatch(terserPattern)
expect(findAssetFile(/chunk-async\.[-\w]{8}-legacy/)).toMatch(terserPattern)
expect(findAssetFile(/chunk-async\.[-\w]{8}(?!-legacy)/)).not.toMatch(
terserPattern,
)
expect(findAssetFile(/immutable-chunk-legacy/)).toMatch(terserPattern)
expect(findAssetFile(/immutable-chunk(?!-legacy)/)).not.toMatch(
terserPattern,
)
expect(findAssetFile(/index-legacy/)).toMatch(terserPattern)
expect(findAssetFile(/index(?!-legacy)/)).not.toMatch(terserPattern)
expect(findAssetFile(/polyfills-legacy/)).toMatch(terserPattern)
expect(findAssetFile(/index-[-\w]{8}-legacy/)).toMatch(terserPattern)
expect(findAssetFile(/index-[-\w]{8}(?!-legacy)/)).not.toMatch(
terserPattern,
)
expect(findAssetFile(/polyfills-[-\w]{8}-legacy/)).toMatch(terserPattern)
})

test('should emit css file', async () => {
Expand All @@ -137,13 +141,17 @@ describe.runIf(isBuild)('build', () => {
})

test('includes structuredClone polyfill which is supported after core-js v3', () => {
expect(findAssetFile(/polyfills-legacy/)).toMatch('"structuredClone"')
expect(findAssetFile(/polyfills-[-\w]{8}-legacy/)).toMatch(
'"structuredClone"',
)
expect(findAssetFile(/polyfills-[-\w]{8}\./)).toMatch('"structuredClone"')
})

test('should generate legacy sourcemap file', async () => {
expect(
listAssets().some((filename) => /index-legacy.+\.map$/.test(filename)),
listAssets().some((filename) =>
/index-[-\w]{8}-legacy.+\.map$/.test(filename),
),
).toBeTruthy()
expect(
listAssets().some((filename) =>
Expand All @@ -154,8 +162,8 @@ describe.runIf(isBuild)('build', () => {

test('should have only modern entry files guarded', async () => {
const guard = /(import\s*\()|(import.meta)|(async\s*function\*)/
expect(findAssetFile(/index(?!-legacy)/)).toMatch(guard)
expect(findAssetFile(/polyfills(?!-legacy)/)).toMatch(guard)
expect(findAssetFile(/index-[-\w]{8}(?!-legacy)/)).toMatch(guard)
expect(findAssetFile(/polyfills-[-\w]{8}(?!-legacy)/)).toMatch(guard)

expect(findAssetFile(/chunk-async(?!-legacy)/)).not.toMatch(guard)
expect(findAssetFile(/index-legacy/)).not.toMatch(guard)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test.runIf(isBuild)('includes only a single script tag', async () => {

await untilUpdated(
() => page.getAttribute('#vite-legacy-entry', 'data-src'),
/.\/assets\/index-legacy-(.+)\.js/,
/.\/assets\/index-[-\w]{8}-legacy\.js/,
true,
)

Expand Down
4 changes: 2 additions & 2 deletions playground/legacy/__tests__/no-polyfills/no-polyfills.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ test('should load and execute the JS file', async () => {
test.runIf(isBuild)('includes a script tag for SystemJS', async () => {
await untilUpdated(
() => page.getAttribute('#vite-legacy-polyfill', 'src'),
/.\/assets\/polyfills-legacy-(.+)\.js/,
/.\/assets\/polyfills-[-\w]{8}-legacy\.js/,
true,
)
await untilUpdated(
() => page.getAttribute('#vite-legacy-entry', 'data-src'),
/.\/assets\/index-legacy-(.+)\.js/,
/.\/assets\/index-[-\w]{8}-legacy\.js/,
true,
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ test.runIf(isBuild)('rebuilds styles only entry on change', async () => {
expect(findAssetFile(/style-only-entry-.+\.css/, 'watch')).toContain(
'hotpink',
)
expect(findAssetFile(/style-only-entry-legacy-.+\.js/, 'watch')).toContain(
'hotpink',
)
expect(findAssetFile(/polyfills-legacy-.+\.js/, 'watch')).toBeTruthy()
expect(
findAssetFile(/style-only-entry-[-\w]{8}-legacy\.js/, 'watch'),
).toContain('hotpink')
expect(findAssetFile(/polyfills-[-\w]{8}-legacy\.js/, 'watch')).toBeTruthy()
const numberOfManifestEntries = Object.keys(readManifest('watch')).length
expect(numberOfManifestEntries).toBe(3)

Expand Down Expand Up @@ -43,5 +43,5 @@ test.runIf(isBuild)('rebuilds styles only entry on change', async () => {
'watch',
)
expect(reRenderedCssLegacyFile).toContain('lightpink')
expect(findAssetFile(/polyfills-legacy-.+\.js/, 'watch')).toBeTruthy()
expect(findAssetFile(/polyfills-[-\w]{8}-legacy\.js/, 'watch')).toBeTruthy()
})

0 comments on commit 8ee38dd

Please sign in to comment.