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

feat(WPTRunner): parse META tags #1664

Merged
merged 8 commits into from Sep 28, 2022
Merged

feat(WPTRunner): parse META tags #1664

merged 8 commits into from Sep 28, 2022

Conversation

KhafraDev
Copy link
Member

@KhafraDev KhafraDev commented Sep 23, 2022

  • Allows parsing META tags and injecting individual scripts into each test. Example of META tags: https://github.com/web-platform-tests/wpt/blob/master/fetch/api/abort/general.any.js#L1-L5
  • Runs each test in its own Worker.
  • Throws an AbortError DOMException in the body mixin methods if the request has been aborted, rather than a TypeError. This behavior, albeit not mentioned in the spec, is tested for in the WPTs.
  • Supports enabling flaky/expected failures for certain tests.
  • Logs stats (# completed, # succeeded, # failed, etc.) once every test is completed.

@KhafraDev

This comment was marked as outdated.

@KhafraDev
Copy link
Member Author

This test is failing and I'm not really sure how to fix it 😕

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']);

@codecov-commenter
Copy link

codecov-commenter commented Sep 24, 2022

Codecov Report

Base: 94.89% // Head: 94.90% // Increases project coverage by +0.01% 🎉

Coverage data is based on head (ce2c132) compared to base (9c3f34c).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1664      +/-   ##
==========================================
+ Coverage   94.89%   94.90%   +0.01%     
==========================================
  Files          53       53              
  Lines        4803     4813      +10     
==========================================
+ Hits         4558     4568      +10     
  Misses        245      245              
Impacted Files Coverage Δ
lib/fetch/body.js 97.26% <100.00%> (+0.15%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@KhafraDev KhafraDev marked this pull request as ready for review September 24, 2022 15:30
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@KhafraDev
Copy link
Member Author

KhafraDev commented Sep 27, 2022

The throwIfAborted steps in the body mixin methods aren't correct - there's a bug somewhere in undici I haven't managed to figure out just yet. However it could also be fixed in a separate pr as the workaround doesn't seem to cause issues.

edit: the issue is the order in which the promise is resolved/rejected. I don't know how to solve this without breaking the spec.

function createDeferredPromise () {
  let res
  let rej
  const promise = new Promise((resolve, reject) => {
    res = resolve
    rej = reject
  })

  return { promise, resolve: res, reject: rej }
}

async function fetch () {
  const promise = createDeferredPromise()

  queueMicrotask(() => promise.reject(new Error('AbortError')))

  promise.resolve()

  return promise.promise
}

await fetch() // resolves

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ronag ronag merged commit e5ee395 into nodejs:main Sep 28, 2022
@KhafraDev KhafraDev deleted the add-wpt branch September 28, 2022 14:47
metcoder95 pushed a commit to metcoder95/undici that referenced this pull request Dec 26, 2022
* feat(WPTRunner): parse `META` tags

* feat: add more routes

* feat: add /resources/data.json route

* fix(fetch): throw AbortError DOMException on consume if aborted

* fix(fetch): throw AbortError on `.formData()` after abort

* feat: add expected failures & end log

* fix: import DOMException for node 16

* feat: run each test in its own worker & simplify worker
crysmags pushed a commit to crysmags/undici that referenced this pull request Feb 27, 2024
* feat(WPTRunner): parse `META` tags

* feat: add more routes

* feat: add /resources/data.json route

* fix(fetch): throw AbortError DOMException on consume if aborted

* fix(fetch): throw AbortError on `.formData()` after abort

* feat: add expected failures & end log

* fix: import DOMException for node 16

* feat: run each test in its own worker & simplify worker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants