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

♻️ Migrate core tests to native node test runner #248

Merged
merged 2 commits into from
Mar 7, 2024

Conversation

cowboyd
Copy link
Member

@cowboyd cowboyd commented Mar 7, 2024

Motivation

Mocha is not maintained, monkey patches require(), and mucks with the module loader. Meanwhile, Node has a native test runner that is fast, reliable, and actively maintained as part of the Node JS project.

Approach

This gets rid of ts-node and mocha in favor of tsx and the native runner. Most of the time this involves just importing from node:test instead of mocha.

In cases where mocha was mushing its hooks onto the global scope (beforeEach(), afterEach(), et al.) the function has been explicitly imported from node:test.

TODOs and Open Questions

  • I had to add the --no-deprecation flag to the test script because a library used by tsx is using a library called psi that is apparently using a deprecated node API.

Learning

Node test runner docs: https://nodejs.org/api/test.html

Mocha is not maintained, monkey patches `require()`, and mucks with
the module loader. Meanwhile, Node has a native test runner that is
fast, reliable, and actively maintained as part of the Node JS
project.

This gets rid of `ts-node` and `mocha` in favor of `tsx` and the
native runner. Most of the time this involves just importing from
`node:test` instead of `mocha`.

In cases where `mocha` was mushing its hooks onto the global
scope (`beforeEach()`, `afterEach()`, et al.) the function has been
explicitly imported from `node:test`.
@cowboyd cowboyd requested a review from wKich March 7, 2024 15:53
Copy link

changeset-bot bot commented Mar 7, 2024

⚠️ No Changeset found

Latest commit: 246d417

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

netlify bot commented Mar 7, 2024

Deploy Preview for interactors canceled.

Name Link
🔨 Latest commit 246d417
🔍 Latest deploy log https://app.netlify.com/sites/interactors/deploys/65e9eb91c55f8600075ee741

@cowboyd
Copy link
Member Author

cowboyd commented Mar 7, 2024

I went ahead and updated the remaining packages because it was so easy.

% yarn why mocha
yarn why v1.22.11
[1/4] 🤔  Why do we have the module "mocha"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
error We couldn't find a match!
✨  Done in 0.28s.

@cowboyd cowboyd merged commit 575b1bc into main Mar 7, 2024
6 checks passed
@cowboyd cowboyd deleted the migrate-core-native-test-runner branch March 7, 2024 16:41
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