digidem / mapeo-core-next

The upcoming version of Mapeo Core
MIT License
7 stars 1 forks source link

test: use Node's test runner for significant speedup #617

Closed EvanHahn closed 2 months ago

EvanHahn commented 2 months ago

tl;dr: node --test instead of brittle to speed up tests. Only affects the runner; brittle is still imported in tests.

We use Brittle for tests, which has two distinct pieces:

  1. The runner (the brittle command)
  2. The module (the brittle import)

These pieces can be used independently. For example, node /path/to/my-brittle-test.js runs an individual file without using the brittle command; it only uses the brittle module. You can also run brittle /path/to/file.js, which might not import the brittle module.

We eventually want to drop Brittle entirely. We can start with the easier part: dropping the test runner.

node --test is typically used with the node:test module, but it doesn't have to be. From Node's docs:

Test files must be executable by Node.js, but are not required to use the node:test module internally.

This replaces npm run test:unit and npm run test:e2e with node --test. In addition to being a step towards our eventual goal, it is also much faster (presumably because it runs concurrently). On my machine, test:unit goes from about 51 seconds to about 12.5, and test:e2e went from ~2.3 minutes to about ~1.9. On CI, npm test started at 2m24s and is now 1m48s.