Skip to content

Commit

Permalink
fix: output of log diff show route and path
Browse files Browse the repository at this point in the history
  • Loading branch information
yannick-bonnefond authored and ybonnefond committed Oct 23, 2024
1 parent e512052 commit 1606f9c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
14 changes: 8 additions & 6 deletions src/debug/Debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,21 @@ export class Debugger {
return acc;
}, {} as Record<string, DiffError[]>);

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);
render.renderErrors(DIFF_SUBJECTS.HEADERS, errors);
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());
}
}
12 changes: 12 additions & 0 deletions src/debug/Output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
Expand Down
16 changes: 8 additions & 8 deletions test/specs/debug.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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+/),
]);
});

Expand All @@ -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',
Expand All @@ -62,7 +63,6 @@ describe('debug', () => {
'Body',
'- Received: undefined',
"+ Expected: { name: (val) => val === 'tonton' }",
expect.stringMatching(/^Route registered at .+:\d+:\d+/),
]);
});

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -134,7 +135,6 @@ describe('debug', () => {
"+ lastname: val => val === 'Doe'",
'- roles: writer',
"+ roles: [ 'writer', 'reviewer' ]",
expect.stringMatching(/^Route registered at .+:\d+:\d+/),
]);
});

Expand All @@ -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+/),
]);
});

Expand Down

0 comments on commit 1606f9c

Please sign in to comment.