From 1606f9c098621892b70b56e7c9e03ee184f8c8e8 Mon Sep 17 00:00:00 2001 From: Yannick B Date: Wed, 23 Oct 2024 19:17:03 +0200 Subject: [PATCH] fix: output of log diff show route and path --- src/debug/Debugger.ts | 14 ++++++++------ src/debug/Output.ts | 12 ++++++++++++ test/specs/debug.spec.ts | 16 ++++++++-------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/debug/Debugger.ts b/src/debug/Debugger.ts index 8369ed2..6404d47 100644 --- a/src/debug/Debugger.ts +++ b/src/debug/Debugger.ts @@ -54,7 +54,14 @@ export class Debugger { return acc; }, {} as Record); - out.add(`## Request: ${this.request.method} ${this.request.path}`); + out.add( + `## Route: ${out.blue(out.bold(this.request.method))} ${out.cyan( + this.request.path, + )}`, + ); + out.pushTab(); + out.add(out.tab(`at ${out.formatLineInfo(route.getInitializerPath())}`)); + out.pullTab(); render.renderErrors(DIFF_SUBJECTS.METHOD, errors); render.renderErrors(DIFF_SUBJECTS.PATH, errors); @@ -62,11 +69,6 @@ export class Debugger { render.renderErrors(DIFF_SUBJECTS.QUERY, errors); render.renderErrors(DIFF_SUBJECTS.BODY, errors); - out.newLine(); - out.add( - `Route registered at ${out.formatLineInfo(route.getInitializerPath())}`, - ); - process.stdout.write(out.render()); } } diff --git a/src/debug/Output.ts b/src/debug/Output.ts index 233e31a..f08d8c3 100644 --- a/src/debug/Output.ts +++ b/src/debug/Output.ts @@ -62,6 +62,18 @@ export class Output { return Color.yellow(text); } + public blue(text: string) { + return Color.blue(text); + } + + public cyan(text: string) { + return Color.cyan(text); + } + + public bold(text: string) { + return Color.bold(text); + } + public formatLineInfo(line: LineInfo | null) { if (line === null) { return ''; diff --git a/test/specs/debug.spec.ts b/test/specs/debug.spec.ts index 34ee371..19978b2 100755 --- a/test/specs/debug.spec.ts +++ b/test/specs/debug.spec.ts @@ -29,11 +29,11 @@ describe('debug', () => { const out = await run(req); expoectOutputToBe(out, [ - '## Request: POST /', + '## Route: POST /', + expect.stringMatching(/^\s\sat .+:\d+:\d+/), 'Method', '- Received: post', '+ Expected: put', - expect.stringMatching(/^Route registered at .+:\d+:\d+/), ]); }); @@ -50,7 +50,8 @@ describe('debug', () => { const out = await run(req); expoectOutputToBe(out, [ - '## Request: GET /test-stuff', + '## Route: GET /test-stuff', + expect.stringMatching(/^\s\sat .+:\d+:\d+/), 'Method', '- Received: get', '+ Expected: post', @@ -62,7 +63,6 @@ describe('debug', () => { 'Body', '- Received: undefined', "+ Expected: { name: (val) => val === 'tonton' }", - expect.stringMatching(/^Route registered at .+:\d+:\d+/), ]); }); @@ -106,7 +106,8 @@ describe('debug', () => { const out = await run(req); expoectOutputToBe(out, [ - '## Request: POST /test', + '## Route: POST /test', + expect.stringMatching(/^\s\sat .+:\d+:\d+/), 'Method', '- Received: post', '+ Expected: put', @@ -134,7 +135,6 @@ describe('debug', () => { "+ lastname: val => val === 'Doe'", '- roles: writer', "+ roles: [ 'writer', 'reviewer' ]", - expect.stringMatching(/^Route registered at .+:\d+:\d+/), ]); }); @@ -145,11 +145,11 @@ describe('debug', () => { const out = await run(req); expoectOutputToBe(out, [ - '## Request: POST /', + '## Route: POST /', + expect.stringMatching(/^\s\sat .+:\d+:\d+/), 'Method', '- Received: post', '+ Expected: put', - expect.stringMatching(/^Route registered at .+:\d+:\d+/), ]); });