mirror of
https://github.com/nodejs/node.git
synced 2025-05-09 13:05:07 +00:00

Adds a new `../common/fixtures' module to begin normalizing `test/fixtures` use. Our test code is a bit inconsistent with regards to use of the fixtures directory. Some code uses `path.join()`, some code uses string concats, some other code uses template strings, etc. In mnay cases, significant duplication of code is seen when accessing fixture files, etc. This updates many (but by no means all) of the tests in the test suite to use the new consistent API. There are still many more to update, which would make an excelent Code-n-Learn exercise. PR-URL: https://github.com/nodejs/node/pull/14332 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Michaël Zasso <targos@protonmail.com>
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
if (!common.hasIntl) {
|
|
// A handful of the tests fail when ICU is not included.
|
|
common.skip('missing Intl');
|
|
}
|
|
|
|
const fixtures = require('../common/fixtures');
|
|
const URL = require('url').URL;
|
|
const { test, assert_equals } = require('../common/wpt');
|
|
|
|
const request = {
|
|
response: require(fixtures.path('url-tests'))
|
|
};
|
|
|
|
/* The following tests are copied from WPT. Modifications to them should be
|
|
upstreamed first. Refs:
|
|
https://github.com/w3c/web-platform-tests/blob/8791bed/url/url-origin.html
|
|
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html
|
|
*/
|
|
/* eslint-disable */
|
|
function runURLOriginTests() {
|
|
// var setup = async_test("Loading data…")
|
|
// setup.step(function() {
|
|
// var request = new XMLHttpRequest()
|
|
// request.open("GET", "urltestdata.json")
|
|
// request.send()
|
|
// request.responseType = "json"
|
|
// request.onload = setup.step_func(function() {
|
|
runURLTests(request.response)
|
|
// setup.done()
|
|
// })
|
|
// })
|
|
}
|
|
|
|
function bURL(url, base) {
|
|
return new URL(url, base || "about:blank")
|
|
}
|
|
|
|
function runURLTests(urltests) {
|
|
for(var i = 0, l = urltests.length; i < l; i++) {
|
|
var expected = urltests[i]
|
|
if (typeof expected === "string" || !("origin" in expected)) continue
|
|
test(function() {
|
|
var url = bURL(expected.input, expected.base)
|
|
assert_equals(url.origin, expected.origin, "origin")
|
|
}, "Origin parsing: <" + expected.input + "> against <" + expected.base + ">")
|
|
}
|
|
}
|
|
|
|
runURLOriginTests()
|
|
/* eslint-enable */
|