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(beforeEach and afterEach): show proper callback name #490

Merged
merged 1 commit into from
Jul 1, 2024
Merged
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
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
Loading