jonnydgreen / deno-mock-fetch

Deno mock fetch implementation
MIT License
8 stars 0 forks source link

Mock Response Returns with empty "url" #8

Open chilledtonic opened 1 year ago

chilledtonic commented 1 year ago

Describe the bug

When using mock-fetch to intercept a fetch, the response it returns with does not have a "url" field - it returns blank. Example below.

Example Test:

Deno.test("getEndpoint should return the correct endpoint URL", async () => {
  const url = "https://webmention.test/test/1";
  const expectedEndpoint = "https://webmention.test/test/1/webmention";

  mf.intercept(url, { method: "GET" }).response("ok", {
    status: 200,
    headers: { "Link": `<${expectedEndpoint}>; rel="webmention"` },
  });

  const endpoint = await getEndpoint(url);

  console.log(endpoint);
  assertEquals(endpoint, expectedEndpoint);
});

Example Response:

Response {
  body: ReadableStream { locked: false },
  bodyUsed: false,
  headers: Headers {
  "content-type": "text/plain;charset=UTF-8",
  link: '<https://webmention.test/test/1/webmention>; rel="webmention"'
},
  ok: true,
  redirected: false,
  status: 200,
  statusText: "",
  url: ""
}

Expected behaviour According to the MSN Docs, the url field should include the final url after any and all redirects (Redirects which could be simulated using the mock library, say). Instead, it comes up completely empty.

I've noticed other mock fetch libraries (namely this one) also have this issue - is this an intended result and I'm just misunderstanding the URL field?

Thanks.

jonnydgreen commented 1 year ago

Hey @chilledtonic - thanks for submitting this issue and sorry for my delayed reply, I was on holiday last week! Yeah it definitely looks like the URL should be populated - I'll double check this tomorrow! If confirmed as a bug, would you be interested in contributing a PR to fix this?

chilledtonic commented 1 year ago

Hey @chilledtonic - thanks for submitting this issue and sorry for my delayed reply, I was on holiday last week!

No worries at all, it's no crisis - I'm actually also on Holiday right now!

Yeah it definitely looks like the URL should be populated - I'll double check this tomorrow! If confirmed as a bug, would you be interested in contributing a PR to fix this?

I'd be happy to contribute. I'll read up on the docs and get back to you. Thanks.

jonnydgreen commented 1 year ago

I'd be happy to contribute. I'll read up on the docs and get back to you. Thanks.

Awesome! Any questions, give me a shout :)

jonnydgreen commented 1 year ago

If confirmed as a bug,

And to confirm, this is a bug - good spot!