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

🚀 Feature: Allow to set timeout on before/after/beforeEach/afterEach in declaration #5202

Open
2 of 3 tasks
perrin4869 opened this issue Aug 27, 2024 · 2 comments · May be fixed by #5231
Open
2 of 3 tasks

🚀 Feature: Allow to set timeout on before/after/beforeEach/afterEach in declaration #5202

perrin4869 opened this issue Aug 27, 2024 · 2 comments · May be fixed by #5231
Labels
status: accepting prs Mocha can use your help with this one! type: feature enhancement proposal

Comments

@perrin4869
Copy link

Feature Request Checklist

Overview

it returns a TestFunction that has a timeout method. This is useful for setting timeouts in slow tests, without needing to define the test code inside a function() {} block.
An analogous feature would be useful for the before/beforeEach/after/afterEach hooks. The current workaround would be:

before(function() {
  this.timeout(3000);
});

Suggested Solution

before/beforeEach/after/afterEach could return a HookFunction, analogous to TestFunction, which has a timeout method. The code above could be rewritten:

before(() => {}).timeout(3000);

Alternatives

None

Additional Info

No response

@perrin4869 perrin4869 added status: in triage a maintainer should (re-)triage (review) this issue type: feature enhancement proposal labels Aug 27, 2024
@JoshuaKGoldberg
Copy link
Member

👍 Agreed, I'm surprised they didn't have this already! This took me a bit to parse through as someone who doesn't use those APIs much. Putting a summary here for clarity...

There are two ways to describe a timeout:

  • this.timeout(...);: allowed for hooks (before(...), etc.) as well as tests (it(...), etc.)
  • test.timeout(...): only allowed for tests

Assuming I'm understanding correctly, this issue is asking to allow hook.timeout(...). Doing so would mirror the test.timeout(...) already allowed.

@JoshuaKGoldberg JoshuaKGoldberg added status: accepting prs Mocha can use your help with this one! and removed status: in triage a maintainer should (re-)triage (review) this issue labels Oct 8, 2024
@perrin4869
Copy link
Author

@JoshuaKGoldberg thanks for summarizing it more clearly than the original post 🙂

ok, I just looked into the codebase, and I think this will be very simple to implement, but I am not sure about potential implications. I will send a PR shortly

@perrin4869 perrin4869 linked a pull request Oct 14, 2024 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Mocha can use your help with this one! type: feature enhancement proposal
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants