Opened 7 months ago

Last modified 3 months ago

#6820 new change

Investigate moving away from nodeunit for tests

Reported by: hfiguiere Assignee:
Priority: Unknown Milestone:
Module: Core Keywords:
Cc: greiner, erikvold, sebastian Blocked By:
Blocking: Platform: Unknown / Cross platform
Ready: no Confidential: no
Tester: Unknown Verified working: no
Review URL(s):

Description (last modified by hfiguiere)

Background

adblockpluscore uses nodeunit for the testing framework. In May 2018, the package has been marked as deprecated:
https://github.com/caolan/nodeunit/commit/ec2ea882bfb7976c91a25256f855c153594d1b8c

While this doesn't stop it from working, it is a clear indication that it may break in the future.

What to change

  • Evaluate a framework replacement
  • Update the tests to use that framework

Note

  • adblockpluschrome uses qunit with mocha.

Change History (6)

comment:1 Changed 7 months ago by greiner

  • Cc greiner added

comment:2 Changed 5 months ago by erikvold

  • Cc erikvold added

comment:3 Changed 5 months ago by hfiguiere

  • Description modified (diff)

comment:4 Changed 5 months ago by sebastian

  • Cc sebastian added

See #6884 for the migration from nodeunit to Mocha in adblockpluschrome, and the reasons for that decision (besides nodeunit being deprecated).

FWIW, I'm not a huge fan of Mocha, but I chose it because (unlike nodeunit) it does the job, and it seems to be the most popular test framework in Node.js environments at the moment.

Where it shines:

  • It works great for testing asynchronous code (with minimal boilerplate). Tests (and hooks) can simply return a promise, and if the promise is rejected, it will report a failure.
    • nodeunit on the other hand doesn't know anything about promises and you have to make sure to call the provided callback if your async test is done, after manually asserting that any promise involved is resolved successfully. Even worse, once the first test fails the process terminates immediately, while asynchronous cleanup tasks might still be pending.
  • You can group tests together, and have hooks that run either before/after each test in the group, or once before/after all tests in the group.
    • nodeunit on the other hand can only run setup and teardown code for each test, which makes it impossible to share resources across multiple tests.

What I personally dislike:

  • The API involves a little too much magic for my taste. You pass a function that defines tests (and hooks) by passing more functions around, and the way to configure stuff (e.g. timeouts) or to share state is through a shared object that is bound to this in those functions.
  • If you don't do BDD, the terminology used in the API appears a little weird. You call describe() in order to define a group of tests, you call it() in order to define a test case.
  • It doesn't report (multiple) successful assertions. As long as there is no error (failed assertion, other thrown exception or rejected promise), the test is simply marked as passed.
Last edited 5 months ago by sebastian (previous) (diff)

comment:5 Changed 3 months ago by erikvold

Here is a list of the common ones that I have seen used (sorted by currently most popular to least):

I like ava fwiw.

Note: See TracTickets for help on using tickets.