FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

test_runner: support mocking json modules by JakobJingleheimer · Pull Request #58007 · nodejs/node · GitHub

/ node Public

test_runner: support mocking json modules - #58007

Merged
nodejs-github-bot merged 4 commits into
nodejs:mainfrom
JakobJingleheimer:test_runner/feat/json-module-mock
Apr 26, 2025
Merged

test_runner: support mocking json modules#58007
nodejs-github-bot merged 4 commits into
nodejs:mainfrom
JakobJingleheimer:test_runner/feat/json-module-mock

Conversation

Copy link
Copy Markdown
Member

No description provided.

JakobJingleheimer added the test_runner Issues and PRs related to the test runner subsystem. label Apr 24, 2025

nodejs-github-bot commented Apr 24, 2025
edited by JakobJingleheimer
Loading

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/test_runner

nodejs-github-bot added the needs-ci PRs that need a full CI run. label Apr 24, 2025
JakobJingleheimer force-pushed the test_runner/feat/json-module-mock branch from acca0d8 to 8961496 Compare April 24, 2025 14:50
Comment thread doc/api/test.md
Comment on lines +2199 to +2202
This function is used to mock the exports of ECMAScript modules, CommonJS modules, JSON modules, and
Node.js builtin modules. Any references to the original module prior to mocking are not impacted. In
order to enable module mocking, Node.js must be started with the
[`--experimental-test-module-mocks`][] command-line flag.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The only change here was to add JSON modules,.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Let's minimize the diff

Suggested change
This function is used to mock the exports of ECMAScript modules, CommonJS modules, JSON modules, and
Node.js builtin modules. Any references to the original module prior to mocking are not impacted. In
order to enable module mocking, Node.js must be started with the
[`--experimental-test-module-mocks`][] command-line flag.
This function is used to mock the exports of ECMAScript modules, CommonJS modules, JSON
modules, and Node.js builtin modules. Any references to the original module
prior to mocking are not impacted. In order to enable module mocking, Node.js must
be started with the [`--experimental-test-module-mocks`][] command-line flag.

Comment on lines +128 to +129
case 'json':
format = 'module';

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This is the main change. Creating a nested ternary seemed messy, so I changed this to a switch.

'builtin',
'commonjs-typescript',
'commonjs',
'json',

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Adding 'json', was the only real change here.

Comment thread doc/api/test.md Outdated

Copy link
Copy Markdown
Member

Except for the linting issue: LGTM

Copy link
Copy Markdown
Member Author

Got to it a split-second after you. Could you re-approve since now there has to be at least approval on the most recent commit.

codecov Bot commented Apr 24, 2025
edited
Loading

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.28%. Comparing base (5d15cbb) to head (4e1ed7a).
Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #58007      +/-   ##
==========================================
+ Coverage   90.27%   90.28%   +0.01%     
==========================================
  Files         630      630              
  Lines      186158   186172      +14     
  Branches    36472    36474       +2     
==========================================
+ Hits       168047   168092      +45     
+ Misses      10976    10964      -12     
+ Partials     7135     7116      -19     
Files with missing lines Coverage Δ
lib/internal/test_runner/mock/loader.js 95.67% <100.00%> (+0.15%) ⬆️
lib/internal/test_runner/mock/mock.js 99.26% <100.00%> (+<0.01%) ⬆️

... and 32 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

JakobJingleheimer added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 24, 2025
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 24, 2025

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Collaborator

Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
Comment thread doc/api/test.md
- version:
- REPLACEME
pr-url: https://github.com/nodejs/node/pull/58007
description: Support JSON modules.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

nit

Suggested change
description: Support JSON modules.
description: Add support for JSON modules mocking.

Comment thread doc/api/test.md
Comment on lines +2199 to +2202
This function is used to mock the exports of ECMAScript modules, CommonJS modules, JSON modules, and
Node.js builtin modules. Any references to the original module prior to mocking are not impacted. In
order to enable module mocking, Node.js must be started with the
[`--experimental-test-module-mocks`][] command-line flag.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Let's minimize the diff

Suggested change
This function is used to mock the exports of ECMAScript modules, CommonJS modules, JSON modules, and
Node.js builtin modules. Any references to the original module prior to mocking are not impacted. In
order to enable module mocking, Node.js must be started with the
[`--experimental-test-module-mocks`][] command-line flag.
This function is used to mock the exports of ECMAScript modules, CommonJS modules, JSON
modules, and Node.js builtin modules. Any references to the original module
prior to mocking are not impacted. In order to enable module mocking, Node.js must
be started with the [`--experimental-test-module-mocks`][] command-line flag.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

nit: we could use an existing fixtures JSON file (e.g. test/fixtures/experimental.json), or at least move/rename it to test/fixtures/simple.json so it can be used by other tests

JakobJingleheimer added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 25, 2025
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 25, 2025

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Collaborator

pmarchini added the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Apr 26, 2025
JakobJingleheimer added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Apr 26, 2025
nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 26, 2025
nodejs-github-bot merged commit cf896c3 into nodejs:main Apr 26, 2025

Copy link
Copy Markdown
Collaborator

Landed in cf896c3

JakobJingleheimer deleted the test_runner/feat/json-module-mock branch April 29, 2025 08:19
RafaelGSS pushed a commit that referenced this pull request May 1, 2025
PR-URL: #58007
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
RafaelGSS pushed a commit that referenced this pull request May 2, 2025
PR-URL: #58007
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
aduh95 pushed a commit that referenced this pull request Jun 10, 2025
PR-URL: #58007
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no outstanding review comments, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants


Back | FazBrowse Home | New Git URL