-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
test_runner: support mocking json modules #58007
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
base: main
Are you sure you want to change the base?
test_runner: support mocking json modules #58007
Conversation
Review requested:
|
acca0d8
to
8961496
Compare
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only change here was to add JSON modules,
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's minimize the diff
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. |
case 'json': | ||
format = 'module'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main change. Creating a nested ternary seemed messy, so I changed this to a switch.
'builtin', | ||
'commonjs-typescript', | ||
'commonjs', | ||
'json', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding 'json',
was the only real change here.
Except for the linting issue: LGTM |
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 ReportAll modified and coverable lines are covered by tests ✅
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
🚀 New features to boost your workflow:
|
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
- version: | ||
- REPLACEME | ||
pr-url: https://github.com/nodejs/node/pull/58007 | ||
description: Support JSON modules. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
description: Support JSON modules. | |
description: Add support for JSON modules mocking. |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's minimize the diff
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
No description provided.