Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 7, 2024
Merged

Conversation

EvanHahn
Copy link
Contributor

@EvanHahn EvanHahn commented May 7, 2024

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.

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.

[Brittle]: https://www.npmjs.com/package/brittle
[Node's docs]: https://nodejs.org/docs/latest-v18.x/api/test.html#test-runner-execution-model
@EvanHahn EvanHahn marked this pull request as ready for review May 7, 2024 15:06
@EvanHahn EvanHahn requested a review from achou11 May 7, 2024 15:07
Copy link
Member

@achou11 achou11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@EvanHahn EvanHahn merged commit da4beac into main May 7, 2024
4 checks passed
@EvanHahn EvanHahn deleted the node--test branch May 7, 2024 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants