Support nested groups?
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description
Currently the test files support a flat list of tests, each sharing all `before` , `beforeEach`, `afterEach` & `after` hooks. I find it useful to declare nested groups with their own hooks, while inheriting context from the parent.
For example I'm stubbing promise behavior and need to write test for if the promise is fulfilled or if it's rejected. Ideally I could do something like:
``` js
test.beforeEach(t => {
t.context.behavior = sinon.stub({ getPromise () })
// Return a pending promise
t.context.behavior.getPromise.returns(new Promise(() => {}))
})
// Add optional title
test.group('promise is fulfilled', () => {
test.beforeEach(t => {
t.context.behavior.getPromise.returns(Promise.resolve(true))
})
test(async () => {
const value = await t.context.behavior.getPromise()
t.true(value)
})
})
test.group('promise is rejected', () => {
// You get the idea…
})
```
Each group would maintain its own list of hooks. Hooks could be inherited from the parent group at runtime or when initializing. There would be a root group for the test file itself.
This would allow building alternative test interfaces alongside AVA.
I'd be happy to try and do a PR for this if there's interest.
---
P.S. AVA looks really intriguing! Test runners could do with some shaking up :+1:
Contributor guide
Research direction
Start with the issue's nested test.group example and review AVA's test registration and before/beforeEach/afterEach/after hook handling. The work is done when nested groups have their own hooks, inherit parent context and hooks as intended, support optional titles, and preserve the existing test interface.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100