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: NodeJS tests using native test runner #32191

Closed
wants to merge 13 commits into from

Conversation

ricardogarim
Copy link
Contributor

With the introduction of Meteor 3 into the project, we now have the opportunity to utilize NodeJS version 20+. This grants us access to the native test runner, allowing us to move away from Jest and thereby enhance the overall performance of our tests.

I've crafted this PR as a draft to propose a discussion on the feasibility of transitioning to the native test runner.

Considering the pros and cons

The simplicity we'll embrace in the project—reducing our dependency count—and the performance gains are both significant points in favor. I've included a benchmark here for comparison among Jest, Mocha, and the native test runner.

Daily coding differences

When it comes to coding tests, the variances between Mocha and the native runner are minimal, primarily in the assertion aspect. Instead of relying on the popular expect, the native runner requires the assert library, as demonstrated in the examples available in the branch's diff. It may take a few minutes to get used of, but once done, the process becomes seamless.

// before
expect(isValidQuery(query, props, ['$or'])).to.be.true;
expect(isValidQuery.errors.length).to.be.equals(0);

// after
assert.strictEqual(isValidQuery(query, props, ['$or']), true);
assert.strictEqual(isValidQuery.errors.length, 0);

An important note is that the native test runner currently lacks support for mocking external modules, though it's in progress. Consequently, we'll have to continue using libraries like proxyquire.

Additionally, since our tests are written in TypeScript, we must select a compiler. Given the usage of swc in other project packages, I've opted to stick with it. This required installing the @swc-node/register library as a devDependency and integrating it into the test execution command line.

What’s next?

With a positive reception from the team, we can begin crafting an action plan. This plan will address how to handle older tests and outline our approach for implementing new ones using the potentially new methodology.

Copy link
Contributor

dionisio-bot bot commented Apr 12, 2024

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

Copy link

changeset-bot bot commented Apr 12, 2024

⚠️ No Changeset found

Latest commit: b345e41

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

@CLAassistant
Copy link

CLAassistant commented Apr 12, 2024

CLA assistant check
All committers have signed the CLA.

@ricardogarim ricardogarim changed the base branch from develop to release-7.0.0 April 12, 2024 02:41
@ricardogarim ricardogarim changed the title Proposal: NodeJS tests using native test runner test: NodeJS tests using native test runner Apr 12, 2024
@ricardogarim ricardogarim changed the base branch from release-7.0.0 to meteor-3.0.0 April 12, 2024 02:44
Implements Node.js native test runner alongside real-world examples. Keeps swc as the compiler as well as proxyquire for module mocking in absence of native support.
@ggazzo ggazzo force-pushed the test/nodejs-native-test-runner branch from c0e79c4 to b345e41 Compare April 12, 2024 22:01
Copy link

codecov bot commented Apr 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.04%. Comparing base (edfc298) to head (b345e41).

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##           meteor-3.0.0   #32191   +/-   ##
=============================================
  Coverage         55.04%   55.04%           
=============================================
  Files              2309     2309           
  Lines             50929    50929           
  Branches          10427    10427           
=============================================
  Hits              28033    28033           
  Misses            20401    20401           
  Partials           2495     2495           
Flag Coverage Δ
unit 75.28% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@ggazzo ggazzo force-pushed the meteor-3.0.0 branch 4 times, most recently from e7c17a2 to 65ca774 Compare April 24, 2024 14:40
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.

None yet

4 participants