diff --git a/examples/test-test/package.json b/examples/test-test/package.json index 779ae86ef4cb..53a13e149a42 100644 --- a/examples/test-test/package.json +++ b/examples/test-test/package.json @@ -3,6 +3,7 @@ "private": true, "scripts": { "dev": "umi dev", + "setup": "umi setup", "start": "npm run dev", "test": "jest --no-cache --coverage" }, diff --git a/packages/preset-umi/src/features/tmpFiles/routes.test.ts b/packages/preset-umi/src/features/tmpFiles/routes.test.ts index 883bd480ef63..3cf05227163d 100644 --- a/packages/preset-umi/src/features/tmpFiles/routes.test.ts +++ b/packages/preset-umi/src/features/tmpFiles/routes.test.ts @@ -46,6 +46,7 @@ test('getRoutes', async () => { }, ], }, + userConfig: {}, applyPlugins(opts: any) { return opts?.initialValue; }, diff --git a/packages/preset-umi/src/features/tmpFiles/tmpFiles.ts b/packages/preset-umi/src/features/tmpFiles/tmpFiles.ts index 8d94951652b9..59d7d7643572 100644 --- a/packages/preset-umi/src/features/tmpFiles/tmpFiles.ts +++ b/packages/preset-umi/src/features/tmpFiles/tmpFiles.ts @@ -380,7 +380,12 @@ export default function EmptyRoute() { '...$1', ); // import: route props - headerImports.push(`import routeProps from './routeProps.js';`); + // why has this branch? since test env don't build routeProps.js + if (process.env.NODE_ENV === 'test') { + headerImports.push(`import routeProps from './routeProps';`); + } else { + headerImports.push(`import routeProps from './routeProps.js';`); + } // prevent override internal route props headerImports.push(` if (process.env.NODE_ENV === 'development') {