summaryrefslogtreecommitdiff
path: root/cli/tests/node_compat/test/parallel/test-whatwg-url-custom-setters.js
diff options
context:
space:
mode:
authorYoshiya Hinosawa <stibium121@gmail.com>2023-02-21 00:35:04 +0900
committerGitHub <noreply@github.com>2023-02-20 16:35:04 +0100
commit6915a9b7a701dde0e1078867961c9a91811c1850 (patch)
treee6822f2b8400c7c7941d3cb9ace59842389b5bc9 /cli/tests/node_compat/test/parallel/test-whatwg-url-custom-setters.js
parenta1cd2a5915c13f6a9b8eafa3807e143a02616bc1 (diff)
test(ext/node): more node compat tests (#17827)
This PR adds the remaining ~650 Node.js compat test cases from std/node. Among these 650 cases, about 130 cases are now failing. These failing cases are prefixed with `TODO:` in `tests/node_compat/config.json`. These will be addressed in later PRs.
Diffstat (limited to 'cli/tests/node_compat/test/parallel/test-whatwg-url-custom-setters.js')
-rw-r--r--cli/tests/node_compat/test/parallel/test-whatwg-url-custom-setters.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/cli/tests/node_compat/test/parallel/test-whatwg-url-custom-setters.js b/cli/tests/node_compat/test/parallel/test-whatwg-url-custom-setters.js
new file mode 100644
index 000000000..c0b4e41bd
--- /dev/null
+++ b/cli/tests/node_compat/test/parallel/test-whatwg-url-custom-setters.js
@@ -0,0 +1,67 @@
+// deno-fmt-ignore-file
+// deno-lint-ignore-file
+
+// Copyright Joyent and Node contributors. All rights reserved. MIT license.
+// Taken from Node 18.12.1
+// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
+
+'use strict';
+
+// Tests below are not from WPT.
+
+const common = require('../common');
+if (!common.hasIntl) {
+ // A handful of the tests fail when ICU is not included.
+ common.skip('missing Intl');
+}
+
+const assert = require('assert');
+const { test, assert_equals } = require('../common/wpt').harness;
+const fixtures = require('../common/fixtures');
+
+// TODO(joyeecheung): we should submit these to the upstream
+const additionalTestCases =
+ require(fixtures.path('url-setter-tests-additional.js'));
+
+{
+ for (const attributeToBeSet in additionalTestCases) {
+ if (attributeToBeSet === 'comment') {
+ continue;
+ }
+ const testCases = additionalTestCases[attributeToBeSet];
+ for (const testCase of testCases) {
+ let name = `Setting <${testCase.href}>.${attributeToBeSet}` +
+ ` = "${testCase.new_value}"`;
+ if ('comment' in testCase) {
+ name += ` ${testCase.comment}`;
+ }
+ test(function() {
+ const url = new URL(testCase.href);
+ url[attributeToBeSet] = testCase.new_value;
+ for (const attribute in testCase.expected) {
+ assert_equals(url[attribute], testCase.expected[attribute]);
+ }
+ }, `URL: ${name}`);
+ }
+ }
+}
+
+{
+ const url = new URL('http://example.com/');
+ const obj = {
+ toString() { throw new Error('toString'); },
+ valueOf() { throw new Error('valueOf'); }
+ };
+ const sym = Symbol();
+ const props = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(url));
+ for (const [name, { set }] of Object.entries(props)) {
+ if (set) {
+ assert.throws(() => url[name] = obj,
+ /^Error: toString$/,
+ `url.${name} = { toString() { throw ... } }`);
+ assert.throws(() => url[name] = sym,
+ /^TypeError: Cannot convert a Symbol value to a string$/,
+ `url.${name} = ${String(sym)}`);
+ }
+ }
+}