-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
test_runner: support object property mocking #58438
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
Conversation
Review requested:
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #58438 +/- ##
==========================================
+ Coverage 90.20% 90.22% +0.01%
==========================================
Files 635 635
Lines 187174 187774 +600
Branches 36751 36866 +115
==========================================
+ Hits 168846 169421 +575
- Misses 11120 11126 +6
- Partials 7208 7227 +19
🚀 New features to boost your workflow:
|
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.
Thanks for working on this. I think this is a good start, but I'd like to see it more unified with the rest of the mocking framework (particularly mock.method()
since the use case is so similar)
Thanks for the thorough review! 😃 |
…provided and rename property mock tests to align with the ones in `test-runner-mocking.js`.
Hey, welcome @idango10 nice seeing you around here, I trust Colin and agree with his feedback. |
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 looking pretty good to me. Two notes:
- It doesn't appear that a
mockImplementationOnce()
equivalent is implemented. - Can we add a test for explicitly mocking a property as
undefined
. This will definitely come up eventually, and I don't think the current implementation can support it. It might take a little bit of work to distinguish between the "explicitundefined
" and "use the previously existing value" use cases.
…d not passing value parameter at all and add test for undefined mock property value
|
Personally, I would just let it apply to both sets and gets and document the caveat you mentioned here. We could make it only apply to gets, but that would be inconsistent with how the rest of the implementation works and we would still need to document that caveat. |
…r single invocation behavior
I added |
doc/api/test.md
Outdated
* `object` {Object} The object whose value is being mocked. | ||
* `propertyName` {string|symbol} The identifier of the property on `object` to mock. | ||
* `value` {any} An optional value used as the mock value | ||
for `object[valueName]`. **Default:** The original property value. |
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.
for `object[valueName]`. **Default:** The original property value. | |
for `object[propertyName]`. **Default:** The original property value. |
valueName -> propertyName
Hey @cjihrig, hope you're doing well! Sorry to ping you, but I wanted to check if you've had a chance to look at my latest changes. Please let me know if anything needs tweaking. Thanks a lot! |
it seems like the API just takes a value - what about getters/setters, enumerability, writability? |
The
notable-change
Please suggest a text for the release notes if you'd like to include a more detailed summary, then proceed to update the PR description with the text or a link to the notable change suggested text comment. Otherwise, the commit will be placed in the Other Notable Changes section. |
Mocking a value for testing why would modification of property descriptors be desirable? |
Landed in 905a722 |
@peteduel because enumerability and writability are all things that should be tested? |
PR-URL: nodejs#58438 Fixes: nodejs#58322 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
PR-URL: #58438 Fixes: #58322 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
Notable changes: doc: * add islandryu to collaborators (Shima Ryuhei) #58714 fs: * (SEMVER-MINOR) allow correct handling of burst in fs-events with AsyncIterator (Philipp Dunkel) #58490 module: * (SEMVER-MINOR) remove experimental warning from type stripping (Marco Ippolito) #58643 test_runner: * (SEMVER-MINOR) support object property mocking (Idan Goshen) #58438 url: * (SEMVER-MINOR) add fileURLToPathBuffer API (James M Snell) #58700 PR-URL: #58727
Notable changes: doc: * add islandryu to collaborators (Shima Ryuhei) #58714 fs: * (SEMVER-MINOR) allow correct handling of burst in fs-events with AsyncIterator (Philipp Dunkel) #58490 module: * (SEMVER-MINOR) remove experimental warning from type stripping (Marco Ippolito) #58643 test_runner: * (SEMVER-MINOR) support object property mocking (Idan Goshen) #58438 url: * (SEMVER-MINOR) add fileURLToPathBuffer API (James M Snell) #58700 PR-URL: #58804
Notable changes: doc: * add islandryu to collaborators (Shima Ryuhei) #58714 fs: * (SEMVER-MINOR) allow correct handling of burst in fs-events with AsyncIterator (Philipp Dunkel) #58490 module: * (SEMVER-MINOR) remove experimental warning from type stripping (Marco Ippolito) #58643 test: * fix test-timeout-flag after revert of auto subtest wait (Pietro Marchini) #58282 test_runner: * Revert "test_runner: remove promises returned by t.test() (Romain Menke) #58282 * Revert "test_runner: remove promises returned by test() (Romain Menke) #58282 * Revert "test_runner: automatically wait for subtests to finish (Romain Menke) #58282 * (SEMVER-MINOR) support object property mocking (Idan Goshen) #58438 url: * (SEMVER-MINOR) add fileURLToPathBuffer API (James M Snell) #58700 PR-URL: #58813
Notable changes: doc: * add islandryu to collaborators (Shima Ryuhei) #58714 fs: * (SEMVER-MINOR) allow correct handling of burst in fs-events with AsyncIterator (Philipp Dunkel) #58490 module: * (SEMVER-MINOR) remove experimental warning from type stripping (Marco Ippolito) #58643 test: * fix test-timeout-flag after revert of auto subtest wait (Pietro Marchini) #58282 test_runner: * (SEMVER-MINOR) support object property mocking (Idan Goshen) #58438 url: * (SEMVER-MINOR) add fileURLToPathBuffer API (James M Snell) #58700 PR-URL: #58813
Notable changes: doc: * add islandryu to collaborators (Shima Ryuhei) #58714 fs: * (SEMVER-MINOR) allow correct handling of burst in fs-events with AsyncIterator (Philipp Dunkel) #58490 module: * (SEMVER-MINOR) remove experimental warning from type stripping (Marco Ippolito) #58643 test: * fix test-timeout-flag after revert of auto subtest wait (Pietro Marchini) #58282 test_runner: * (SEMVER-MINOR) support object property mocking (Idan Goshen) #58438 url: * (SEMVER-MINOR) add fileURLToPathBuffer API (James M Snell) #58700 PR-URL: #58813
PR-URL: #58438 Fixes: #58322 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
Notable changes: crypto: * update root certificates to NSS 3.114 (Node.js GitHub Bot) #59571 deps: * update archs files for openssl-3.5.1 (Node.js GitHub Bot) #59234 * upgrade openssl sources to openssl-3.5.1 (Node.js GitHub Bot) #59234 http: * (SEMVER-MINOR) add Agent.agentKeepAliveTimeoutBuffer option (Haram Jeong) #59315 http2: * (SEMVER-MINOR) add support for raw header arrays in h2Stream.respond() (Tim Perry) #59455 inspector: * add http2 tracking support (Darshan Sen) #59611 sea: * (SEMVER-MINOR) implement execArgvExtension (Joyee Cheung) #59560 * (SEMVER-MINOR) support execArgv in sea config (Joyee Cheung) #59314 stream: * (SEMVER-MINOR) add brotli support to CompressionStream and DecompressionStream (Matthew Aitken) #59464 test_runner: * (SEMVER-MINOR) support object property mocking (Idan Goshen) #58438 worker: * (SEMVER-MINOR) add cpu profile APIs for worker (theanarkh) #59428 PR-URL: #59973
Notable changes: crypto: * update root certificates to NSS 3.114 (Node.js GitHub Bot) #59571 deps: * fix OpenSSL security level at 1 (Richard Lau) #59859 * upgrade openssl sources to openssl-3.5.2 (Node.js GitHub Bot) #59371 doc: * stabilize --disable-sigusr1 (Rafael Gonzaga) #59707 * mark `path.matchesGlob` as stable (Aviv Keller) #59572 http: * (SEMVER-MINOR) add Agent.agentKeepAliveTimeoutBuffer option (Haram Jeong) #59315 http2: * (SEMVER-MINOR) add support for raw header arrays in h2Stream.respond() (Tim Perry) #59455 inspector: * add http2 tracking support (Darshan Sen) #59611 sea: * (SEMVER-MINOR) implement execArgvExtension (Joyee Cheung) #59560 * (SEMVER-MINOR) support execArgv in sea config (Joyee Cheung) #59314 stream: * (SEMVER-MINOR) add brotli support to CompressionStream and DecompressionStream (Matthew Aitken) #59464 test_runner: * (SEMVER-MINOR) support object property mocking (Idan Goshen) #58438 worker: * (SEMVER-MINOR) add cpu profile APIs for worker (theanarkh) #59428 PR-URL: #59973
Notable changes: crypto: * update root certificates to NSS 3.114 (Node.js GitHub Bot) #59571 deps: * fix OpenSSL security level at 1 (Richard Lau) #59859 * upgrade openssl sources to openssl-3.5.2 (Node.js GitHub Bot) #59371 doc: * stabilize --disable-sigusr1 (Rafael Gonzaga) #59707 * mark `path.matchesGlob` as stable (Aviv Keller) #59572 http: * (SEMVER-MINOR) add Agent.agentKeepAliveTimeoutBuffer option (Haram Jeong) #59315 http2: * (SEMVER-MINOR) add support for raw header arrays in h2Stream.respond() (Tim Perry) #59455 inspector: * add http2 tracking support (Darshan Sen) #59611 sea: * (SEMVER-MINOR) implement execArgvExtension (Joyee Cheung) #59560 * (SEMVER-MINOR) support execArgv in sea config (Joyee Cheung) #59314 stream: * (SEMVER-MINOR) add brotli support to CompressionStream and DecompressionStream (Matthew Aitken) #59464 test_runner: * (SEMVER-MINOR) support object property mocking (Idan Goshen) #58438 worker: * (SEMVER-MINOR) add cpu profile APIs for worker (theanarkh) #59428 PR-URL: #59973
Fixes: #58322
This PR adds object property mocking to the test runner.
Example usage: