import { _internals } from "https://deno.land/x/serpapi@0.0.8/src/utils.ts";
This _internals
object is needed to support stubbing/spying of
fetch, execute and getBaseUrl.
https://deno.land/manual@v1.28.3/basics/testing/mocking
If fetch is stubbed via globalThis
, the test phase of the npm build fails.
const fetchStub = stub(globalThis, "fetch", resolvesNext([new Response("data")]));
dnt
shims fetch
by relying on the
undici
package. It replaces all references to fetch
with dntShim.fetch
.
As a side effect, stubbing globalThis.fetch
becomes incorrect; we want to
stub dntShim.fetch
instead.
As a workaround, the _internals
object serves as an indirection and we
stub the fetch
key of this object instead.