Skip to content

Commit e377e2c

Browse files
committed
fix: enhance error handling and add router registration in lean profile tests
1 parent ee0fd31 commit e377e2c

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

create-arkstack/src/actions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,13 @@ export default class {
272272
/\n\s*if \((?:err|cause) instanceof ModelNotFoundException\) \{\n\s*error\.code = 404\n\s*error\.message = `\$\{(?:err|cause)\.getModelName\(\)\} not found!`\n\s*\}\n/g,
273273
'\n',
274274
)
275+
.replace(
276+
/if \(\!\(err instanceof ValidationException\) &&\n\s*!\(err instanceof ModelNotFoundException\)\) {/g,
277+
'if (!(err instanceof ValidationException)) {'
278+
)
275279
.replace(
276280
/\s*\/\/ Register API routes\s*await ClearRouter\.group\('\/api', async \(\) => \{\s*await import\(pathToFileURL\(join\(process\.cwd\(\), 'src\/routes\/api\.ts'\)\)\.href\)\s*\}\)\s*/g,
277-
'\n',
281+
'\n\n ',
278282
)
279283

280284
await writeFile(filePath, content, 'utf-8')

create-arkstack/tests/lean-profile.test.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,44 @@ describe('makeLeanProfile', () => {
5959
' error.message = `${cause.getModelName()} not found!`',
6060
' }',
6161
'',
62+
' if (!(err instanceof ValidationException) &&\n !(err instanceof ModelNotFoundException)) {',
63+
' error.stack = (cause as Error).stack',
64+
' }',
65+
'',
6266
' return error',
6367
'}',
6468
'',
6569
].join('\n'),
6670
)
6771

72+
await writeFile(
73+
join(location, 'src/core/router.ts'),
74+
[
75+
'import { Router as ClearRouter } from \'clear-router/express\'',
76+
'',
77+
'export class Router extends ClearRouter {',
78+
' static async bind () {',
79+
' const router = ClearRouter.express.Router()',
80+
'',
81+
' // Register API routes',
82+
' await ClearRouter.group(\'/api\', async () => {',
83+
' await import(pathToFileURL(join(process.cwd(), \'src/routes/api.ts\')).href)',
84+
' })',
85+
'',
86+
' // Register web routes',
87+
' await ClearRouter.group(\'/\', async () => {',
88+
' await import(pathToFileURL(join(process.cwd(), \'src/routes/web.ts\')).href)',
89+
' })',
90+
'',
91+
' // Apply the registered routes to the Express application',
92+
' ClearRouter.apply(router)',
93+
'',
94+
' return router',
95+
' }',
96+
'}',
97+
].join('\n'),
98+
)
99+
68100
await writeFile(
69101
join(location, 'src/routes/api.ts'),
70102
'Router.get(\'/stale\', () => [])\n',
@@ -93,7 +125,8 @@ describe('makeLeanProfile', () => {
93125
const actions = new Actions(location)
94126
await actions.makeLeanProfile('express')
95127

96-
expect(existsSync(join(location, 'src/app'))).toBe(false)
128+
expect(existsSync(join(location, 'src/app/http/controllers'))).toBe(false)
129+
expect(existsSync(join(location, 'src/app/http/resources'))).toBe(false)
97130
expect(existsSync(join(location, 'src/routes/api.ts'))).toBe(false)
98131
expect(existsSync(join(location, 'src/core/database.ts'))).toBe(false)
99132
expect(existsSync(join(location, 'prisma.config.ts'))).toBe(false)
@@ -114,5 +147,7 @@ describe('makeLeanProfile', () => {
114147
expect(handlersContent).not.toContain('ModelNotFoundException')
115148
expect(handlersContent).not.toContain('not found!')
116149

150+
const routerContent = await readFile(join(location, 'src/core/router.ts'), 'utf-8')
151+
expect(routerContent).not.toContain('await ClearRouter.group(\'/api\'')
117152
})
118153
})

0 commit comments

Comments
 (0)