fix(vite,webpack): don't add type checker/analyzer when testing (#24608)

This commit is contained in:
Daniel Roe 2023-12-05 17:09:46 +00:00 committed by GitHub
parent 4981e3259d
commit 1e393ad696
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 7 deletions

View File

@ -82,7 +82,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
esbuild: {
options: { exclude: excludePattern }
},
analyze: nuxt.options.build.analyze && (nuxt.options.build.analyze === true || nuxt.options.build.analyze.enabled)
analyze: !nuxt.options.test && nuxt.options.build.analyze && (nuxt.options.build.analyze === true || nuxt.options.build.analyze.enabled)
? {
template: 'treemap',
projectRoot: nuxt.options.rootDir,

View File

@ -130,12 +130,12 @@ export async function buildClient (ctx: ViteBuildContext) {
}
// Add analyze plugin if needed
if (ctx.nuxt.options.build.analyze && (ctx.nuxt.options.build.analyze === true || ctx.nuxt.options.build.analyze.enabled)) {
if (!ctx.nuxt.options.test && ctx.nuxt.options.build.analyze && (ctx.nuxt.options.build.analyze === true || ctx.nuxt.options.build.analyze.enabled)) {
clientConfig.plugins!.push(...await import('./plugins/analyze').then(r => r.analyzePlugin(ctx)))
}
// Add type checking client panel
if (ctx.nuxt.options.typescript.typeCheck === true && ctx.nuxt.options.dev) {
if (!ctx.nuxt.options.test && ctx.nuxt.options.typescript.typeCheck === true && ctx.nuxt.options.dev) {
clientConfig.plugins!.push(typeCheckPlugin({ sourcemap: !!ctx.nuxt.options.sourcemap.client }))
}

View File

@ -140,7 +140,7 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => {
}
// Add type-checking
if (ctx.nuxt.options.typescript.typeCheck === true || (ctx.nuxt.options.typescript.typeCheck === 'build' && !ctx.nuxt.options.dev)) {
if (!ctx.nuxt.options.test && (ctx.nuxt.options.typescript.typeCheck === true || (ctx.nuxt.options.typescript.typeCheck === 'build' && !ctx.nuxt.options.dev))) {
const checker = await import('vite-plugin-checker').then(r => r.default)
addVitePlugin(checker({
vueTsc: {

View File

@ -83,7 +83,7 @@ function clientOptimization (_ctx: WebpackConfigContext) {
function clientPlugins (ctx: WebpackConfigContext) {
// webpack Bundle Analyzer
// https://github.com/webpack-contrib/webpack-bundle-analyzer
if (!ctx.isDev && ctx.name === 'client' && ctx.userConfig.analyze && (ctx.userConfig.analyze === true || ctx.userConfig.analyze.enabled)) {
if (!ctx.isDev && !ctx.nuxt.options.test && ctx.name === 'client' && ctx.userConfig.analyze && (ctx.userConfig.analyze === true || ctx.userConfig.analyze.enabled)) {
const statsDir = resolve(ctx.options.analyzeDir)
ctx.config.plugins!.push(new BundleAnalyzerPlugin({
@ -100,7 +100,7 @@ function clientPlugins (ctx: WebpackConfigContext) {
// Normally type checking runs in server config, but in `ssr: false` there is
// no server build, so we inject here instead.
if (!ctx.nuxt.options.ssr) {
if (ctx.nuxt.options.typescript.typeCheck === true || (ctx.nuxt.options.typescript.typeCheck === 'build' && !ctx.nuxt.options.dev)) {
if (!ctx.nuxt.options.test && (ctx.nuxt.options.typescript.typeCheck === true || (ctx.nuxt.options.typescript.typeCheck === 'build' && !ctx.nuxt.options.dev))) {
ctx.config.plugins!.push(new ForkTSCheckerWebpackPlugin({
logger
}))

View File

@ -89,7 +89,7 @@ function serverPlugins (ctx: WebpackConfigContext) {
}
// Add type-checking
if (ctx.nuxt.options.typescript.typeCheck === true || (ctx.nuxt.options.typescript.typeCheck === 'build' && !ctx.nuxt.options.dev)) {
if (!ctx.nuxt.options.test && (ctx.nuxt.options.typescript.typeCheck === true || (ctx.nuxt.options.typescript.typeCheck === 'build' && !ctx.nuxt.options.dev))) {
ctx.config.plugins!.push(new ForkTSCheckerWebpackPlugin({
logger
}))