From 9f69cffb828d8149fe30e6dbff712f36cf78002c Mon Sep 17 00:00:00 2001 From: DIYgod Date: Mon, 4 Mar 2024 02:12:49 +0800 Subject: [PATCH] fix: test error --- lib/init-routes.ts | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/init-routes.ts b/lib/init-routes.ts index 19e410828..ee510a8c3 100644 --- a/lib/init-routes.ts +++ b/lib/init-routes.ts @@ -14,19 +14,22 @@ type Root = { const routes: Record void> = {}; -const imports = directoryImport({ - targetDirectoryPath: path.join(__dirname, './routes'), - importPattern: /router\.ts$/, -}); - -for (const path in imports) { - const name = path.split('/').find(Boolean); - if (name) { - routes[name] = ( - imports[path] as { - default: (root: Root) => void; - } - ).default; +if (process.env.NODE_ENV === 'test') { + routes.test = (await import('./routes/test/router')).default; +} else { + const imports = directoryImport({ + targetDirectoryPath: path.join(__dirname, './routes'), + importPattern: /router\.ts$/, + }); + for (const path in imports) { + const name = path.split('/').find(Boolean); + if (name) { + routes[name] = ( + imports[path] as { + default: (root: Root) => void; + } + ).default; + } } }