Update linting rules to no longer force arrow functions in mocha tests
Background
In our tests, we currently tend to use arrow functions for the test bodies. This is also one of the linting rules we have, to prefer-arrow-callback.
This is discouraged in Mocha's documentation, since Mocha uses this
for its context. Without this
, you can't do things like increase a test's timeout or mark the test as pending.
In adblockpluscore
, the "prefer-arrow-callback" lint is disabled for tests to allow following Mocha's recommendation, so making this change would also align the linting rules between core and webext.
There is an eslint plugin to add additional mocha rules, including a mocha-aware version of "prefer-arrow-callback", but it currently has an issue which causes it to fail on Node 17 onwards.
Use case
- Tests that modify timeout need to change the type of function to avoid confusing errors.
What to change
- Update the linting rules to no longer prefer arrow functions in tests
- Change all calls of
describe
andit
to use a traditionalfunction()
orasync function()
body, and not an arrow function.
Edited by Justin Wernick