test(css): deterministic css emit with the same file basename (#12773)

This commit is contained in:
sun0day 2023-04-08 02:02:39 +08:00 committed by GitHub
parent f09551f18d
commit b91135c009
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,19 @@
import { beforeEach, describe, expect, test } from 'vitest'
import { findAssetFile, isBuild, startDefaultServe } from '~utils'
beforeEach(async () => {
await startDefaultServe()
})
for (let i = 0; i < 5; i++) {
describe.runIf(isBuild)('css files has same basename', () => {
test('emit file name should consistent', () => {
expect(findAssetFile('sub.css', 'same-file-name', '.')).toMatch(
'.sub1-sub',
)
expect(findAssetFile('sub2.css', 'same-file-name', '.')).toMatch(
'.sub2-sub',
)
})
})
}

View File

@ -0,0 +1,2 @@
import config from '../../vite.config-same-file-name'
export default config

View File

@ -117,3 +117,6 @@ document
import './unsupported.css'
import './async/index'
import('./same-name/sub1/sub')
import('./same-name/sub2/sub')

View File

@ -0,0 +1,3 @@
.sub1-sub {
color: red;
}

View File

@ -0,0 +1,3 @@
import './sub.css'
export default 'sub1-name'

View File

@ -0,0 +1,3 @@
.sub2-sub {
color: blue;
}

View File

@ -0,0 +1,3 @@
import './sub.css'
export default 'sub2-name'

View File

@ -0,0 +1,17 @@
import { defineConfig } from 'vite'
import baseConfig from './vite.config.js'
export default defineConfig({
...baseConfig,
build: {
...baseConfig.build,
outDir: 'dist/same-file-name',
rollupOptions: {
output: {
entryFileNames: '[name].js',
chunkFileNames: '[name].[hash].js',
assetFileNames: '[name].[ext]',
},
},
},
})