0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 23:43:09 +01:00
nodejs/test/known_issues/test-url-parse-conformance.js
Joyee Cheung 1357913180
test: use URL fixtures under test/fixtures/wpt/url/resources
Removes the following files:

- test/fixtures/url-tests.js
- test/fixtures/url-setter-tests.js
- test/fixtures/url-toascii.js

in favor of:

- test/fixtures/wpt/url/resources/urltestdata.json
- test/fixtures/wpt/url/resources/setters_tests.json
- test/fixtures/wpt/url/resources/toascii.json

Also removes dependency of `fixtures/url-tests.js` in http2 tests
and use `fixtures/person-large.jpg` instead since they are just
looking for a big enough file to transfer.

PR-URL: https://github.com/nodejs/node/pull/24035
Refs: https://github.com/nodejs/node/issues/23192
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
2018-11-09 20:27:20 +08:00

58 lines
1.8 KiB
JavaScript

'use strict';
// Refs: https://github.com/nodejs/node/issues/5832
require('../common');
const url = require('url');
const assert = require('assert');
const fixtures = require('../common/fixtures');
const tests = require(
fixtures.path('wpt', 'url', 'resources', 'urltestdata.json')
);
let failed = 0;
let attempted = 0;
tests.forEach((test) => {
attempted++;
// Skip comments
if (typeof test === 'string') return;
let parsed;
try {
// Attempt to parse
parsed = url.parse(url.resolve(test.base, test.input));
if (test.failure) {
// If the test was supposed to fail and we didn't get an
// error, treat it as a failure.
failed++;
} else {
// Test was not supposed to fail, so we're good so far. Now
// check the results of the parse.
let username, password;
try {
assert.strictEqual(test.href, parsed.href);
assert.strictEqual(test.protocol, parsed.protocol);
username = parsed.auth ? parsed.auth.split(':', 2)[0] : '';
password = parsed.auth ? parsed.auth.split(':', 2)[1] : '';
assert.strictEqual(test.username, username);
assert.strictEqual(test.password, password);
assert.strictEqual(test.host, parsed.host);
assert.strictEqual(test.hostname, parsed.hostname);
assert.strictEqual(+test.port, +parsed.port);
assert.strictEqual(test.pathname, parsed.pathname || '/');
assert.strictEqual(test.search, parsed.search || '');
assert.strictEqual(test.hash, parsed.hash || '');
} catch {
// For now, we're just interested in the number of failures.
failed++;
}
}
} catch {
// If Parse failed and it wasn't supposed to, treat it as a failure.
if (!test.failure)
failed++;
}
});
assert.ok(failed === 0, `${failed} failed tests (out of ${attempted})`);