Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Apr 1, 2019
1 parent 7f4c98d commit bd80c6e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 45 deletions.
19 changes: 11 additions & 8 deletions test/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ const {
normalizeMessage,
} = require('./helpers')

const snapshotArgs = function([error, level]) {
return [
normalizeMessage(inspect(error), { colors: false }),
String(error.stack),
String(error),
level,
]
}

repeatEvents((prefix, { name, emitEvent }) => {
test(`${prefix} should fire opts.log()`, async t => {
const { stopLogging, log } = startLogging({ log: 'spy' })
Expand Down Expand Up @@ -48,14 +57,8 @@ repeatEvents((prefix, { name, emitEvent }) => {

t.true(log.called)

const [error, level, event] = log.firstCall.args
t.snapshot([
normalizeMessage(inspect(error), { colors: false }),
String(error.stack),
String(error),
level,
event,
])
const snapshot = log.args.flatMap(snapshotArgs)
t.snapshot(snapshot)

stopLogging()

Expand Down
72 changes: 35 additions & 37 deletions test/snapshots/log.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,41 @@ Generated by [AVA](https://ava.li).
Initially resolved with: { success: true }␊
Then rejected with: Error: message`,
'info',
{
name: 'multipleResolves',
nextRejected: true,
nextValue: Error {
message: 'message',
},
rejected: false,
value: {
success: true,
},
},
`i multipleResolves (a promise was resolved multiple times) ␊
Initially resolved with: { success: true }␊
Then resolved again with: { success: true }`,
`MultipleResolves: a promise was resolved multiple times:␊
Initially resolved with: { success: true }␊
Then resolved again with: { success: true }␊
`,
`MultipleResolves: a promise was resolved multiple times:␊
Initially resolved with: { success: true }␊
Then resolved again with: { success: true }`,
'info',
`i multipleResolves (a promise was multiple times) ␊
Initially rejected with: Error: message␊
Then resolved with: { success: true }␊
at STACK TRACE`,
`MultipleResolves: a promise was resolved/rejected multiple times:␊
Initially rejected with: Error: message␊
Then resolved with: { success: true }␊
at STACK TRACE`,
`MultipleResolves: a promise was resolved/rejected multiple times:␊
Initially rejected with: Error: message␊
Then resolved with: { success: true }`,
'info',
`i multipleResolves (a promise was rejected multiple times) ␊
Initially rejected with: Error: message␊
Then rejected again with: Error: message␊
at STACK TRACE`,
`MultipleResolves: a promise was rejected multiple times:␊
Initially rejected with: Error: message␊
Then rejected again with: Error: message␊
at STACK TRACE`,
`MultipleResolves: a promise was rejected multiple times:␊
Initially rejected with: Error: message␊
Then rejected again with: Error: message`,
'info',
]

## [rejectionHandled] should fire opts.log() with arguments
Expand All @@ -45,12 +69,6 @@ Generated by [AVA](https://ava.li).
at STACK TRACE`,
'RejectionHandled: a promise was rejected and handled too late: Error: message',
'error',
{
name: 'rejectionHandled',
value: Error {
message: 'message',
},
},
]

## [uncaughtException] should fire opts.log() with arguments
Expand All @@ -64,12 +82,6 @@ Generated by [AVA](https://ava.li).
at STACK TRACE`,
'UncaughtException: an exception was thrown but not caught: Error: message',
'error',
{
name: 'uncaughtException',
value: Error {
message: 'message',
},
},
]

## [unhandledRejection] should fire opts.log() with arguments
Expand All @@ -83,12 +95,6 @@ Generated by [AVA](https://ava.li).
at STACK TRACE`,
'UnhandledRejection: a promise was rejected but not handled: Error: message',
'error',
{
name: 'unhandledRejection',
value: Error {
message: 'message',
},
},
]

## [warning] should fire opts.log() with arguments
Expand All @@ -105,12 +111,4 @@ Generated by [AVA](https://ava.li).
`Warning: WarningType: message␊
[500] Detail`,
'warn',
{
name: 'warning',
value: WarningType (Error) {
code: '500',
detail: 'Detail',
message: 'message',
},
},
]
Binary file modified test/snapshots/log.js.snap
Binary file not shown.

0 comments on commit bd80c6e

Please sign in to comment.