Skip to content

Commit

Permalink
handle empty app logs
Browse files Browse the repository at this point in the history
  • Loading branch information
raiyaj committed Nov 3, 2022
1 parent 4931b6c commit 0d0ab75
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 2 additions & 4 deletions packages/pwa-kit-dev/bin/pwa-kit-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const pkg = require('../package.json')
const {getConfig} = require('pwa-kit-runtime/utils/ssr-config')

const colors = {
info: 'cyan',
info: 'green',
warn: 'yellow',
error: 'red'
}
Expand Down Expand Up @@ -375,9 +375,7 @@ const main = () => {
console.log(
chalk.green(new Date(log.timestamp).toISOString()),
chalk.cyan(shortRequestId),
['WARN', 'ERROR'].includes(level)
? chalk[colors[level.toLowerCase()]].bold(paddedLevel)
: paddedLevel,
chalk[colors[level.toLowerCase()] || 'green'].bold(paddedLevel),
message
)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/pwa-kit-dev/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ Utils.parseLog = (log) => {
let requestId, shortRequestId, message, level

if (
parts.length > 3 &&
parts.length >= 3 &&
validator.isISO8601(parts[0]) &&
validator.isUUID(parts[1]) &&
validator.isAlpha(parts[2])
Expand Down
8 changes: 8 additions & 0 deletions packages/pwa-kit-dev/scripts/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ test('parseLog parses application and platform logs correctly', () => {
message: 'Response status: 500\tuh oh!',
shortRequestId
}
},
{
log: `2022-10-31T22:00:00.000Z\t${requestId}\tINFO\t`,
expected: {
level: 'INFO',
message: '',
shortRequestId
}
}
]
cases.forEach(({log, expected}) => {
Expand Down

0 comments on commit 0d0ab75

Please sign in to comment.