Skip to content
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

fetch: wpt tests that are failing #1666

Open
KhafraDev opened this issue Sep 24, 2022 · 7 comments
Open

fetch: wpt tests that are failing #1666

KhafraDev opened this issue Sep 24, 2022 · 7 comments
Labels
fetch good first issue Good for newcomers

Comments

@KhafraDev
Copy link
Member

KhafraDev commented Sep 24, 2022

We check if signal is aborted here:

if (requestObject.signal.aborted) {

and the promise gets rejected here:
p.reject(error)

import { fetch, setGlobalOrigin } from 'undici'
import assert from 'assert'

setGlobalOrigin('http://localhost:3000')

const controller = new AbortController();
const signal = controller.signal;
controller.abort();

const log = [];

await Promise.all([
	fetch('../resources/data.json', { signal }).then(
		() => assert_unreached("Fetch must not resolve"),
		() => log.push('fetch-reject')
	),
	Promise.resolve().then(() => log.push('next-microtask'))
]);

assert.deepStrictEqual(log, ['fetch-reject', 'next-microtask']);

Originally posted by @KhafraDev in #1664 (comment)

@KhafraDev KhafraDev added good first issue Good for newcomers fetch labels Sep 25, 2022
@KhafraDev
Copy link
Member Author

KhafraDev commented Oct 4, 2022

This case also fails:

const request = new Request('https://example.com', { method: 'POST', body: 'body' })
const originalBody = request.body
assert(request.bodyUsed === false)

const otherRequest = new Request(request, { body: 'another body' })
assert(request.bodyUsed === true) // <--- this assert fails
assert(request.body === originalBody)
assert(originalBody !== undefined)
assert(originalBody !== null)
assert(otherRequest.body !== originalBody)

@KhafraDev

This comment has been hidden.

@KhafraDev KhafraDev changed the title fetch: wpt test is failing fetch: wpt tests that are failing Oct 5, 2022
@KhafraDev
Copy link
Member Author

const initialBuffer = new Int8Array(new ArrayBuffer(16))

const stream = new ReadableStream({
  start (controller) {
    controller.enqueue(initialBuffer)
    controller.close()
  }
})
const [out1, out2] = stream.tee()

const { value } = await out2.getReader().read()

console.log(value === initialBuffer) // this should be false

The same subset of tests are failing here (https://staging.wpt.fyi/results/fetch/api/response/response-clone.any.html?label=master&label=experimental&aligned&view=subtest)

The spec makes no mention of cloning the value returned by ReadableStreamDefaultReader.read that I could find. It's likely why this test is failing in most other environments.

@KhafraDev

This comment has been hidden.

@KhafraDev
Copy link
Member Author

KhafraDev commented Oct 11, 2022

Another test fails due to fetch allowing binding of this:

Expected outcomes:

const url = 'https://example.com'

await fetch.call({}, url) // rejects
await fetch.call(undefined, url) // resolves
await fetch.call(globalThis, url) // resolves

The problem is that depending on how undici is imported, the default this can be a few values:

  1. undefined
  2. module
  3. module.exports
  4. some sort of object used when importing; we don't have access to it to compare.

We can't bind the value of this because when logging fetch it would should [Function bound fetch] and, currently, this is already bound to the dispatcher being used in the request.

Imports expected to work:

  1. const { fetch } = require('undici'); fetch(...)
  2. const undici = require('undici'); undici.fetch(...)
  3. import * as undici from 'undici'; undici.fetch(...)
  4. import undici from 'undici'; undici.fetch(...)
  5. import { fetch } from 'undici'; fetch(...)

@mcollina
Copy link
Member

Should we create fetch as a closure instead?

@KhafraDev
Copy link
Member Author

I will experiment with it, but none of my initial attempts got anywhere

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fetch good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants