lib: refactor lazy loading of undici for fetch method by YCChenVictor · Pull Request #52275 · nodejs/node

@nodejs-github-bot added lib / src

Issues and PRs related to general changes in the lib or src directory.

needs-ci

PRs that need a full CI run.

labels

Mar 30, 2024

mcollina

atlowChemi

regseb

@YCChenVictor

Object.defineProperty is updated to lazily load the undici dependency
for the fetch method. This change allows for simpler and more reliable
mocking of the fetch method for testing purposes, resolving issues
encountered with premature method invocation during testing.

Fixes: nodejs#52015

atlowChemi

mcollina

@YCChenVictor

Instead of importing undici upfront, the module is now conditionally
required using require only when the fetch function is called for the
first time and the undici implementation is not already available. This
lazy loading approach improves resource usage and test reliability by
loading undici only when needed.

atlowChemi

@MoLow MoLow added request-ci

Add this label to start a Jenkins CI on a PR.

and removed request-ci

Add this label to start a Jenkins CI on a PR.

labels

Apr 9, 2024

@panva panva added the commit-queue-squash

Add this label to instruct the Commit Queue to squash all the PR commits into the first one.

label

Apr 9, 2024

Ethan-Arrowood

joyeecheung

aduh95 pushed a commit that referenced this pull request

Apr 29, 2024
Object.defineProperty is updated to lazily load the undici dependency
for the fetch method. This change allows for simpler and more reliable
mocking of the fetch method for testing purposes, resolving issues
encountered with premature method invocation during testing.

Fixes: #52015
PR-URL: #52275
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>

marco-ippolito pushed a commit that referenced this pull request

May 2, 2024
Object.defineProperty is updated to lazily load the undici dependency
for the fetch method. This change allows for simpler and more reliable
mocking of the fetch method for testing purposes, resolving issues
encountered with premature method invocation during testing.

Fixes: #52015
PR-URL: #52275
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>

marco-ippolito pushed a commit that referenced this pull request

May 3, 2024
Object.defineProperty is updated to lazily load the undici dependency
for the fetch method. This change allows for simpler and more reliable
mocking of the fetch method for testing purposes, resolving issues
encountered with premature method invocation during testing.

Fixes: #52015
PR-URL: #52275
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>