-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
url, test: synchronize web-platform-test url tests #11079
Conversation
54cea70
to
701e92b
Compare
Completed. Request review from @nodejs/url A few tests are out of sync/not sync'ed:
The test data is out of sync too, I've updated There are some tests commented out because we are not compatible yet, the major blocker is #10454 (PR: #10967) and the encoding of space to |
Force pushed because of filename mistakes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a couple nits
https://github.com/w3c/web-platform-tests/blob/8791bed/url/url-origin.html | ||
*/ | ||
function runURLOriginTests() { | ||
// var setup = async_test("Loading data…") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps remove the commented out code sections?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just commenting them out would make it easier to update and easier to compare with the upstream, maybe just me though
test(function() { | ||
var url = bURL(expected.input, expected.base) | ||
assert_equals(url.origin, expected.origin, "origin") | ||
}, "Origin parsing: <" + expected.input + "> against <" + expected.base + ">") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: template string may be better here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just copy-pasting the upstream. I think they don't do ES.Next features for browser compatibility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that's fine then
@@ -0,0 +1,87 @@ | |||
module.exports = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we upstream these to web-platform-tests? I can do it if that'd be easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can give it a try first :D. These test cases don't have base
so is urltestdata.json
the right place to go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. No base is just a base of about:blank, so just add that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks!
assert_equals(url.port, expected.port, "port") | ||
assert_equals(url.pathname, expected.pathname, "pathname") | ||
assert_equals(url.search, expected.search, "search") | ||
// if ("searchParams" in expected) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"??a=b&c=d"
is broken at the moment, can make another PR to skip specific test cases later I think (though the whole condition doesn't have to be commented out. I'll change that)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
test/common.js
Outdated
|
||
// https://github.com/w3c/testharness.js/blob/master/testharness.js | ||
exports.WPT = { | ||
test: (fn) => fn(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather have a more featureful test()
, perhaps one like
(fn, desc) => {
try {
fn();
} catch (err) {
if (err instanceof Error)
err.message = `In ${desc}:\n ${err.message}`;
throw err;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Thanks
Rebased and updated URL search parameters constructor tests to w3c/web-platform-tests/405394a now that #11060 has been merged. EDIT: oops, I mean 405394a for search params tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also the issue of attribution. According to the W3C 3-clause BSD License (the alternative does not allow modification of source), we "must retain the original copyright notice". I don't think we are doing that currently.
@@ -1,52 +1,58 @@ | |||
'use strict'; | |||
|
|||
require('../common'); | |||
const common = require('../common'); | |||
const assert = require('assert'); | |||
const url = require('url'); | |||
const URL = url.URL; | |||
const URLSearchParams = url.URLSearchParams; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can condense these three lines into
const { URL, URLSearchParams } = require('url');
test/common.js
Outdated
}, desc); | ||
}, | ||
assert_array_equals: assert.deepStrictEqual, | ||
assert_unreached: assert.fail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The signature of assert_unreached()
in WPT is (description)
, but assert.fail()
in Node.js is (actual, expected, message, operator)
. Maybe
(description) => assert.fail('reached', 'unreached', `Reached unreachable code: ${description}`, 'is')
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the docs
If message is falsy, the error message is set as the values of actual and expected separated by the provided operator. Otherwise, the error message is the value of message.
Probably just
assert.fail(undefined, undefined, `Reached unreachable code: ${description}`);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joyeecheung, yeah, that'd work as well. IMO the 2 undefined
s look a bit too long to be aesthetically pleasing, but up to you.
@TimothyGu Thanks for catching the copyright notice, looks like url-tests.json is doing that with
So I'll put this in other files too. @jasnell is it the right way to do it? |
Yes, our JSON parsing does not recognize regular javascript style comments so including it in a property like this is good. |
New CI: https://ci.nodejs.org/job/node-test-pull-request/6165/ @TimothyGu Does this LGTY? |
Aborted CI, only |
Landed in 10b687b |
* attributon of WPT in url-setter-tests * add WPT test utilities * synchronize WPT URLSearchParams tests * synchronize WPT url tests * split whatwg-url-inspect test * port historical url tests from WPT * protocol setter and special URLs Refs: web-platform-tests/wpt#4413 Refs: whatwg/url#104 PR-URL: #11079 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
* attributon of WPT in url-setter-tests * add WPT test utilities * synchronize WPT URLSearchParams tests * synchronize WPT url tests * split whatwg-url-inspect test * port historical url tests from WPT * protocol setter and special URLs Refs: web-platform-tests/wpt#4413 Refs: whatwg/url#104 Backport-of: nodejs#11079
* attributon of WPT in url-setter-tests * add WPT test utilities * synchronize WPT URLSearchParams tests * synchronize WPT url tests * split whatwg-url-inspect test * port historical url tests from WPT * protocol setter and special URLs Refs: web-platform-tests/wpt#4413 Refs: whatwg/url#104 Backport-of: nodejs#11079
* attributon of WPT in url-setter-tests * add WPT test utilities * synchronize WPT URLSearchParams tests * synchronize WPT url tests * split whatwg-url-inspect test * port historical url tests from WPT * protocol setter and special URLs Refs: web-platform-tests/wpt#4413 Refs: whatwg/url#104 Backport-of: #11079
* attributon of WPT in url-setter-tests * add WPT test utilities * synchronize WPT URLSearchParams tests * synchronize WPT url tests * split whatwg-url-inspect test * port historical url tests from WPT * protocol setter and special URLs Refs: web-platform-tests/wpt#4413 Refs: whatwg/url#104 PR-URL: nodejs#11079 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
This is still a WIP, I'll update all the URLSearchParams tests first, then see how we can synchronize other tests. But I would like to get some feedback from @nodejs/url just to make sure I'm on the right direction.This is an attempt to synchronize the tests of our WHATWG URL implementation with the tests in https://github.com/w3c/web-platform-tests/tree/master/url. #9484 ported some of the URLSearchParams tests into our code base, but it is somewhat hard to see how up-to-date we are compared with the upstream tests.
In this PR, the upstream tests are placed like this
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test, url-whatwg