Skip to content

Commit

Permalink
fix: added global Request object
Browse files Browse the repository at this point in the history
  • Loading branch information
picunada committed Aug 21, 2023
1 parent fe27409 commit 5801297
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ export const fetch =

export const Headers = _globalThis.Headers;

export const Request = _globalThis.Request;

export const ofetch = createFetch({ fetch, Headers });
export const $fetch = ofetch;
7 changes: 6 additions & 1 deletion src/node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import http from "node:http";
import https, { AgentOptions } from "node:https";
import nodeFetch, { Headers as _Headers } from "node-fetch-native";
import nodeFetch, {
Headers as _Headers,
Request as _Request,
} from "node-fetch-native";

import { createFetch } from "./base";

Expand Down Expand Up @@ -34,5 +37,7 @@ export const fetch = globalThis.fetch || createNodeFetch();

export const Headers = globalThis.Headers || _Headers;

export const Request = globalThis.Request || _Request;

export const ofetch = createFetch({ fetch, Headers });
export const $fetch = ofetch;
3 changes: 1 addition & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { Blob } from "fetch-blob";
import { FormData } from "formdata-polyfill/esm.min.js";
import { describe, beforeAll, afterAll, it, expect } from "vitest";
import { Headers, $fetch } from "../src/node";
import { Headers, Request, $fetch } from "../src/node";

describe("ofetch", () => {
let listener;
Expand Down Expand Up @@ -257,7 +257,6 @@ describe("ofetch", () => {
statusCode: 404,
statusMessage: "Cannot find any path matching /404.",
});
console.log(error.request);
expect(error.response?._data).to.deep.eq(error.data);
expect(error.request.url).to.equal(getURL("404"));
});
Expand Down

0 comments on commit 5801297

Please sign in to comment.