Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: output a single formatted message to console #1820

Merged
merged 4 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/core/handlers/GraphQLHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,12 @@ Consider naming this operation or using "graphql.operation()" request handler to
: `anonymous ${args.parsedResult?.operationType}`

console.groupCollapsed(
devUtils.formatMessage('%s %s (%c%s%c)'),
getTimestamp(),
`${requestInfo}`,
devUtils.formatMessage(
`${getTimestamp()} ${requestInfo} (%c${loggedResponse.status} ${
loggedResponse.statusText
}%c)`,
),
`color:${statusColor}`,
`${loggedResponse.status} ${loggedResponse.statusText}`,
'color:inherit',
)
console.log('Request:', loggedRequest)
Expand Down
10 changes: 5 additions & 5 deletions src/core/handlers/HttpHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ export class HttpHandler extends RequestHandler<
const statusColor = getStatusCodeColor(loggedResponse.status)

console.groupCollapsed(
devUtils.formatMessage('%s %s %s (%c%s%c)'),
getTimestamp(),
args.request.method,
publicUrl,
devUtils.formatMessage(
`${getTimestamp()} ${args.request.method} ${publicUrl} (%c${
loggedResponse.status
} ${loggedResponse.statusText}%c)`,
),
`color:${statusColor}`,
`${loggedResponse.status} ${loggedResponse.statusText}`,
'color:inherit',
)
console.log('Request', loggedRequest)
Expand Down
8 changes: 4 additions & 4 deletions test/browser/graphql-api/logging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test('prints a log for a GraphQL query', async ({
expect.arrayContaining([
expect.stringMatching(
new RegExp(
`^\\[MSW\\] %s %s \\(%c%s%c\\) \\d{2}:\\d{2}:\\d{2} query GetUserDetail color:${StatusCodeColor.Success} 200 OK color:inherit$`,
`^\\[MSW\\] \\d{2}:\\d{2}:\\d{2} query GetUserDetail \\(%c200 OK%c\\) color:${StatusCodeColor.Success} color:inherit$`,
),
),
]),
Expand Down Expand Up @@ -60,7 +60,7 @@ test('prints a log for a GraphQL mutation', async ({
expect.arrayContaining([
expect.stringMatching(
new RegExp(
`\\[MSW\\] %s %s \\(%c%s%c\\) \\d{2}:\\d{2}:\\d{2} mutation Login color:${StatusCodeColor.Success} 200 OK color:inherit$`,
`\\[MSW\\] \\d{2}:\\d{2}:\\d{2} mutation Login \\(%c200 OK%c\\) color:${StatusCodeColor.Success} color:inherit$`,
),
),
]),
Expand Down Expand Up @@ -91,7 +91,7 @@ test('prints a log for a GraphQL query intercepted via "graphql.operation"', asy
expect.arrayContaining([
expect.stringMatching(
new RegExp(
`\\[MSW\\] %s %s \\(%c%s%c\\) \\d{2}:\\d{2}:\\d{2} query GetLatestPosts color:${StatusCodeColor.Warning} 301 Moved Permanently color:inherit$`,
`\\[MSW\\] \\d{2}:\\d{2}:\\d{2} query GetLatestPosts \\(%c301 Moved Permanently%c\\) color:${StatusCodeColor.Warning} color:inherit$`,
),
),
]),
Expand Down Expand Up @@ -122,7 +122,7 @@ test('prints a log for a GraphQL mutation intercepted via "graphql.operation"',
expect.arrayContaining([
expect.stringMatching(
new RegExp(
`\\[MSW\\] %s %s \\(%c%s%c\\) \\d{2}:\\d{2}:\\d{2} mutation CreatePost color:${StatusCodeColor.Warning} 301 Moved Permanently color:inherit$`,
`^\\[MSW\\] \\d{2}:\\d{2}:\\d{2} mutation CreatePost \\(%c301 Moved Permanently%c\\) color:${StatusCodeColor.Warning} color:inherit$`,
),
),
]),
Expand Down
4 changes: 2 additions & 2 deletions test/browser/rest-api/logging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ test('prints the intercepted request info into browser console', async ({
await fetch('https://example.com/users/octocat')

await waitFor(() => {
expect(consoleSpy.get('raw')?.get('startGroupCollapsed')).toEqual(
expect(consoleSpy.get('raw')!.get('startGroupCollapsed')).toEqual(
expect.arrayContaining([
expect.stringMatching(
new RegExp(
`^\\[MSW\\] %s %s %s \\(%c%s%c\\) \\d{2}:\\d{2}:\\d{2} GET https://example.com/users/octocat color:${StatusCodeColor.Success} 200 OK color:inherit$`,
`^\\[MSW\\] \\d{2}:\\d{2}:\\d{2} GET https://example.com/users/octocat \\(%c200 OK%c\\) color:${StatusCodeColor.Success} color:inherit$`,
),
),
]),
Expand Down
Loading