From 66615b6284c78c3a54998e16de1ec91dfbb570db Mon Sep 17 00:00:00 2001 From: pshu Date: Mon, 23 Sep 2024 15:44:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20test=20browser=20template?= =?UTF-8?q?=20use=20wrong=20loadingComponent=20value?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/preset-umi/src/features/test/test.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/preset-umi/src/features/test/test.ts b/packages/preset-umi/src/features/test/test.ts index 90942b4e4927..247786b67898 100644 --- a/packages/preset-umi/src/features/test/test.ts +++ b/packages/preset-umi/src/features/test/test.ts @@ -1,6 +1,7 @@ import { winPath } from '@umijs/utils'; import { existsSync } from 'fs'; import { dirname, join } from 'path'; +import { expandJSPaths } from '../../commands/dev/watch'; import { TEMPLATES_DIR } from '../../constants'; import { IApi } from '../../types'; import { importsToStr } from '../tmpFiles/importsToStr'; @@ -27,6 +28,12 @@ export default (api: IApi) => { ), }), ); + + const loadingFile = expandJSPaths( + join(api.paths.absSrcPath, 'loading'), + ).find(existsSync); + const globalLoading = loadingFile ? winPath(loadingFile) : undefined; + // testBrowser.tsx api.writeTmpFile({ noPluginDir: true, @@ -66,10 +73,7 @@ export default (api: IApi) => { historyType: api.config.history.type, reactRouter5Compat: !!api.config.reactRouter5Compat, hydrate: !!api.config.ssr, - loadingComponent: - existsSync(join(api.paths.absSrcPath, 'loading.tsx')) || - existsSync(join(api.paths.absSrcPath, 'loading.jsx')) || - existsSync(join(api.paths.absSrcPath, 'loading.js')), + loadingComponent: globalLoading, }, }); });