test: fix playground config variants (#13725)

This commit is contained in:
patak 2023-07-07 13:09:18 +02:00 committed by GitHub
parent df492face0
commit 8f109a67bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 77 additions and 85 deletions

View File

@ -1 +0,0 @@
export { default } from '../../vite.config-relative-base'

View File

@ -1 +0,0 @@
export { default } from '../../vite.config-runtime-base'

View File

@ -1 +0,0 @@
export { default } from '../../vite.config-url-base'

View File

@ -1,2 +0,0 @@
import config from '../../vite.config-no-css-minify'
export default config

View File

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

View File

@ -1 +0,0 @@
export { default } from '../../vite.config-preload-disabled'

View File

@ -1 +0,0 @@
export { default } from '../../vite.config-resolve-deps'

View File

@ -4,6 +4,7 @@ import os from 'node:os'
import fs from 'fs-extra'
import { chromium } from 'playwright-chromium'
import type {
ConfigEnv,
InlineConfig,
Logger,
PluginOption,
@ -197,27 +198,31 @@ beforeAll(async (s) => {
}
})
function loadConfigFromDir(dir: string) {
return loadConfigFromFile(
{
command: isBuild ? 'build' : 'serve',
mode: isBuild ? 'production' : 'development',
},
undefined,
dir,
)
}
export async function startDefaultServe(): Promise<void> {
let config: UserConfig | null = null
// config file near the *.spec.ts
const res = await loadConfigFromDir(dirname(testPath))
if (res) {
config = res.config
const configEnv: ConfigEnv = {
command: isBuild ? 'build' : 'serve',
mode: isBuild ? 'production' : 'development',
}
// config file named by convention as the *.spec.ts folder
const variantName = path.basename(dirname(testPath))
if (variantName !== '__tests__') {
const configVariantPath = path.resolve(
rootDir,
`vite.config-${variantName}.js`,
)
if (fs.existsSync(configVariantPath)) {
const res = await loadConfigFromFile(configEnv, configVariantPath)
if (res) {
config = res.config
}
}
}
// config file from test root dir
if (!config) {
const res = await loadConfigFromDir(rootDir)
const res = await loadConfigFromFile(configEnv, undefined, rootDir)
if (res) {
config = res.config
}

View File

@ -1 +0,0 @@
export { default } from '../../vite.config-es'

View File

@ -1 +0,0 @@
export { default } from '../../vite.config-iife'

View File

@ -1 +0,0 @@
export { default } from '../../vite.config-relative-base-iife'

View File

@ -1 +0,0 @@
export { default } from '../../vite.config-relative-base'

View File

@ -1,2 +0,0 @@
import sourcemap from '../../vite.config-sourcemap'
export default sourcemap('hidden')

View File

@ -1,2 +0,0 @@
import sourcemap from '../../vite.config-sourcemap'
export default sourcemap('inline')

View File

@ -1,2 +0,0 @@
import sourcemap from '../../vite.config-sourcemap'
export default sourcemap(true)

View File

@ -0,0 +1,2 @@
import sourcemap from './worker-sourcemap-config.js'
export default sourcemap('hidden')

View File

@ -0,0 +1,2 @@
import sourcemap from './worker-sourcemap-config.js'
export default sourcemap('inline')

View File

@ -1,50 +1,2 @@
import { defineConfig } from 'vite'
import workerPluginTestPlugin from './worker-plugin-test-plugin'
/** @param {boolean | 'inline' | 'hidden' | 'sourcemap'} sourcemap */
export default (sourcemap) => {
sourcemap =
/** @type {'inline' | 'hidden' | 'sourcemap'} */ (
process.env.WORKER_MODE
) || sourcemap
if (sourcemap === 'sourcemap') {
sourcemap = true
}
const typeName =
typeof sourcemap === 'boolean' ? 'sourcemap' : 'sourcemap-' + sourcemap
return defineConfig({
base: `/iife-${typeName}/`,
resolve: {
alias: {
'@': __dirname,
},
},
worker: {
format: 'iife',
plugins: [workerPluginTestPlugin()],
rollupOptions: {
output: {
assetFileNames: 'assets/[name]-worker_asset[hash].[ext]',
chunkFileNames: 'assets/[name]-worker_chunk[hash].js',
entryFileNames: 'assets/[name]-worker_entry[hash].js',
},
},
},
build: {
outDir: `dist/iife-${typeName}/`,
sourcemap: sourcemap,
rollupOptions: {
output: {
assetFileNames: 'assets/[name]-[hash].[ext]',
chunkFileNames: 'assets/[name]-[hash].js',
entryFileNames: 'assets/[name]-[hash].js',
},
},
},
plugins: [workerPluginTestPlugin()],
cacheDir: `node_modules/.vite-sourcemap-${typeName}`,
})
}
import sourcemap from './worker-sourcemap-config.js'
export default sourcemap(true)

View File

@ -0,0 +1,50 @@
import { defineConfig } from 'vite'
import workerPluginTestPlugin from './worker-plugin-test-plugin'
/** @param {boolean | 'inline' | 'hidden' | 'sourcemap'} sourcemap */
export default (sourcemap) => {
sourcemap =
/** @type {'inline' | 'hidden' | 'sourcemap'} */ (
process.env.WORKER_MODE
) || sourcemap
if (sourcemap === 'sourcemap') {
sourcemap = true
}
const typeName =
typeof sourcemap === 'boolean' ? 'sourcemap' : 'sourcemap-' + sourcemap
return defineConfig({
base: `/iife-${typeName}/`,
resolve: {
alias: {
'@': __dirname,
},
},
worker: {
format: 'iife',
plugins: [workerPluginTestPlugin()],
rollupOptions: {
output: {
assetFileNames: 'assets/[name]-worker_asset[hash].[ext]',
chunkFileNames: 'assets/[name]-worker_chunk[hash].js',
entryFileNames: 'assets/[name]-worker_entry[hash].js',
},
},
},
build: {
outDir: `dist/iife-${typeName}/`,
sourcemap: sourcemap,
rollupOptions: {
output: {
assetFileNames: 'assets/[name]-[hash].[ext]',
chunkFileNames: 'assets/[name]-[hash].js',
entryFileNames: 'assets/[name]-[hash].js',
},
},
},
plugins: [workerPluginTestPlugin()],
cacheDir: `node_modules/.vite-sourcemap-${typeName}`,
})
}