avajs/eslint-plugin-ava

Rule proposal: Enforce hooks to be at the top of the test file #196

sindresorhus posted onGitHub

It's useful to be able to see the hooks first for readability.

Proposed order: before, after, beforeEach, afterEach, test

Thoughts?


Is there an argument for before, beforeEach, afterEach and after?

What about the .always modifier?

posted by novemberborn over 6 years ago

Is there an argument for before, beforeEach, afterEach and after?

Yes, but I would prefer to sort them by semantic value, not when they are run. before/after are test-wide hooks so they are defined first, then test specific hooks, and then the actual tests. (This is also how we have it sorted in examples in the AVA readme).

What about the .always modifier?

It should be after the hook with the same name without .always. So if you have after.always and after, after should come before after.always.

posted by sindresorhus over 6 years ago

👍 let's do this.

posted by novemberborn over 6 years ago

@issuehunt has funded $60.00 to this issue.


posted by IssueHuntBot almost 6 years ago

What would be the name of such a rule ? hooks-order ?

Hooks can have .serial, .always, .cb and .skip as modifiers, do we care for al ? what should be their effects ? their combined effects ?

Do you agree with this:

// `serial` have priority 1 but before
test.serial.after()
test.serial.after.cb()
test.serial.after.always()
test.serial.after.always.cb()
test.serial.after.skip()
test.serial.after.cb.skip()
test.serial.after.always.skip()
test.serial.after.always.cb.skip()

test.after()

test.after.cb()
test.after.always()
test.after.always.cb()
// `skip` have priority 2
test.after.skip()
test.after.cb.skip()
// `always` have priority 3
test.after.always.skip()
test.after.always.cb.skip() // cb is the least impactful modifier

test()

Other possibility is to prioritize by position on the call test.serial.after.always.cb.skip() (so 1st serial, always, cb then skip)

posted by GMartigny almost 6 years ago

I don't think the concurrency (.serial) or execution method (.cb) are relevant here. AVA already orchestrates those and it's very test suite specific.

posted by novemberborn almost 6 years ago

@sindresorhus has rewarded $54.00 to @mrhen. See it on IssueHunt

  • :moneybag: Total deposit: $60.00
  • :tada: Repository reward(0%): $0.00
  • :wrench: Service fee(10%): $6.00
posted by issuehunt-app[bot] over 5 years ago

Fund this Issue

$60.00
Rewarded

Rewarded pull request

Recent activities

mrhen was rewarded by sindresorhus for avajs/eslint-plugin-ava# 196
over 5 years ago
mrhen submitted an output to  avajs/ eslint-plugin-ava# 196
almost 6 years ago