Skip to content

Commit

Permalink
fix(beforeEach and afterEach): show proper callback name (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
wellwelwel committed Jul 1, 2024
1 parent 81a8e8d commit 812744d
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/services/each.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,21 @@ const eachCore = async (

const cb = configs[type];

/* c8 ignore next 3 */
if (typeof cb !== 'function') {
return true;
}
const cbName = cb.name !== type ? cb.name : 'anonymous function';

/* c8 ignore start */
Write.log(
` ${format('◯').dim().info()} ${format(
`${cb}: ${cb.name || 'anonymous function'}`
)
` ${format('◯').dim().info()} ${format(`${type}: ${cbName}`)
.dim()
.italic()}`
);
/* c8 ignore stop */

try {
const resultCb = cb();

if (resultCb instanceof Promise) {
await resultCb;
}
await cb();

return true;
} catch (error) {
Write.log(
format(` ✘ ${type} callback failed ${format(`› ${cb}`).dim()}`)
format(` ✘ ${type} callback failed ${format(`› ${cbName}`).dim()}`)
.fail()
.bold()
);
Expand Down

0 comments on commit 812744d

Please sign in to comment.