summaryrefslogtreecommitdiff
path: root/tests/node_compat/test/parallel
diff options
context:
space:
mode:
Diffstat (limited to 'tests/node_compat/test/parallel')
-rw-r--r--tests/node_compat/test/parallel/test-buffer-no-negative-allocation.js3
-rw-r--r--tests/node_compat/test/parallel/test-buffer-over-max-length.js13
-rw-r--r--tests/node_compat/test/parallel/test-buffer-slice.js4
-rw-r--r--tests/node_compat/test/parallel/test-buffer-slow.js3
-rw-r--r--tests/node_compat/test/parallel/test-buffer-tostring-rangeerror.js18
-rw-r--r--tests/node_compat/test/parallel/test-console-table.js130
-rw-r--r--tests/node_compat/test/parallel/test-diagnostics-channel-pub-sub.js7
-rw-r--r--tests/node_compat/test/parallel/test-event-emitter-emit-context.js2
-rw-r--r--tests/node_compat/test/parallel/test-event-emitter-error-monitor.js2
-rw-r--r--tests/node_compat/test/parallel/test-file-write-stream.js3
-rw-r--r--tests/node_compat/test/parallel/test-file-write-stream2.js3
-rw-r--r--tests/node_compat/test/parallel/test-file-write-stream3.js3
-rw-r--r--tests/node_compat/test/parallel/test-file-write-stream4.js3
-rw-r--r--tests/node_compat/test/parallel/test-fs-access.js39
-rw-r--r--tests/node_compat/test/parallel/test-fs-append-file-sync.js11
-rw-r--r--tests/node_compat/test/parallel/test-fs-copyfile.js3
-rw-r--r--tests/node_compat/test/parallel/test-fs-open-flags.js3
-rw-r--r--tests/node_compat/test/parallel/test-fs-open-mode-mask.js5
-rw-r--r--tests/node_compat/test/parallel/test-fs-open-numeric-flags.js3
-rw-r--r--tests/node_compat/test/parallel/test-fs-read-stream-autoClose.js3
-rw-r--r--tests/node_compat/test/parallel/test-fs-read-stream-fd.js3
-rw-r--r--tests/node_compat/test/parallel/test-fs-read-stream-inherit.js18
-rw-r--r--tests/node_compat/test/parallel/test-fs-read.js2
-rw-r--r--tests/node_compat/test/parallel/test-fs-readv-sync.js3
-rw-r--r--tests/node_compat/test/parallel/test-fs-readv.js3
-rw-r--r--tests/node_compat/test/parallel/test-fs-rmdir-recursive-sync-warns-not-found.js3
-rw-r--r--tests/node_compat/test/parallel/test-fs-rmdir-recursive-sync-warns-on-file.js3
-rw-r--r--tests/node_compat/test/parallel/test-fs-rmdir-recursive-throws-not-found.js7
-rw-r--r--tests/node_compat/test/parallel/test-fs-rmdir-recursive-throws-on-file.js7
-rw-r--r--tests/node_compat/test/parallel/test-fs-rmdir-recursive-warns-not-found.js3
-rw-r--r--tests/node_compat/test/parallel/test-fs-rmdir-recursive-warns-on-file.js3
-rw-r--r--tests/node_compat/test/parallel/test-fs-watchfile.js8
-rw-r--r--tests/node_compat/test/parallel/test-fs-write-buffer.js17
-rw-r--r--tests/node_compat/test/parallel/test-fs-write-file-buffer.js3
-rw-r--r--tests/node_compat/test/parallel/test-fs-write-file-invalid-path.js5
-rw-r--r--tests/node_compat/test/parallel/test-fs-write-file-sync.js53
-rw-r--r--tests/node_compat/test/parallel/test-fs-write-stream-autoclose-option.js3
-rw-r--r--tests/node_compat/test/parallel/test-fs-write-stream-close-without-callback.js3
-rw-r--r--tests/node_compat/test/parallel/test-fs-write-stream-double-close.js7
-rw-r--r--tests/node_compat/test/parallel/test-fs-write-stream-end.js7
-rw-r--r--tests/node_compat/test/parallel/test-fs-write-stream-fs.js5
-rw-r--r--tests/node_compat/test/parallel/test-fs-write-stream-throw-type-error.js3
-rw-r--r--tests/node_compat/test/parallel/test-fs-write-stream.js3
-rw-r--r--tests/node_compat/test/parallel/test-fs-write-sync.js3
-rw-r--r--tests/node_compat/test/parallel/test-fs-write.js40
-rw-r--r--tests/node_compat/test/parallel/test-fs-writev-sync.js3
-rw-r--r--tests/node_compat/test/parallel/test-http-agent-getname.js3
-rw-r--r--tests/node_compat/test/parallel/test-http-outgoing-internal-headernames-getter.js2
-rw-r--r--tests/node_compat/test/parallel/test-http-url.parse-only-support-http-https-protocol.js4
-rw-r--r--tests/node_compat/test/parallel/test-net-isipv4.js8
-rw-r--r--tests/node_compat/test/parallel/test-net-isipv6.js8
-rw-r--r--tests/node_compat/test/parallel/test-parse-args.mjs6
-rw-r--r--tests/node_compat/test/parallel/test-path-extname.js29
-rw-r--r--tests/node_compat/test/parallel/test-path-parse-format.js4
-rw-r--r--tests/node_compat/test/parallel/test-path.js8
-rw-r--r--tests/node_compat/test/parallel/test-readline-keys.js4
-rw-r--r--tests/node_compat/test/parallel/test-stream-buffer-list.js91
-rw-r--r--tests/node_compat/test/parallel/test-stream-readable-destroy.js2
-rw-r--r--tests/node_compat/test/parallel/test-stream-uint8array.js2
-rw-r--r--tests/node_compat/test/parallel/test-stream-writable-decoded-encoding.js47
-rw-r--r--tests/node_compat/test/parallel/test-stream-writable-end-cb-error.js2
-rw-r--r--tests/node_compat/test/parallel/test-stream2-readable-from-list.js108
-rw-r--r--tests/node_compat/test/parallel/test-stream2-writable.js11
-rw-r--r--tests/node_compat/test/parallel/test-url-format-whatwg.js5
-rw-r--r--tests/node_compat/test/parallel/test-url-parse-invalid-input.js30
-rw-r--r--tests/node_compat/test/parallel/test-url-parse-query.js2
-rw-r--r--tests/node_compat/test/parallel/test-url-pathtofileurl.js37
-rw-r--r--tests/node_compat/test/parallel/test-url-relative.js25
-rw-r--r--tests/node_compat/test/parallel/test-whatwg-events-add-event-listener-options-signal.js9
69 files changed, 420 insertions, 506 deletions
diff --git a/tests/node_compat/test/parallel/test-buffer-no-negative-allocation.js b/tests/node_compat/test/parallel/test-buffer-no-negative-allocation.js
index 27ccf90db..a679f26bb 100644
--- a/tests/node_compat/test/parallel/test-buffer-no-negative-allocation.js
+++ b/tests/node_compat/test/parallel/test-buffer-no-negative-allocation.js
@@ -12,9 +12,8 @@ const assert = require('assert');
const { SlowBuffer } = require('buffer');
const msg = {
- code: 'ERR_INVALID_ARG_VALUE',
+ code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
- message: /^The argument 'size' is invalid\. Received [^"]*$/
};
// Test that negative Buffer length inputs throw errors.
diff --git a/tests/node_compat/test/parallel/test-buffer-over-max-length.js b/tests/node_compat/test/parallel/test-buffer-over-max-length.js
index 5737ad873..c53a9d611 100644
--- a/tests/node_compat/test/parallel/test-buffer-over-max-length.js
+++ b/tests/node_compat/test/parallel/test-buffer-over-max-length.js
@@ -15,23 +15,12 @@ const SlowBuffer = buffer.SlowBuffer;
const kMaxLength = buffer.kMaxLength;
const bufferMaxSizeMsg = {
- code: 'ERR_INVALID_ARG_VALUE',
+ code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
- message: /^The argument 'size' is invalid\. Received [^"]*$/
};
-assert.throws(() => Buffer((-1 >>> 0) + 2), bufferMaxSizeMsg);
-assert.throws(() => SlowBuffer((-1 >>> 0) + 2), bufferMaxSizeMsg);
-assert.throws(() => Buffer.alloc((-1 >>> 0) + 2), bufferMaxSizeMsg);
-assert.throws(() => Buffer.allocUnsafe((-1 >>> 0) + 2), bufferMaxSizeMsg);
-assert.throws(() => Buffer.allocUnsafeSlow((-1 >>> 0) + 2), bufferMaxSizeMsg);
-
assert.throws(() => Buffer(kMaxLength + 1), bufferMaxSizeMsg);
assert.throws(() => SlowBuffer(kMaxLength + 1), bufferMaxSizeMsg);
assert.throws(() => Buffer.alloc(kMaxLength + 1), bufferMaxSizeMsg);
assert.throws(() => Buffer.allocUnsafe(kMaxLength + 1), bufferMaxSizeMsg);
assert.throws(() => Buffer.allocUnsafeSlow(kMaxLength + 1), bufferMaxSizeMsg);
-
-// issue GH-4331
-assert.throws(() => Buffer.allocUnsafe(0x100000001), bufferMaxSizeMsg);
-assert.throws(() => Buffer.allocUnsafe(0xFFFFFFFFF), bufferMaxSizeMsg);
diff --git a/tests/node_compat/test/parallel/test-buffer-slice.js b/tests/node_compat/test/parallel/test-buffer-slice.js
index 1ae0c105a..bd3e8bbb4 100644
--- a/tests/node_compat/test/parallel/test-buffer-slice.js
+++ b/tests/node_compat/test/parallel/test-buffer-slice.js
@@ -78,9 +78,9 @@ for (let i = 0, s = buf.toString(); i < buf.length; ++i) {
);
}
-expectedSameBufs.forEach(([buf1, buf2]) => {
+for (const [buf1, buf2] of expectedSameBufs) {
assert.strictEqual(Buffer.compare(buf1, buf2), 0);
-});
+}
const utf16Buf = Buffer.from('0123456789', 'utf16le');
assert.deepStrictEqual(utf16Buf.slice(0, 6), Buffer.from('012', 'utf16le'));
diff --git a/tests/node_compat/test/parallel/test-buffer-slow.js b/tests/node_compat/test/parallel/test-buffer-slow.js
index b10c4c6db..577a92a9f 100644
--- a/tests/node_compat/test/parallel/test-buffer-slow.js
+++ b/tests/node_compat/test/parallel/test-buffer-slow.js
@@ -59,9 +59,8 @@ assert.throws(() => SlowBuffer(true), bufferInvalidTypeMsg);
// Should throw with invalid length value
const bufferMaxSizeMsg = {
- code: 'ERR_INVALID_ARG_VALUE',
+ code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
- message: /^The argument 'size' is invalid\. Received [^"]*$/
};
assert.throws(() => SlowBuffer(NaN), bufferMaxSizeMsg);
assert.throws(() => SlowBuffer(Infinity), bufferMaxSizeMsg);
diff --git a/tests/node_compat/test/parallel/test-buffer-tostring-rangeerror.js b/tests/node_compat/test/parallel/test-buffer-tostring-rangeerror.js
index dbc69747e..9ec11056c 100644
--- a/tests/node_compat/test/parallel/test-buffer-tostring-rangeerror.js
+++ b/tests/node_compat/test/parallel/test-buffer-tostring-rangeerror.js
@@ -8,18 +8,22 @@
'use strict';
require('../common');
-// This test ensures that Node.js throws a RangeError when trying to convert a
-// gigantic buffer into a string.
+// This test ensures that Node.js throws an Error when trying to convert a
+// large buffer into a string.
// Regression test for https://github.com/nodejs/node/issues/649.
const assert = require('assert');
-const SlowBuffer = require('buffer').SlowBuffer;
+const {
+ SlowBuffer,
+ constants: {
+ MAX_STRING_LENGTH,
+ },
+} = require('buffer');
-const len = 1422561062959;
+const len = MAX_STRING_LENGTH + 1;
const message = {
- code: 'ERR_INVALID_ARG_VALUE',
- name: 'RangeError',
- message: /^The argument 'size' is invalid\. Received [^"]*$/
+ code: 'ERR_STRING_TOO_LONG',
+ name: 'Error',
};
assert.throws(() => Buffer(len).toString('utf8'), message);
assert.throws(() => SlowBuffer(len).toString('utf8'), message);
diff --git a/tests/node_compat/test/parallel/test-console-table.js b/tests/node_compat/test/parallel/test-console-table.js
index da3c66032..991521e8e 100644
--- a/tests/node_compat/test/parallel/test-console-table.js
+++ b/tests/node_compat/test/parallel/test-console-table.js
@@ -45,19 +45,19 @@ test([1, 2, 3], `
┌─────────┬────────┐
│ (index) │ Values │
├─────────┼────────┤
-│ 0 │ 1 │
-│ 1 │ 2 │
-│ 2 │ 3 │
+│ 0 │ 1 │
+│ 1 │ 2 │
+│ 2 │ 3 │
└─────────┴────────┘
`);
test([Symbol(), 5, [10]], `
┌─────────┬────┬──────────┐
-│ (index) │ 0 │ Values │
+│ (index) │ 0 │ Values │
├─────────┼────┼──────────┤
-│ 0 │ │ Symbol() │
-│ 1 │ │ 5 │
-│ 2 │ 10 │ │
+│ 0 │ │ Symbol() │
+│ 1 │ │ 5 │
+│ 2 │ 10 │ │
└─────────┴────┴──────────┘
`);
@@ -65,46 +65,46 @@ test([null, 5], `
┌─────────┬────────┐
│ (index) │ Values │
├─────────┼────────┤
-│ 0 │ null │
-│ 1 │ 5 │
+│ 0 │ null │
+│ 1 │ 5 │
└─────────┴────────┘
`);
test([undefined, 5], `
┌─────────┬───────────┐
-│ (index) │ Values │
+│ (index) │ Values │
├─────────┼───────────┤
-│ 0 │ undefined │
-│ 1 │ 5 │
+│ 0 │ undefined │
+│ 1 │ 5 │
└─────────┴───────────┘
`);
test({ a: 1, b: Symbol(), c: [10] }, `
┌─────────┬────┬──────────┐
-│ (index) │ 0 │ Values │
+│ (index) │ 0 │ Values │
├─────────┼────┼──────────┤
-│ a │ │ 1 │
-│ b │ │ Symbol() │
-│ c │ 10 │ │
+│ a │ │ 1 │
+│ b │ │ Symbol() │
+│ c │ 10 │ │
└─────────┴────┴──────────┘
`);
test(new Map([ ['a', 1], [Symbol(), [2]] ]), `
┌───────────────────┬──────────┬────────┐
-│ (iteration index) │ Key │ Values │
+│ (iteration index) │ Key │ Values │
├───────────────────┼──────────┼────────┤
-│ 0 │ 'a' │ 1 │
-│ 1 │ Symbol() │ [ 2 ] │
+│ 0 │ 'a' │ 1 │
+│ 1 │ Symbol() │ [ 2 ] │
└───────────────────┴──────────┴────────┘
`);
test(new Set([1, 2, Symbol()]), `
┌───────────────────┬──────────┐
-│ (iteration index) │ Values │
+│ (iteration index) │ Values │
├───────────────────┼──────────┤
-│ 0 │ 1 │
-│ 1 │ 2 │
-│ 2 │ Symbol() │
+│ 0 │ 1 │
+│ 1 │ 2 │
+│ 2 │ Symbol() │
└───────────────────┴──────────┘
`);
@@ -112,8 +112,8 @@ test({ a: 1, b: 2 }, ['a'], `
┌─────────┬───┐
│ (index) │ a │
├─────────┼───┤
-│ a │ │
-│ b │ │
+│ a │ │
+│ b │ │
└─────────┴───┘
`);
@@ -121,8 +121,8 @@ test([{ a: 1, b: 2 }, { a: 3, c: 4 }], ['a'], `
┌─────────┬───┐
│ (index) │ a │
├─────────┼───┤
-│ 0 │ 1 │
-│ 1 │ 3 │
+│ 0 │ 1 │
+│ 1 │ 3 │
└─────────┴───┘
`);
@@ -130,9 +130,9 @@ test(new Map([[1, 1], [2, 2], [3, 3]]).entries(), `
┌───────────────────┬─────┬────────┐
│ (iteration index) │ Key │ Values │
├───────────────────┼─────┼────────┤
-│ 0 │ 1 │ 1 │
-│ 1 │ 2 │ 2 │
-│ 2 │ 3 │ 3 │
+│ 0 │ 1 │ 1 │
+│ 1 │ 2 │ 2 │
+│ 2 │ 3 │ 3 │
└───────────────────┴─────┴────────┘
`);
@@ -140,9 +140,9 @@ test(new Map([[1, 1], [2, 2], [3, 3]]).values(), `
┌───────────────────┬────────┐
│ (iteration index) │ Values │
├───────────────────┼────────┤
-│ 0 │ 1 │
-│ 1 │ 2 │
-│ 2 │ 3 │
+│ 0 │ 1 │
+│ 1 │ 2 │
+│ 2 │ 3 │
└───────────────────┴────────┘
`);
@@ -150,9 +150,9 @@ test(new Map([[1, 1], [2, 2], [3, 3]]).keys(), `
┌───────────────────┬────────┐
│ (iteration index) │ Values │
├───────────────────┼────────┤
-│ 0 │ 1 │
-│ 1 │ 2 │
-│ 2 │ 3 │
+│ 0 │ 1 │
+│ 1 │ 2 │
+│ 2 │ 3 │
└───────────────────┴────────┘
`);
@@ -160,9 +160,9 @@ test(new Set([1, 2, 3]).values(), `
┌───────────────────┬────────┐
│ (iteration index) │ Values │
├───────────────────┼────────┤
-│ 0 │ 1 │
-│ 1 │ 2 │
-│ 2 │ 3 │
+│ 0 │ 1 │
+│ 1 │ 2 │
+│ 2 │ 3 │
└───────────────────┴────────┘
`);
@@ -171,15 +171,15 @@ test({ a: { a: 1, b: 2, c: 3 } }, `
┌─────────┬───┬───┬───┐
│ (index) │ a │ b │ c │
├─────────┼───┼───┼───┤
-│ a │ 1 │ 2 │ 3 │
+│ a │ 1 │ 2 │ 3 │
└─────────┴───┴───┴───┘
`);
test({ a: { a: { a: 1, b: 2, c: 3 } } }, `
┌─────────┬──────────┐
-│ (index) │ a │
+│ (index) │ a │
├─────────┼──────────┤
-│ a │ [Object] │
+│ a │ [Object] │
└─────────┴──────────┘
`);
@@ -187,7 +187,7 @@ test({ a: [1, 2] }, `
┌─────────┬───┬───┐
│ (index) │ 0 │ 1 │
├─────────┼───┼───┤
-│ a │ 1 │ 2 │
+│ a │ 1 │ 2 │
└─────────┴───┴───┘
`);
@@ -195,9 +195,9 @@ test({ a: [1, 2, 3, 4, 5], b: 5, c: { e: 5 } }, `
┌─────────┬───┬───┬───┬───┬───┬───┬────────┐
│ (index) │ 0 │ 1 │ 2 │ 3 │ 4 │ e │ Values │
├─────────┼───┼───┼───┼───┼───┼───┼────────┤
-│ a │ 1 │ 2 │ 3 │ 4 │ 5 │ │ │
-│ b │ │ │ │ │ │ │ 5 │
-│ c │ │ │ │ │ │ 5 │ │
+│ a │ 1 │ 2 │ 3 │ 4 │ 5 │ │ │
+│ b │ │ │ │ │ │ │ 5 │
+│ c │ │ │ │ │ │ 5 │ │
└─────────┴───┴───┴───┴───┴───┴───┴────────┘
`);
@@ -205,9 +205,9 @@ test(new Uint8Array([1, 2, 3]), `
┌─────────┬────────┐
│ (index) │ Values │
├─────────┼────────┤
-│ 0 │ 1 │
-│ 1 │ 2 │
-│ 2 │ 3 │
+│ 0 │ 1 │
+│ 1 │ 2 │
+│ 2 │ 3 │
└─────────┴────────┘
`);
@@ -215,9 +215,9 @@ test(Buffer.from([1, 2, 3]), `
┌─────────┬────────┐
│ (index) │ Values │
├─────────┼────────┤
-│ 0 │ 1 │
-│ 1 │ 2 │
-│ 2 │ 3 │
+│ 0 │ 1 │
+│ 1 │ 2 │
+│ 2 │ 3 │
└─────────┴────────┘
`);
@@ -225,7 +225,7 @@ test({ a: undefined }, ['x'], `
┌─────────┬───┐
│ (index) │ x │
├─────────┼───┤
-│ a │ │
+│ a │ │
└─────────┴───┘
`);
@@ -245,23 +245,23 @@ test(new Map(), `
test([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }], `
┌─────────┬─────┬─────┐
-│ (index) │ a │ b │
+│ (index) │ a │ b │
├─────────┼─────┼─────┤
-│ 0 │ 1 │ 'Y' │
-│ 1 │ 'Z' │ 2 │
+│ 0 │ 1 │ 'Y' │
+│ 1 │ 'Z' │ 2 │
└─────────┴─────┴─────┘
`);
{
const line = '─'.repeat(79);
- const header = `${' '.repeat(37)}name${' '.repeat(40)}`;
+ const header = `name${' '.repeat(77)}`;
const name = 'very long long long long long long long long long long long ' +
'long long long long';
test([{ name }], `
┌─────────┬──${line}──┐
-│ (index) │ ${header}│
+│ (index) │ ${header} │
├─────────┼──${line}──┤
-│ 0 │ '${name}' │
+│ 0 │ '${name}' │
└─────────┴──${line}──┘
`);
}
@@ -270,8 +270,8 @@ test({ foo: '¥', bar: '¥' }, `
┌─────────┬────────┐
│ (index) │ Values │
├─────────┼────────┤
-│ foo │ '¥' │
-│ bar │ '¥' │
+│ foo │ '¥' │
+│ bar │ '¥' │
└─────────┴────────┘
`);
@@ -279,8 +279,8 @@ test({ foo: '你好', bar: 'hello' }, `
┌─────────┬─────────┐
│ (index) │ Values │
├─────────┼─────────┤
-│ foo │ '你好' │
-│ bar │ 'hello' │
+│ foo │ '你好' │
+│ bar │ 'hello' │
└─────────┴─────────┘
`);
@@ -292,8 +292,8 @@ test([{ foo: 10 }, { foo: 20 }], ['__proto__'], `
┌─────────┬───────────┐
│ (index) │ __proto__ │
├─────────┼───────────┤
-│ 0 │ │
-│ 1 │ │
+│ 0 │ │
+│ 1 │ │
└─────────┴───────────┘
`);
assert.strictEqual('0' in Object.prototype, false);
diff --git a/tests/node_compat/test/parallel/test-diagnostics-channel-pub-sub.js b/tests/node_compat/test/parallel/test-diagnostics-channel-pub-sub.js
index 8a8554823..ef2486f5a 100644
--- a/tests/node_compat/test/parallel/test-diagnostics-channel-pub-sub.js
+++ b/tests/node_compat/test/parallel/test-diagnostics-channel-pub-sub.js
@@ -49,3 +49,10 @@ assert.ok(!dc.unsubscribe(name, subscriber));
assert.throws(() => {
dc.subscribe(name, null);
}, { code: 'ERR_INVALID_ARG_TYPE' });
+
+// Reaching zero subscribers should not delete from the channels map as there
+// will be no more weakref to incRef if another subscribe happens while the
+// channel object itself exists.
+channel.subscribe(subscriber);
+channel.unsubscribe(subscriber);
+channel.subscribe(subscriber);
diff --git a/tests/node_compat/test/parallel/test-event-emitter-emit-context.js b/tests/node_compat/test/parallel/test-event-emitter-emit-context.js
index 437a1fadb..76c22aa9a 100644
--- a/tests/node_compat/test/parallel/test-event-emitter-emit-context.js
+++ b/tests/node_compat/test/parallel/test-event-emitter-emit-context.js
@@ -15,7 +15,7 @@ const EE = new EventEmitter();
// Works as expected if the context has no `constructor.name`
{
- const ctx = Object.create(null);
+ const ctx = { __proto__: null };
assert.throws(
() => EE.emit.call(ctx, 'error', new Error('foo')),
common.expectsError({ name: 'Error', message: 'foo' })
diff --git a/tests/node_compat/test/parallel/test-event-emitter-error-monitor.js b/tests/node_compat/test/parallel/test-event-emitter-error-monitor.js
index d6676a8e1..e5df20e60 100644
--- a/tests/node_compat/test/parallel/test-event-emitter-error-monitor.js
+++ b/tests/node_compat/test/parallel/test-event-emitter-error-monitor.js
@@ -32,7 +32,7 @@ EE.emit('error', theErr);
// Verify it works with once
process.nextTick(() => EE.emit('error', theErr));
-assert.rejects(EventEmitter.once(EE, 'notTriggered'), theErr);
+assert.rejects(EventEmitter.once(EE, 'notTriggered'), theErr).then(common.mustCall());
// Only error events trigger error monitor
EE.on('aEvent', common.mustCall());
diff --git a/tests/node_compat/test/parallel/test-file-write-stream.js b/tests/node_compat/test/parallel/test-file-write-stream.js
index 6b8c3d494..22ebadd1c 100644
--- a/tests/node_compat/test/parallel/test-file-write-stream.js
+++ b/tests/node_compat/test/parallel/test-file-write-stream.js
@@ -30,10 +30,9 @@
const common = require('../common');
const assert = require('assert');
-const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
-const fn = path.join(tmpdir.path, 'write.txt');
+const fn = tmpdir.resolve('write.txt');
tmpdir.refresh();
const file = fs.createWriteStream(fn, {
highWaterMark: 10
diff --git a/tests/node_compat/test/parallel/test-file-write-stream2.js b/tests/node_compat/test/parallel/test-file-write-stream2.js
index 12b7f243d..8b23683a7 100644
--- a/tests/node_compat/test/parallel/test-file-write-stream2.js
+++ b/tests/node_compat/test/parallel/test-file-write-stream2.js
@@ -30,13 +30,12 @@
require('../common');
const assert = require('assert');
-const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
-const filepath = path.join(tmpdir.path, 'write.txt');
+const filepath = tmpdir.resolve('write.txt');
const EXPECTED = '012345678910';
diff --git a/tests/node_compat/test/parallel/test-file-write-stream3.js b/tests/node_compat/test/parallel/test-file-write-stream3.js
index f34b5f6ea..2dd5444a6 100644
--- a/tests/node_compat/test/parallel/test-file-write-stream3.js
+++ b/tests/node_compat/test/parallel/test-file-write-stream3.js
@@ -29,13 +29,12 @@
'use strict';
const common = require('../common');
const assert = require('assert');
-const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
-const filepath = path.join(tmpdir.path, 'write_pos.txt');
+const filepath = tmpdir.resolve('write_pos.txt');
const cb_expected = 'write open close write open close write open close ';
diff --git a/tests/node_compat/test/parallel/test-file-write-stream4.js b/tests/node_compat/test/parallel/test-file-write-stream4.js
index 8a143c2c4..9d5cd7d32 100644
--- a/tests/node_compat/test/parallel/test-file-write-stream4.js
+++ b/tests/node_compat/test/parallel/test-file-write-stream4.js
@@ -11,13 +11,12 @@
// Refs: https://github.com/nodejs/node/issues/31366
const common = require('../common');
-const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
-const filepath = path.join(tmpdir.path, 'write_pos.txt');
+const filepath = tmpdir.resolve('write_pos.txt');
const fileReadStream = fs.createReadStream(process.execPath);
const fileWriteStream = fs.createWriteStream(filepath, {
diff --git a/tests/node_compat/test/parallel/test-fs-access.js b/tests/node_compat/test/parallel/test-fs-access.js
index a67f9fe07..8add7d553 100644
--- a/tests/node_compat/test/parallel/test-fs-access.js
+++ b/tests/node_compat/test/parallel/test-fs-access.js
@@ -20,15 +20,14 @@ if (common.isIBMi)
const assert = require('assert');
const fs = require('fs');
-const path = require('path');
const { internalBinding } = require('internal/test/binding');
const { UV_ENOENT } = internalBinding('uv');
const tmpdir = require('../common/tmpdir');
-const doesNotExist = path.join(tmpdir.path, '__this_should_not_exist');
-const readOnlyFile = path.join(tmpdir.path, 'read_only_file');
-const readWriteFile = path.join(tmpdir.path, 'read_write_file');
+const doesNotExist = tmpdir.resolve('__this_should_not_exist');
+const readOnlyFile = tmpdir.resolve('read_only_file');
+const readWriteFile = tmpdir.resolve('read_write_file');
function createFileWithPerms(file, mode) {
fs.writeFileSync(file, '');
@@ -71,10 +70,10 @@ if (!common.isWindows && process.getuid() === 0) {
}
}
-assert.strictEqual(typeof fs.F_OK, 'number');
-assert.strictEqual(typeof fs.R_OK, 'number');
-assert.strictEqual(typeof fs.W_OK, 'number');
-assert.strictEqual(typeof fs.X_OK, 'number');
+assert.strictEqual(typeof fs.constants.F_OK, 'number');
+assert.strictEqual(typeof fs.constants.R_OK, 'number');
+assert.strictEqual(typeof fs.constants.W_OK, 'number');
+assert.strictEqual(typeof fs.constants.X_OK, 'number');
const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
@@ -84,16 +83,16 @@ fs.access(__filename, common.mustCall(function(...args) {
fs.promises.access(__filename)
.then(common.mustCall())
.catch(throwNextTick);
-fs.access(__filename, fs.R_OK, common.mustCall(function(...args) {
+fs.access(__filename, fs.constants.R_OK, common.mustCall(function(...args) {
assert.deepStrictEqual(args, [null]);
}));
-fs.promises.access(__filename, fs.R_OK)
+fs.promises.access(__filename, fs.constants.R_OK)
.then(common.mustCall())
.catch(throwNextTick);
-fs.access(readOnlyFile, fs.R_OK, common.mustCall(function(...args) {
+fs.access(readOnlyFile, fs.constants.R_OK, common.mustCall(function(...args) {
assert.deepStrictEqual(args, [null]);
}));
-fs.promises.access(readOnlyFile, fs.R_OK)
+fs.promises.access(readOnlyFile, fs.constants.R_OK)
.then(common.mustCall())
.catch(throwNextTick);
@@ -119,8 +118,8 @@ fs.promises.access(readOnlyFile, fs.R_OK)
assert.strictEqual(err.path, readOnlyFile);
}
}
- fs.access(readOnlyFile, fs.W_OK, common.mustCall(expectedError));
- fs.promises.access(readOnlyFile, fs.W_OK)
+ fs.access(readOnlyFile, fs.constants.W_OK, common.mustCall(expectedError));
+ fs.promises.access(readOnlyFile, fs.constants.W_OK)
.then(common.mustNotCall(), common.mustCall(expectedError))
.catch(throwNextTick);
}
@@ -132,18 +131,18 @@ fs.promises.access(readOnlyFile, fs.R_OK)
return true;
};
assert.throws(
- () => { fs.access(100, fs.F_OK, common.mustNotCall()); },
+ () => { fs.access(100, fs.constants.F_OK, common.mustNotCall()); },
expectedError
);
- fs.promises.access(100, fs.F_OK)
+ fs.promises.access(100, fs.constants.F_OK)
.then(common.mustNotCall(), common.mustCall(expectedError))
.catch(throwNextTick);
}
assert.throws(
() => {
- fs.access(__filename, fs.F_OK);
+ fs.access(__filename, fs.constants.F_OK);
},
{
code: 'ERR_INVALID_ARG_TYPE',
@@ -152,7 +151,7 @@ assert.throws(
assert.throws(
() => {
- fs.access(__filename, fs.F_OK, common.mustNotMutateObjectDeep({}));
+ fs.access(__filename, fs.constants.F_OK, common.mustNotMutateObjectDeep({}));
},
{
code: 'ERR_INVALID_ARG_TYPE',
@@ -161,14 +160,14 @@ assert.throws(
// Regular access should not throw.
fs.accessSync(__filename);
-const mode = fs.R_OK | fs.W_OK;
+const mode = fs.constants.R_OK | fs.constants.W_OK;
fs.accessSync(readWriteFile, mode);
// Invalid modes should throw.
[
false,
1n,
- { [Symbol.toPrimitive]() { return fs.R_OK; } },
+ { [Symbol.toPrimitive]() { return fs.constants.R_OK; } },
[1],
'r',
].forEach((mode, i) => {
diff --git a/tests/node_compat/test/parallel/test-fs-append-file-sync.js b/tests/node_compat/test/parallel/test-fs-append-file-sync.js
index bed75f171..fa79ddb55 100644
--- a/tests/node_compat/test/parallel/test-fs-append-file-sync.js
+++ b/tests/node_compat/test/parallel/test-fs-append-file-sync.js
@@ -29,7 +29,6 @@
'use strict';
const common = require('../common');
const assert = require('assert');
-const join = require('path').join;
const fs = require('fs');
const currentFileData = 'ABCD';
@@ -47,7 +46,7 @@ const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
// Test that empty file will be created and have content added.
-const filename = join(tmpdir.path, 'append-sync.txt');
+const filename = tmpdir.resolve('append-sync.txt');
fs.appendFileSync(filename, data);
@@ -56,7 +55,7 @@ const fileData = fs.readFileSync(filename);
assert.strictEqual(Buffer.byteLength(data), fileData.length);
// Test that appends data to a non empty file.
-const filename2 = join(tmpdir.path, 'append-sync2.txt');
+const filename2 = tmpdir.resolve('append-sync2.txt');
fs.writeFileSync(filename2, currentFileData);
fs.appendFileSync(filename2, data);
@@ -67,7 +66,7 @@ assert.strictEqual(Buffer.byteLength(data) + currentFileData.length,
fileData2.length);
// Test that appendFileSync accepts buffers.
-const filename3 = join(tmpdir.path, 'append-sync3.txt');
+const filename3 = tmpdir.resolve('append-sync3.txt');
fs.writeFileSync(filename3, currentFileData);
const buf = Buffer.from(data, 'utf8');
@@ -77,7 +76,7 @@ const fileData3 = fs.readFileSync(filename3);
assert.strictEqual(buf.length + currentFileData.length, fileData3.length);
-const filename4 = join(tmpdir.path, 'append-sync4.txt');
+const filename4 = tmpdir.resolve('append-sync4.txt');
fs.writeFileSync(filename4, currentFileData, common.mustNotMutateObjectDeep({ mode: m }));
[
@@ -102,7 +101,7 @@ assert.strictEqual(Buffer.byteLength(String(num)) + currentFileData.length,
fileData4.length);
// Test that appendFile accepts file descriptors.
-const filename5 = join(tmpdir.path, 'append-sync5.txt');
+const filename5 = tmpdir.resolve('append-sync5.txt');
fs.writeFileSync(filename5, currentFileData);
const filename5fd = fs.openSync(filename5, 'a+', 0o600);
diff --git a/tests/node_compat/test/parallel/test-fs-copyfile.js b/tests/node_compat/test/parallel/test-fs-copyfile.js
index 37d709750..d00a076f3 100644
--- a/tests/node_compat/test/parallel/test-fs-copyfile.js
+++ b/tests/node_compat/test/parallel/test-fs-copyfile.js
@@ -17,9 +17,8 @@ const {
UV_ENOENT,
UV_EEXIST
} = internalBinding('uv');
-const path = require('path');
const src = fixtures.path('a.js');
-const dest = path.join(tmpdir.path, 'copyfile.out');
+const dest = tmpdir.resolve('copyfile.out');
const {
COPYFILE_EXCL,
COPYFILE_FICLONE,
diff --git a/tests/node_compat/test/parallel/test-fs-open-flags.js b/tests/node_compat/test/parallel/test-fs-open-flags.js
index 2bacf8300..89f6bdcb6 100644
--- a/tests/node_compat/test/parallel/test-fs-open-flags.js
+++ b/tests/node_compat/test/parallel/test-fs-open-flags.js
@@ -34,7 +34,6 @@ const fixtures = require('../common/fixtures');
const assert = require('assert');
const fs = require('fs');
-const path = require('path');
// 0 if not found in fs.constants
const { O_APPEND = 0,
@@ -93,7 +92,7 @@ assert.throws(
if (common.isLinux || common.isOSX) {
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
- const file = path.join(tmpdir.path, 'a.js');
+ const file = tmpdir.resolve('a.js');
fs.copyFileSync(fixtures.path('a.js'), file);
fs.open(file, O_DSYNC, common.mustSucceed((fd) => {
fs.closeSync(fd);
diff --git a/tests/node_compat/test/parallel/test-fs-open-mode-mask.js b/tests/node_compat/test/parallel/test-fs-open-mode-mask.js
index 20dd31b8c..30a2cd354 100644
--- a/tests/node_compat/test/parallel/test-fs-open-mode-mask.js
+++ b/tests/node_compat/test/parallel/test-fs-open-mode-mask.js
@@ -11,7 +11,6 @@
const common = require('../common');
const assert = require('assert');
-const path = require('path');
const fs = require('fs');
const mode = common.isWindows ? 0o444 : 0o644;
@@ -27,7 +26,7 @@ function test(mode, asString) {
(mode | maskToIgnore).toString(8) : (mode | maskToIgnore);
{
- const file = path.join(tmpdir.path, `openSync-${suffix}.txt`);
+ const file = tmpdir.resolve(`openSync-${suffix}.txt`);
const fd = fs.openSync(file, 'w+', input);
assert.strictEqual(fs.fstatSync(fd).mode & 0o777, mode);
fs.closeSync(fd);
@@ -35,7 +34,7 @@ function test(mode, asString) {
}
{
- const file = path.join(tmpdir.path, `open-${suffix}.txt`);
+ const file = tmpdir.resolve(`open-${suffix}.txt`);
fs.open(file, 'w+', input, common.mustSucceed((fd) => {
assert.strictEqual(fs.fstatSync(fd).mode & 0o777, mode);
fs.closeSync(fd);
diff --git a/tests/node_compat/test/parallel/test-fs-open-numeric-flags.js b/tests/node_compat/test/parallel/test-fs-open-numeric-flags.js
index 2e62a1cfd..025eff60d 100644
--- a/tests/node_compat/test/parallel/test-fs-open-numeric-flags.js
+++ b/tests/node_compat/test/parallel/test-fs-open-numeric-flags.js
@@ -10,13 +10,12 @@ require('../common');
const assert = require('assert');
const fs = require('fs');
-const path = require('path');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
// O_WRONLY without O_CREAT shall fail with ENOENT
-const pathNE = path.join(tmpdir.path, 'file-should-not-exist');
+const pathNE = tmpdir.resolve('file-should-not-exist');
assert.throws(
() => fs.openSync(pathNE, fs.constants.O_WRONLY),
(e) => e.code === 'ENOENT'
diff --git a/tests/node_compat/test/parallel/test-fs-read-stream-autoClose.js b/tests/node_compat/test/parallel/test-fs-read-stream-autoClose.js
index 70fd17e00..2ab7b69e3 100644
--- a/tests/node_compat/test/parallel/test-fs-read-stream-autoClose.js
+++ b/tests/node_compat/test/parallel/test-fs-read-stream-autoClose.js
@@ -9,10 +9,9 @@
const common = require('../common');
const fs = require('fs');
-const path = require('path');
const assert = require('assert');
const tmpdir = require('../common/tmpdir');
-const writeFile = path.join(tmpdir.path, 'write-autoClose.txt');
+const writeFile = tmpdir.resolve('write-autoClose.txt');
tmpdir.refresh();
const file = fs.createWriteStream(writeFile, { autoClose: true });
diff --git a/tests/node_compat/test/parallel/test-fs-read-stream-fd.js b/tests/node_compat/test/parallel/test-fs-read-stream-fd.js
index 5562c5796..ba7c06419 100644
--- a/tests/node_compat/test/parallel/test-fs-read-stream-fd.js
+++ b/tests/node_compat/test/parallel/test-fs-read-stream-fd.js
@@ -30,9 +30,8 @@
const common = require('../common');
const fs = require('fs');
const assert = require('assert');
-const path = require('path');
const tmpdir = require('../common/tmpdir');
-const file = path.join(tmpdir.path, '/read_stream_fd_test.txt');
+const file = tmpdir.resolve('read_stream_fd_test.txt');
const input = 'hello world';
let output = '';
diff --git a/tests/node_compat/test/parallel/test-fs-read-stream-inherit.js b/tests/node_compat/test/parallel/test-fs-read-stream-inherit.js
index 79fa88486..2f8c139e8 100644
--- a/tests/node_compat/test/parallel/test-fs-read-stream-inherit.js
+++ b/tests/node_compat/test/parallel/test-fs-read-stream-inherit.js
@@ -57,7 +57,7 @@ const rangeFile = fixtures.path('x.txt');
}
{
- const file = fs.createReadStream(fn, Object.create({ encoding: 'utf8' }));
+ const file = fs.createReadStream(fn, { __proto__: { encoding: 'utf8' } });
file.length = 0;
file.on('data', function(data) {
assert.strictEqual(typeof data, 'string');
@@ -75,7 +75,7 @@ const rangeFile = fixtures.path('x.txt');
}
{
- const options = Object.create({ bufferSize: 1, start: 1, end: 2 });
+ const options = { __proto__: { bufferSize: 1, start: 1, end: 2 } };
const file = fs.createReadStream(rangeFile, options);
assert.strictEqual(file.start, 1);
assert.strictEqual(file.end, 2);
@@ -89,7 +89,7 @@ const rangeFile = fixtures.path('x.txt');
}
{
- const options = Object.create({ bufferSize: 1, start: 1 });
+ const options = { __proto__: { bufferSize: 1, start: 1 } };
const file = fs.createReadStream(rangeFile, options);
assert.strictEqual(file.start, 1);
file.data = '';
@@ -103,7 +103,7 @@ const rangeFile = fixtures.path('x.txt');
// https://github.com/joyent/node/issues/2320
{
- const options = Object.create({ bufferSize: 1.23, start: 1 });
+ const options = { __proto__: { bufferSize: 1.23, start: 1 } };
const file = fs.createReadStream(rangeFile, options);
assert.strictEqual(file.start, 1);
file.data = '';
@@ -122,7 +122,7 @@ const rangeFile = fixtures.path('x.txt');
assert.throws(
() => {
- fs.createReadStream(rangeFile, Object.create({ start: 10, end: 2 }));
+ fs.createReadStream(rangeFile, { __proto__: { start: 10, end: 2 } });
},
{
code: 'ERR_OUT_OF_RANGE',
@@ -132,7 +132,7 @@ const rangeFile = fixtures.path('x.txt');
}
{
- const options = Object.create({ start: 0, end: 0 });
+ const options = { __proto__: { start: 0, end: 0 } };
const stream = fs.createReadStream(rangeFile, options);
assert.strictEqual(stream.start, 0);
assert.strictEqual(stream.end, 0);
@@ -157,7 +157,7 @@ const rangeFile = fixtures.path('x.txt');
{
let data = '';
let file =
- fs.createReadStream(rangeFile, Object.create({ autoClose: false }));
+ fs.createReadStream(rangeFile, { __proto__: { autoClose: false } });
assert.strictEqual(file.autoClose, false);
file.on('data', (chunk) => { data += chunk; });
file.on('end', common.mustCall(function() {
@@ -171,7 +171,7 @@ const rangeFile = fixtures.path('x.txt');
function fileNext() {
// This will tell us if the fd is usable again or not.
- file = fs.createReadStream(null, Object.create({ fd: file.fd, start: 0 }));
+ file = fs.createReadStream(null, { __proto__: { fd: file.fd, start: 0 } });
file.data = '';
file.on('data', function(data) {
file.data += data;
@@ -188,7 +188,7 @@ const rangeFile = fixtures.path('x.txt');
// Just to make sure autoClose won't close the stream because of error.
{
- const options = Object.create({ fd: 13337, autoClose: false });
+ const options = { __proto__: { fd: 13337, autoClose: false } };
const file = fs.createReadStream(null, options);
file.on('data', common.mustNotCall());
file.on('error', common.mustCall());
diff --git a/tests/node_compat/test/parallel/test-fs-read.js b/tests/node_compat/test/parallel/test-fs-read.js
index 3afad7aad..e8318df1e 100644
--- a/tests/node_compat/test/parallel/test-fs-read.js
+++ b/tests/node_compat/test/parallel/test-fs-read.js
@@ -86,7 +86,7 @@ assert.throws(
assert.throws(
() => fs.read(fd, { buffer: null }, common.mustNotCall()),
- /TypeError: Cannot read properties of null \(reading 'byteLength'\)/,
+ { code: 'ERR_INVALID_ARG_TYPE' },
'throws when options.buffer is null'
);
diff --git a/tests/node_compat/test/parallel/test-fs-readv-sync.js b/tests/node_compat/test/parallel/test-fs-readv-sync.js
index 4af09db61..fd0fc8cda 100644
--- a/tests/node_compat/test/parallel/test-fs-readv-sync.js
+++ b/tests/node_compat/test/parallel/test-fs-readv-sync.js
@@ -10,7 +10,6 @@
require('../common');
const assert = require('assert');
const fs = require('fs');
-const path = require('path');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
@@ -20,7 +19,7 @@ const expected = 'ümlaut. Лорем 運務ホソモ指及 आपको कर
const exptectedBuff = Buffer.from(expected);
const expectedLength = exptectedBuff.length;
-const filename = path.join(tmpdir.path, 'readv_sync.txt');
+const filename = tmpdir.resolve('readv_sync.txt');
fs.writeFileSync(filename, exptectedBuff);
const allocateEmptyBuffers = (combinedLength) => {
diff --git a/tests/node_compat/test/parallel/test-fs-readv.js b/tests/node_compat/test/parallel/test-fs-readv.js
index 6d1096dbf..42581cfe8 100644
--- a/tests/node_compat/test/parallel/test-fs-readv.js
+++ b/tests/node_compat/test/parallel/test-fs-readv.js
@@ -9,7 +9,6 @@
const common = require('../common');
const assert = require('assert');
-const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
@@ -18,7 +17,7 @@ tmpdir.refresh();
const expected = 'ümlaut. Лорем 運務ホソモ指及 आपको करने विकास 紙読決多密所 أضف';
let cnt = 0;
-const getFileName = () => path.join(tmpdir.path, `readv_${++cnt}.txt`);
+const getFileName = () => tmpdir.resolve(`readv_${++cnt}.txt`);
const exptectedBuff = Buffer.from(expected);
const allocateEmptyBuffers = (combinedLength) => {
diff --git a/tests/node_compat/test/parallel/test-fs-rmdir-recursive-sync-warns-not-found.js b/tests/node_compat/test/parallel/test-fs-rmdir-recursive-sync-warns-not-found.js
index 175e22f02..121a66e09 100644
--- a/tests/node_compat/test/parallel/test-fs-rmdir-recursive-sync-warns-not-found.js
+++ b/tests/node_compat/test/parallel/test-fs-rmdir-recursive-sync-warns-not-found.js
@@ -10,7 +10,6 @@ const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const fs = require('fs');
-const path = require('path');
tmpdir.refresh();
@@ -23,7 +22,7 @@ tmpdir.refresh();
'DEP0147'
);
assert.throws(
- () => fs.rmdirSync(path.join(tmpdir.path, 'noexist.txt'),
+ () => fs.rmdirSync(tmpdir.resolve('noexist.txt'),
{ recursive: true }),
{ code: 'ENOENT' }
);
diff --git a/tests/node_compat/test/parallel/test-fs-rmdir-recursive-sync-warns-on-file.js b/tests/node_compat/test/parallel/test-fs-rmdir-recursive-sync-warns-on-file.js
index b0109c410..b3f4d1fab 100644
--- a/tests/node_compat/test/parallel/test-fs-rmdir-recursive-sync-warns-on-file.js
+++ b/tests/node_compat/test/parallel/test-fs-rmdir-recursive-sync-warns-on-file.js
@@ -10,7 +10,6 @@ const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const fs = require('fs');
-const path = require('path');
tmpdir.refresh();
@@ -21,7 +20,7 @@ tmpdir.refresh();
'will be removed. Use fs.rm(path, { recursive: true }) instead',
'DEP0147'
);
- const filePath = path.join(tmpdir.path, 'rmdir-recursive.txt');
+ const filePath = tmpdir.resolve('rmdir-recursive.txt');
fs.writeFileSync(filePath, '');
assert.throws(
() => fs.rmdirSync(filePath, { recursive: true }),
diff --git a/tests/node_compat/test/parallel/test-fs-rmdir-recursive-throws-not-found.js b/tests/node_compat/test/parallel/test-fs-rmdir-recursive-throws-not-found.js
index f8ed34e42..931308aad 100644
--- a/tests/node_compat/test/parallel/test-fs-rmdir-recursive-throws-not-found.js
+++ b/tests/node_compat/test/parallel/test-fs-rmdir-recursive-throws-not-found.js
@@ -10,14 +10,13 @@ const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const fs = require('fs');
-const path = require('path');
tmpdir.refresh();
{
assert.throws(
() =>
- fs.rmdirSync(path.join(tmpdir.path, 'noexist.txt'), { recursive: true }),
+ fs.rmdirSync(tmpdir.resolve('noexist.txt'), { recursive: true }),
{
code: 'ENOENT',
}
@@ -25,7 +24,7 @@ tmpdir.refresh();
}
{
fs.rmdir(
- path.join(tmpdir.path, 'noexist.txt'),
+ tmpdir.resolve('noexist.txt'),
{ recursive: true },
common.mustCall((err) => {
assert.strictEqual(err.code, 'ENOENT');
@@ -34,7 +33,7 @@ tmpdir.refresh();
}
{
assert.rejects(
- () => fs.promises.rmdir(path.join(tmpdir.path, 'noexist.txt'),
+ () => fs.promises.rmdir(tmpdir.resolve('noexist.txt'),
{ recursive: true }),
{
code: 'ENOENT',
diff --git a/tests/node_compat/test/parallel/test-fs-rmdir-recursive-throws-on-file.js b/tests/node_compat/test/parallel/test-fs-rmdir-recursive-throws-on-file.js
index d16539b06..6a48678bc 100644
--- a/tests/node_compat/test/parallel/test-fs-rmdir-recursive-throws-on-file.js
+++ b/tests/node_compat/test/parallel/test-fs-rmdir-recursive-throws-on-file.js
@@ -10,26 +10,25 @@ const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const fs = require('fs');
-const path = require('path');
tmpdir.refresh();
const code = common.isWindows ? 'ENOENT' : 'ENOTDIR';
{
- const filePath = path.join(tmpdir.path, 'rmdir-recursive.txt');
+ const filePath = tmpdir.resolve('rmdir-recursive.txt');
fs.writeFileSync(filePath, '');
assert.throws(() => fs.rmdirSync(filePath, { recursive: true }), { code });
}
{
- const filePath = path.join(tmpdir.path, 'rmdir-recursive.txt');
+ const filePath = tmpdir.resolve('rmdir-recursive.txt');
fs.writeFileSync(filePath, '');
fs.rmdir(filePath, { recursive: true }, common.mustCall((err) => {
assert.strictEqual(err.code, code);
}));
}
{
- const filePath = path.join(tmpdir.path, 'rmdir-recursive.txt');
+ const filePath = tmpdir.resolve('rmdir-recursive.txt');
fs.writeFileSync(filePath, '');
assert.rejects(() => fs.promises.rmdir(filePath, { recursive: true }),
{ code }).then(common.mustCall());
diff --git a/tests/node_compat/test/parallel/test-fs-rmdir-recursive-warns-not-found.js b/tests/node_compat/test/parallel/test-fs-rmdir-recursive-warns-not-found.js
index 1bd45a313..2eae8b1e3 100644
--- a/tests/node_compat/test/parallel/test-fs-rmdir-recursive-warns-not-found.js
+++ b/tests/node_compat/test/parallel/test-fs-rmdir-recursive-warns-not-found.js
@@ -9,7 +9,6 @@
const common = require('../common');
const tmpdir = require('../common/tmpdir');
const fs = require('fs');
-const path = require('path');
tmpdir.refresh();
@@ -22,7 +21,7 @@ tmpdir.refresh();
'DEP0147'
);
fs.rmdir(
- path.join(tmpdir.path, 'noexist.txt'),
+ tmpdir.resolve('noexist.txt'),
{ recursive: true },
common.mustCall()
);
diff --git a/tests/node_compat/test/parallel/test-fs-rmdir-recursive-warns-on-file.js b/tests/node_compat/test/parallel/test-fs-rmdir-recursive-warns-on-file.js
index 72adc3c11..89250b048 100644
--- a/tests/node_compat/test/parallel/test-fs-rmdir-recursive-warns-on-file.js
+++ b/tests/node_compat/test/parallel/test-fs-rmdir-recursive-warns-on-file.js
@@ -10,7 +10,6 @@ const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const fs = require('fs');
-const path = require('path');
tmpdir.refresh();
@@ -21,7 +20,7 @@ tmpdir.refresh();
'will be removed. Use fs.rm(path, { recursive: true }) instead',
'DEP0147'
);
- const filePath = path.join(tmpdir.path, 'rmdir-recursive.txt');
+ const filePath = tmpdir.resolve('rmdir-recursive.txt');
fs.writeFileSync(filePath, '');
fs.rmdir(filePath, { recursive: true }, common.mustCall((err) => {
assert.strictEqual(err.code, common.isWindows ? 'ENOENT' : 'ENOTDIR');
diff --git a/tests/node_compat/test/parallel/test-fs-watchfile.js b/tests/node_compat/test/parallel/test-fs-watchfile.js
index 7419b276c..ccbaabe06 100644
--- a/tests/node_compat/test/parallel/test-fs-watchfile.js
+++ b/tests/node_compat/test/parallel/test-fs-watchfile.js
@@ -37,7 +37,7 @@ assert.throws(() => {
fs.watchFile(new Object(), common.mustNotCall());
}, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError' });
-const enoentFile = path.join(tmpdir.path, 'non-existent-file');
+const enoentFile = tmpdir.resolve('non-existent-file');
const expectedStatObject = new fs.Stats(
0, // dev
0, // mode
@@ -92,14 +92,14 @@ watcher.on('stop', common.mustCall());
// Watch events should callback with a filename on supported systems.
// Omitting AIX. It works but not reliably.
if (common.isLinux || common.isOSX || common.isWindows) {
- const dir = path.join(tmpdir.path, 'watch');
+ const dir = tmpdir.resolve('watch');
fs.mkdir(dir, common.mustCall(function(err) {
if (err) assert.fail(err);
- fs.watch(dir, common.mustCall(function(eventType, filename) {
+ const handle = fs.watch(dir, common.mustCall(function(eventType, filename) {
clearInterval(interval);
- this._handle.close();
+ handle.close();
assert.strictEqual(filename, 'foo.txt');
}));
diff --git a/tests/node_compat/test/parallel/test-fs-write-buffer.js b/tests/node_compat/test/parallel/test-fs-write-buffer.js
index c867d3cd1..13ee5f068 100644
--- a/tests/node_compat/test/parallel/test-fs-write-buffer.js
+++ b/tests/node_compat/test/parallel/test-fs-write-buffer.js
@@ -29,7 +29,6 @@
'use strict';
const common = require('../common');
const assert = require('assert');
-const path = require('path');
const fs = require('fs');
const expected = Buffer.from('hello');
@@ -38,7 +37,7 @@ tmpdir.refresh();
// fs.write with all parameters provided:
{
- const filename = path.join(tmpdir.path, 'write1.txt');
+ const filename = tmpdir.resolve('write1.txt');
fs.open(filename, 'w', 0o644, common.mustSucceed((fd) => {
const cb = common.mustSucceed((written) => {
assert.strictEqual(written, expected.length);
@@ -54,7 +53,7 @@ tmpdir.refresh();
// fs.write with a buffer, without the length parameter:
{
- const filename = path.join(tmpdir.path, 'write2.txt');
+ const filename = tmpdir.resolve('write2.txt');
fs.open(filename, 'w', 0o644, common.mustSucceed((fd) => {
const cb = common.mustSucceed((written) => {
assert.strictEqual(written, 2);
@@ -70,7 +69,7 @@ tmpdir.refresh();
// fs.write with a buffer, without the offset and length parameters:
{
- const filename = path.join(tmpdir.path, 'write3.txt');
+ const filename = tmpdir.resolve('write3.txt');
fs.open(filename, 'w', 0o644, common.mustSucceed((fd) => {
const cb = common.mustSucceed((written) => {
assert.strictEqual(written, expected.length);
@@ -86,7 +85,7 @@ tmpdir.refresh();
// fs.write with the offset passed as undefined followed by the callback:
{
- const filename = path.join(tmpdir.path, 'write4.txt');
+ const filename = tmpdir.resolve('write4.txt');
fs.open(filename, 'w', 0o644, common.mustSucceed((fd) => {
const cb = common.mustSucceed((written) => {
assert.strictEqual(written, expected.length);
@@ -102,7 +101,7 @@ tmpdir.refresh();
// fs.write with offset and length passed as undefined followed by the callback:
{
- const filename = path.join(tmpdir.path, 'write5.txt');
+ const filename = tmpdir.resolve('write5.txt');
fs.open(filename, 'w', 0o644, common.mustSucceed((fd) => {
const cb = common.mustSucceed((written) => {
assert.strictEqual(written, expected.length);
@@ -118,7 +117,7 @@ tmpdir.refresh();
// fs.write with a Uint8Array, without the offset and length parameters:
{
- const filename = path.join(tmpdir.path, 'write6.txt');
+ const filename = tmpdir.resolve('write6.txt');
fs.open(filename, 'w', 0o644, common.mustSucceed((fd) => {
const cb = common.mustSucceed((written) => {
assert.strictEqual(written, expected.length);
@@ -134,7 +133,7 @@ tmpdir.refresh();
// fs.write with invalid offset type
{
- const filename = path.join(tmpdir.path, 'write7.txt');
+ const filename = tmpdir.resolve('write7.txt');
fs.open(filename, 'w', 0o644, common.mustSucceed((fd) => {
assert.throws(() => {
fs.write(fd,
@@ -156,7 +155,7 @@ tmpdir.refresh();
// fs.write with a DataView, without the offset and length parameters:
{
- const filename = path.join(tmpdir.path, 'write8.txt');
+ const filename = tmpdir.resolve('write8.txt');
fs.open(filename, 'w', 0o644, common.mustSucceed((fd) => {
const cb = common.mustSucceed((written) => {
assert.strictEqual(written, expected.length);
diff --git a/tests/node_compat/test/parallel/test-fs-write-file-buffer.js b/tests/node_compat/test/parallel/test-fs-write-file-buffer.js
index 6de3eadd5..d0bfd32aa 100644
--- a/tests/node_compat/test/parallel/test-fs-write-file-buffer.js
+++ b/tests/node_compat/test/parallel/test-fs-write-file-buffer.js
@@ -28,7 +28,6 @@
'use strict';
require('../common');
-const join = require('path').join;
const util = require('util');
const fs = require('fs');
@@ -57,6 +56,6 @@ const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
const buf = Buffer.from(data, 'base64');
-fs.writeFileSync(join(tmpdir.path, 'test.jpg'), buf);
+fs.writeFileSync(tmpdir.resolve('test.jpg'), buf);
util.log('Done!');
diff --git a/tests/node_compat/test/parallel/test-fs-write-file-invalid-path.js b/tests/node_compat/test/parallel/test-fs-write-file-invalid-path.js
index cec74e7cc..063f3e491 100644
--- a/tests/node_compat/test/parallel/test-fs-write-file-invalid-path.js
+++ b/tests/node_compat/test/parallel/test-fs-write-file-invalid-path.js
@@ -10,7 +10,6 @@
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
-const path = require('path');
if (!common.isWindows)
common.skip('This test is for Windows only.');
@@ -25,7 +24,7 @@ const DATA_VALUE = 'hello';
const RESERVED_CHARACTERS = '<>"|?*';
[...RESERVED_CHARACTERS].forEach((ch) => {
- const pathname = path.join(tmpdir.path, `somefile_${ch}`);
+ const pathname = tmpdir.resolve(`somefile_${ch}`);
assert.throws(
() => {
fs.writeFileSync(pathname, DATA_VALUE);
@@ -36,7 +35,7 @@ const RESERVED_CHARACTERS = '<>"|?*';
// Test for ':' (NTFS data streams).
// Refs: https://msdn.microsoft.com/en-us/library/windows/desktop/bb540537.aspx
-const pathname = path.join(tmpdir.path, 'foo:bar');
+const pathname = tmpdir.resolve('foo:bar');
fs.writeFileSync(pathname, DATA_VALUE);
let content = '';
diff --git a/tests/node_compat/test/parallel/test-fs-write-file-sync.js b/tests/node_compat/test/parallel/test-fs-write-file-sync.js
index d23523ad3..e7da85260 100644
--- a/tests/node_compat/test/parallel/test-fs-write-file-sync.js
+++ b/tests/node_compat/test/parallel/test-fs-write-file-sync.js
@@ -33,7 +33,6 @@ if (!common.isMainThread)
common.skip('Setting process.umask is not supported in Workers');
const assert = require('assert');
-const path = require('path');
const fs = require('fs');
// On Windows chmod is only able to manipulate read-only bit. Test if creating
@@ -48,7 +47,7 @@ tmpdir.refresh();
// Test writeFileSync
{
- const file = path.join(tmpdir.path, 'testWriteFileSync.txt');
+ const file = tmpdir.resolve('testWriteFileSync.txt');
fs.writeFileSync(file, '123', { mode });
const content = fs.readFileSync(file, { encoding: 'utf8' });
@@ -58,7 +57,7 @@ tmpdir.refresh();
// Test appendFileSync
{
- const file = path.join(tmpdir.path, 'testAppendFileSync.txt');
+ const file = tmpdir.resolve('testAppendFileSync.txt');
fs.appendFileSync(file, 'abc', { mode });
const content = fs.readFileSync(file, { encoding: 'utf8' });
@@ -84,7 +83,7 @@ tmpdir.refresh();
return _closeSync(...args);
};
- const file = path.join(tmpdir.path, 'testWriteFileSyncFd.txt');
+ const file = tmpdir.resolve('testWriteFileSyncFd.txt');
const fd = fs.openSync(file, 'w+', mode);
fs.writeFileSync(fd, '123');
@@ -101,7 +100,7 @@ tmpdir.refresh();
// Test writeFileSync with flags
{
- const file = path.join(tmpdir.path, 'testWriteFileSyncFlags.txt');
+ const file = tmpdir.resolve('testWriteFileSyncFlags.txt');
fs.writeFileSync(file, 'hello ', { encoding: 'utf8', flag: 'a' });
fs.writeFileSync(file, 'world!', { encoding: 'utf8', flag: 'a' });
@@ -109,20 +108,36 @@ tmpdir.refresh();
assert.strictEqual(content, 'hello world!');
}
-// Test writeFileSync with an object with an own toString function
+// Test writeFileSync with no flags
{
- // Runtime deprecated by DEP0162
- common.expectWarning('DeprecationWarning',
- 'Implicit coercion of objects with own toString property is deprecated.',
- 'DEP0162');
- const file = path.join(tmpdir.path, 'testWriteFileSyncStringify.txt');
- const data = {
- toString() {
- return 'hello world!';
- }
- };
+ const utf8Data = 'hello world!';
+ for (const test of [
+ { data: utf8Data },
+ { data: utf8Data, options: { encoding: 'utf8' } },
+ { data: Buffer.from(utf8Data, 'utf8').toString('hex'), options: { encoding: 'hex' } },
+ ]) {
+ const file = tmpdir.resolve(`testWriteFileSyncNewFile_${Math.random()}.txt`);
+ fs.writeFileSync(file, test.data, test.options);
+
+ const content = fs.readFileSync(file, { encoding: 'utf-8' });
+ assert.strictEqual(content, utf8Data);
+ }
+}
- fs.writeFileSync(file, data, { encoding: 'utf8', flag: 'a' });
- const content = fs.readFileSync(file, { encoding: 'utf8' });
- assert.strictEqual(content, String(data));
+// Test writeFileSync with an invalid input
+{
+ const file = tmpdir.resolve('testWriteFileSyncInvalid.txt');
+ for (const data of [
+ false, 5, {}, [], null, undefined, true, 5n, () => {}, Symbol(), new Map(),
+ new String('notPrimitive'),
+ { [Symbol.toPrimitive]: (hint) => 'amObject' },
+ { toString() { return 'amObject'; } },
+ Promise.resolve('amPromise'),
+ common.mustNotCall(),
+ ]) {
+ assert.throws(
+ () => fs.writeFileSync(file, data, { encoding: 'utf8', flag: 'a' }),
+ { code: 'ERR_INVALID_ARG_TYPE' }
+ );
+ }
}
diff --git a/tests/node_compat/test/parallel/test-fs-write-stream-autoclose-option.js b/tests/node_compat/test/parallel/test-fs-write-stream-autoclose-option.js
index d4158b4ad..480f7dcdb 100644
--- a/tests/node_compat/test/parallel/test-fs-write-stream-autoclose-option.js
+++ b/tests/node_compat/test/parallel/test-fs-write-stream-autoclose-option.js
@@ -8,12 +8,11 @@
'use strict';
const common = require('../common');
const assert = require('assert');
-const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
-const file = path.join(tmpdir.path, 'write-autoclose-opt1.txt');
+const file = tmpdir.resolve('write-autoclose-opt1.txt');
tmpdir.refresh();
let stream = fs.createWriteStream(file, { flags: 'w+', autoClose: false });
stream.write('Test1');
diff --git a/tests/node_compat/test/parallel/test-fs-write-stream-close-without-callback.js b/tests/node_compat/test/parallel/test-fs-write-stream-close-without-callback.js
index 9cd124840..ad685be77 100644
--- a/tests/node_compat/test/parallel/test-fs-write-stream-close-without-callback.js
+++ b/tests/node_compat/test/parallel/test-fs-write-stream-close-without-callback.js
@@ -9,12 +9,11 @@
require('../common');
const fs = require('fs');
-const path = require('path');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
-const s = fs.createWriteStream(path.join(tmpdir.path, 'nocallback'));
+const s = fs.createWriteStream(tmpdir.resolve('nocallback'));
s.end('hello world');
s.close();
diff --git a/tests/node_compat/test/parallel/test-fs-write-stream-double-close.js b/tests/node_compat/test/parallel/test-fs-write-stream-double-close.js
index ae0f1d8f1..0f5733308 100644
--- a/tests/node_compat/test/parallel/test-fs-write-stream-double-close.js
+++ b/tests/node_compat/test/parallel/test-fs-write-stream-double-close.js
@@ -10,20 +10,19 @@
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
-const path = require('path');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
{
- const s = fs.createWriteStream(path.join(tmpdir.path, 'rw'));
+ const s = fs.createWriteStream(tmpdir.resolve('rw'));
s.close(common.mustCall());
s.close(common.mustCall());
}
{
- const s = fs.createWriteStream(path.join(tmpdir.path, 'rw2'));
+ const s = fs.createWriteStream(tmpdir.resolve('rw2'));
let emits = 0;
s.on('close', () => {
@@ -44,7 +43,7 @@ tmpdir.refresh();
}
{
- const s = fs.createWriteStream(path.join(tmpdir.path, 'rw'), {
+ const s = fs.createWriteStream(tmpdir.resolve('rw'), {
autoClose: false
});
diff --git a/tests/node_compat/test/parallel/test-fs-write-stream-end.js b/tests/node_compat/test/parallel/test-fs-write-stream-end.js
index d2458cd38..3221a558e 100644
--- a/tests/node_compat/test/parallel/test-fs-write-stream-end.js
+++ b/tests/node_compat/test/parallel/test-fs-write-stream-end.js
@@ -29,21 +29,20 @@
'use strict';
const common = require('../common');
const assert = require('assert');
-const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
{
- const file = path.join(tmpdir.path, 'write-end-test0.txt');
+ const file = tmpdir.resolve('write-end-test0.txt');
const stream = fs.createWriteStream(file);
stream.end();
stream.on('close', common.mustCall());
}
{
- const file = path.join(tmpdir.path, 'write-end-test1.txt');
+ const file = tmpdir.resolve('write-end-test1.txt');
const stream = fs.createWriteStream(file);
stream.end('a\n', 'utf8');
stream.on('close', common.mustCall(function() {
@@ -53,7 +52,7 @@ tmpdir.refresh();
}
{
- const file = path.join(tmpdir.path, 'write-end-test2.txt');
+ const file = tmpdir.resolve('write-end-test2.txt');
const stream = fs.createWriteStream(file);
stream.end();
diff --git a/tests/node_compat/test/parallel/test-fs-write-stream-fs.js b/tests/node_compat/test/parallel/test-fs-write-stream-fs.js
index 44511cf81..253f5e425 100644
--- a/tests/node_compat/test/parallel/test-fs-write-stream-fs.js
+++ b/tests/node_compat/test/parallel/test-fs-write-stream-fs.js
@@ -7,14 +7,13 @@
'use strict';
const common = require('../common');
-const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
{
- const file = path.join(tmpdir.path, 'write-end-test0.txt');
+ const file = tmpdir.resolve('write-end-test0.txt');
const stream = fs.createWriteStream(file, {
fs: {
open: common.mustCall(fs.open),
@@ -28,7 +27,7 @@ tmpdir.refresh();
{
- const file = path.join(tmpdir.path, 'write-end-test1.txt');
+ const file = tmpdir.resolve('write-end-test1.txt');
const stream = fs.createWriteStream(file, {
fs: {
open: common.mustCall(fs.open),
diff --git a/tests/node_compat/test/parallel/test-fs-write-stream-throw-type-error.js b/tests/node_compat/test/parallel/test-fs-write-stream-throw-type-error.js
index b60d613b7..988512aa3 100644
--- a/tests/node_compat/test/parallel/test-fs-write-stream-throw-type-error.js
+++ b/tests/node_compat/test/parallel/test-fs-write-stream-throw-type-error.js
@@ -9,11 +9,10 @@
require('../common');
const assert = require('assert');
const fs = require('fs');
-const path = require('path');
const tmpdir = require('../common/tmpdir');
-const example = path.join(tmpdir.path, 'dummy');
+const example = tmpdir.resolve('dummy');
tmpdir.refresh();
// Should not throw.
diff --git a/tests/node_compat/test/parallel/test-fs-write-stream.js b/tests/node_compat/test/parallel/test-fs-write-stream.js
index a1f715094..107f22af0 100644
--- a/tests/node_compat/test/parallel/test-fs-write-stream.js
+++ b/tests/node_compat/test/parallel/test-fs-write-stream.js
@@ -29,12 +29,11 @@
'use strict';
const common = require('../common');
const assert = require('assert');
-const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
-const file = path.join(tmpdir.path, 'write.txt');
+const file = tmpdir.resolve('write.txt');
tmpdir.refresh();
diff --git a/tests/node_compat/test/parallel/test-fs-write-sync.js b/tests/node_compat/test/parallel/test-fs-write-sync.js
index ade0849ce..e65923102 100644
--- a/tests/node_compat/test/parallel/test-fs-write-sync.js
+++ b/tests/node_compat/test/parallel/test-fs-write-sync.js
@@ -29,10 +29,9 @@
'use strict';
require('../common');
const assert = require('assert');
-const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
-const filename = path.join(tmpdir.path, 'write.txt');
+const filename = tmpdir.resolve('write.txt');
tmpdir.refresh();
diff --git a/tests/node_compat/test/parallel/test-fs-write.js b/tests/node_compat/test/parallel/test-fs-write.js
index 33fcb84cf..e10db287f 100644
--- a/tests/node_compat/test/parallel/test-fs-write.js
+++ b/tests/node_compat/test/parallel/test-fs-write.js
@@ -2,8 +2,8 @@
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
-// Taken from Node 16.13.0
-// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
+// Taken from Node 18.12.1
+// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
// Copyright Joyent, Inc. and other Node contributors.
//
@@ -30,17 +30,15 @@
'use strict';
const common = require('../common');
const assert = require('assert');
-const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
-const fn = path.join(tmpdir.path, 'write.txt');
-const fn2 = path.join(tmpdir.path, 'write2.txt');
-const fn3 = path.join(tmpdir.path, 'write3.txt');
-const fn4 = path.join(tmpdir.path, 'write4.txt');
-const fn5 = path.join(tmpdir.path, 'write5.txt');
+const fn = tmpdir.resolve('write.txt');
+const fn2 = tmpdir.resolve('write2.txt');
+const fn3 = tmpdir.resolve('write3.txt');
+const fn4 = tmpdir.resolve('write4.txt');
const expected = 'ümlaut.';
const constants = fs.constants;
@@ -106,9 +104,6 @@ fs.open(fn, 'w', 0o644, common.mustSucceed((fd) => {
fs.write(fd, '', 0, 'utf8', written);
}));
-// TODO(kt3k): Enable this test when fs.open supports number for `flags`
-// paramter.
-/*
const args = constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC;
fs.open(fn2, args, 0o644, common.mustSucceed((fd) => {
const done = common.mustSucceed((written) => {
@@ -126,7 +121,6 @@ fs.open(fn2, args, 0o644, common.mustSucceed((fd) => {
fs.write(fd, '', 0, 'utf8', written);
}));
-*/
fs.open(fn3, 'w', 0o644, common.mustSucceed((fd) => {
const done = common.mustSucceed((written) => {
@@ -137,17 +131,6 @@ fs.open(fn3, 'w', 0o644, common.mustSucceed((fd) => {
fs.write(fd, expected, done);
}));
-fs.open(fn4, 'w', 0o644, common.mustSucceed((fd) => {
- const done = common.mustSucceed((written) => {
- assert.strictEqual(written, Buffer.byteLength(expected));
- fs.closeSync(fd);
- });
-
- const data = {
- toString() { return expected; }
- };
- fs.write(fd, data, done);
-}));
[false, 'test', {}, [], null, undefined].forEach((i) => {
assert.throws(
@@ -166,7 +149,14 @@ fs.open(fn4, 'w', 0o644, common.mustSucceed((fd) => {
);
});
-[false, 5, {}, [], null, undefined].forEach((data) => {
+[
+ false, 5, {}, [], null, undefined, true, 5n, () => {}, Symbol(), new Map(),
+ new String('notPrimitive'),
+ { [Symbol.toPrimitive]: (hint) => 'amObject' },
+ { toString() { return 'amObject'; } },
+ Promise.resolve('amPromise'),
+ common.mustNotCall(),
+].forEach((data) => {
assert.throws(
() => fs.write(1, data, common.mustNotCall()),
{
@@ -185,7 +175,7 @@ fs.open(fn4, 'w', 0o644, common.mustSucceed((fd) => {
{
// Regression test for https://github.com/nodejs/node/issues/38168
- const fd = fs.openSync(fn5, 'w');
+ const fd = fs.openSync(fn4, 'w');
assert.throws(
() => fs.writeSync(fd, 'abc', 0, 'hex'),
diff --git a/tests/node_compat/test/parallel/test-fs-writev-sync.js b/tests/node_compat/test/parallel/test-fs-writev-sync.js
index ba90f693a..35db3675f 100644
--- a/tests/node_compat/test/parallel/test-fs-writev-sync.js
+++ b/tests/node_compat/test/parallel/test-fs-writev-sync.js
@@ -9,7 +9,6 @@
require('../common');
const assert = require('assert');
-const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
@@ -17,7 +16,7 @@ tmpdir.refresh();
const expected = 'ümlaut. Лорем 運務ホソモ指及 आपको करने विकास 紙読決多密所 أضف';
-const getFileName = (i) => path.join(tmpdir.path, `writev_sync_${i}.txt`);
+const getFileName = (i) => tmpdir.resolve(`writev_sync_${i}.txt`);
/**
* Testing with a array of buffers input
diff --git a/tests/node_compat/test/parallel/test-http-agent-getname.js b/tests/node_compat/test/parallel/test-http-agent-getname.js
index 43dc09f2c..530cc1378 100644
--- a/tests/node_compat/test/parallel/test-http-agent-getname.js
+++ b/tests/node_compat/test/parallel/test-http-agent-getname.js
@@ -10,7 +10,6 @@
require('../common');
const assert = require('assert');
const http = require('http');
-const path = require('path');
const tmpdir = require('../common/tmpdir');
@@ -48,7 +47,7 @@ assert.strictEqual(
);
// unix socket
-const socketPath = path.join(tmpdir.path, 'foo', 'bar');
+const socketPath = tmpdir.resolve('foo', 'bar');
assert.strictEqual(
agent.getName({
socketPath
diff --git a/tests/node_compat/test/parallel/test-http-outgoing-internal-headernames-getter.js b/tests/node_compat/test/parallel/test-http-outgoing-internal-headernames-getter.js
index 4cca65000..490d814b9 100644
--- a/tests/node_compat/test/parallel/test-http-outgoing-internal-headernames-getter.js
+++ b/tests/node_compat/test/parallel/test-http-outgoing-internal-headernames-getter.js
@@ -24,7 +24,7 @@ common.expectWarning('DeprecationWarning', warn, 'DEP0066');
// Tests _headerNames getter result after setting a header.
const outgoingMessage = new OutgoingMessage();
outgoingMessage.setHeader('key', 'value');
- const expect = Object.create(null);
+ const expect = { __proto__: null };
expect.key = 'key';
assert.deepStrictEqual(outgoingMessage._headerNames, expect);
}
diff --git a/tests/node_compat/test/parallel/test-http-url.parse-only-support-http-https-protocol.js b/tests/node_compat/test/parallel/test-http-url.parse-only-support-http-https-protocol.js
index bc90d70b4..98b222f39 100644
--- a/tests/node_compat/test/parallel/test-http-url.parse-only-support-http-https-protocol.js
+++ b/tests/node_compat/test/parallel/test-http-url.parse-only-support-http-https-protocol.js
@@ -41,7 +41,7 @@ const invalidUrls = [
'f://some.host/path',
];
-invalidUrls.forEach((invalid) => {
+for (const invalid of invalidUrls) {
assert.throws(
() => { http.request(url.parse(invalid)); },
{
@@ -49,4 +49,4 @@ invalidUrls.forEach((invalid) => {
name: 'TypeError'
}
);
-});
+}
diff --git a/tests/node_compat/test/parallel/test-net-isipv4.js b/tests/node_compat/test/parallel/test-net-isipv4.js
index 1589196d5..cdc9f22ac 100644
--- a/tests/node_compat/test/parallel/test-net-isipv4.js
+++ b/tests/node_compat/test/parallel/test-net-isipv4.js
@@ -44,10 +44,10 @@ const v4not = [
'192.168.0.2000000000',
];
-v4.forEach((ip) => {
+for (const ip of v4) {
assert.strictEqual(net.isIPv4(ip), true);
-});
+}
-v4not.forEach((ip) => {
+for (const ip of v4not) {
assert.strictEqual(net.isIPv4(ip), false);
-});
+}
diff --git a/tests/node_compat/test/parallel/test-net-isipv6.js b/tests/node_compat/test/parallel/test-net-isipv6.js
index e74239d5d..752aa5aad 100644
--- a/tests/node_compat/test/parallel/test-net-isipv6.js
+++ b/tests/node_compat/test/parallel/test-net-isipv6.js
@@ -242,10 +242,10 @@ const v6not = [
'02001:0000:1234:0000:0000:C1C0:ABCD:0876',
];
-v6.forEach((ip) => {
+for (const ip of v6) {
assert.strictEqual(net.isIPv6(ip), true);
-});
+}
-v6not.forEach((ip) => {
+for (const ip of v6not) {
assert.strictEqual(net.isIPv6(ip), false);
-});
+}
diff --git a/tests/node_compat/test/parallel/test-parse-args.mjs b/tests/node_compat/test/parallel/test-parse-args.mjs
index f8bc14a6c..0d5aa72f6 100644
--- a/tests/node_compat/test/parallel/test-parse-args.mjs
+++ b/tests/node_compat/test/parallel/test-parse-args.mjs
@@ -458,7 +458,7 @@ const candidateGreedyOptions = [
'--foo',
];
-candidateGreedyOptions.forEach((value) => {
+for (const value of candidateGreedyOptions) {
test(`greedy: when short option with value '${value}' then eaten`, () => {
const args = ['-w', value];
const options = { with: { type: 'string', short: 'w' } };
@@ -476,7 +476,7 @@ candidateGreedyOptions.forEach((value) => {
const result = parseArgs({ args, options, strict: false });
assert.deepStrictEqual(result, expectedResult);
});
-});
+}
test('strict: when candidate option value is plain text then does not throw', () => {
const args = ['--with', 'abc'];
@@ -980,7 +980,7 @@ test('tokens:true should not include the default options after the args input',
test('proto as default value must be ignored', () => {
const args = [];
- const options = Object.create(null);
+ const options = { __proto__: null };
// eslint-disable-next-line no-proto
options.__proto__ = { type: 'string', default: 'HELLO' };
diff --git a/tests/node_compat/test/parallel/test-path-extname.js b/tests/node_compat/test/parallel/test-path-extname.js
index f5894058b..8cba90b07 100644
--- a/tests/node_compat/test/parallel/test-path-extname.js
+++ b/tests/node_compat/test/parallel/test-path-extname.js
@@ -13,7 +13,7 @@ const path = require('path');
const failures = [];
const slashRE = /\//g;
-[
+const testPaths = [
[__filename, '.js'],
['', ''],
['/path/to/file', ''],
@@ -57,10 +57,13 @@ const slashRE = /\//g;
['file//', ''],
['file./', '.'],
['file.//', '.'],
-].forEach((test) => {
- const expected = test[1];
- [path.posix.extname, path.win32.extname].forEach((extname) => {
- let input = test[0];
+];
+
+for (const testPath of testPaths) {
+ const expected = testPath[1];
+ const extNames = [path.posix.extname, path.win32.extname];
+ for (const extname of extNames) {
+ let input = testPath[0];
let os;
if (extname === path.win32.extname) {
input = input.replace(slashRE, '\\');
@@ -73,16 +76,14 @@ const slashRE = /\//g;
JSON.stringify(expected)}\n actual=${JSON.stringify(actual)}`;
if (actual !== expected)
failures.push(`\n${message}`);
- });
- {
- const input = `C:${test[0].replace(slashRE, '\\')}`;
- const actual = path.win32.extname(input);
- const message = `path.win32.extname(${JSON.stringify(input)})\n expect=${
- JSON.stringify(expected)}\n actual=${JSON.stringify(actual)}`;
- if (actual !== expected)
- failures.push(`\n${message}`);
}
-});
+ const input = `C:${testPath[0].replace(slashRE, '\\')}`;
+ const actual = path.win32.extname(input);
+ const message = `path.win32.extname(${JSON.stringify(input)})\n expect=${
+ JSON.stringify(expected)}\n actual=${JSON.stringify(actual)}`;
+ if (actual !== expected)
+ failures.push(`\n${message}`);
+}
assert.strictEqual(failures.length, 0, failures.join(''));
// On Windows, backslash is a path separator.
diff --git a/tests/node_compat/test/parallel/test-path-parse-format.js b/tests/node_compat/test/parallel/test-path-parse-format.js
index 5b31751f2..7f4682899 100644
--- a/tests/node_compat/test/parallel/test-path-parse-format.js
+++ b/tests/node_compat/test/parallel/test-path-parse-format.js
@@ -231,3 +231,7 @@ function checkFormat(path, testCases) {
});
});
}
+
+// See https://github.com/nodejs/node/issues/44343
+assert.strictEqual(path.format({ name: 'x', ext: 'png' }), 'x.png');
+assert.strictEqual(path.format({ name: 'x', ext: '.png' }), 'x.png');
diff --git a/tests/node_compat/test/parallel/test-path.js b/tests/node_compat/test/parallel/test-path.js
index 41b760bff..2d0a92872 100644
--- a/tests/node_compat/test/parallel/test-path.js
+++ b/tests/node_compat/test/parallel/test-path.js
@@ -42,8 +42,8 @@ function fail(fn) {
}, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError' });
}
-typeErrorTests.forEach((test) => {
- [path.posix, path.win32].forEach((namespace) => {
+for (const test of typeErrorTests) {
+ for (const namespace of [path.posix, path.win32]) {
fail(namespace.join, test);
fail(namespace.resolve, test);
fail(namespace.normalize, test);
@@ -59,8 +59,8 @@ typeErrorTests.forEach((test) => {
if (test !== undefined) {
fail(namespace.basename, 'foo', test);
}
- });
-});
+ }
+}
// path.sep tests
// windows
diff --git a/tests/node_compat/test/parallel/test-readline-keys.js b/tests/node_compat/test/parallel/test-readline-keys.js
index ec68f7faa..4487e8d71 100644
--- a/tests/node_compat/test/parallel/test-readline-keys.js
+++ b/tests/node_compat/test/parallel/test-readline-keys.js
@@ -41,9 +41,9 @@ function addTest(sequences, expectedKeys) {
keys = [];
- sequences.forEach((sequence) => {
+ for (const sequence of sequences) {
fi.write(sequence);
- });
+ }
assert.deepStrictEqual(keys, expectedKeys);
}
diff --git a/tests/node_compat/test/parallel/test-stream-buffer-list.js b/tests/node_compat/test/parallel/test-stream-buffer-list.js
deleted file mode 100644
index 08abd2459..000000000
--- a/tests/node_compat/test/parallel/test-stream-buffer-list.js
+++ /dev/null
@@ -1,91 +0,0 @@
-// 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 `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
-
-// Flags: --expose-internals
-'use strict';
-require('../common');
-const assert = require('assert');
-const BufferList = require('internal/streams/buffer_list');
-
-// Test empty buffer list.
-const emptyList = new BufferList();
-
-emptyList.shift();
-assert.deepStrictEqual(emptyList, new BufferList());
-
-assert.strictEqual(emptyList.join(','), '');
-
-assert.deepStrictEqual(emptyList.concat(0), Buffer.alloc(0));
-
-const buf = Buffer.from('foo');
-
-function testIterator(list, count) {
- // test iterator
- let len = 0;
- // eslint-disable-next-line no-unused-vars
- for (const x of list) {
- len++;
- }
- assert.strictEqual(len, count);
-}
-
-// Test buffer list with one element.
-const list = new BufferList();
-testIterator(list, 0);
-
-list.push(buf);
-testIterator(list, 1);
-for (const x of list) {
- assert.strictEqual(x, buf);
-}
-
-const copy = list.concat(3);
-testIterator(copy, 3);
-
-assert.notStrictEqual(copy, buf);
-assert.deepStrictEqual(copy, buf);
-
-assert.strictEqual(list.join(','), 'foo');
-
-const shifted = list.shift();
-testIterator(list, 0);
-assert.strictEqual(shifted, buf);
-assert.deepStrictEqual(list, new BufferList());
-
-{
- const list = new BufferList();
- list.push('foo');
- list.push('bar');
- list.push('foo');
- list.push('bar');
- assert.strictEqual(list.consume(6, true), 'foobar');
- assert.strictEqual(list.consume(6, true), 'foobar');
-}
-
-{
- const list = new BufferList();
- list.push('foo');
- list.push('bar');
- assert.strictEqual(list.consume(5, true), 'fooba');
-}
-
-{
- const list = new BufferList();
- list.push(buf);
- list.push(buf);
- list.push(buf);
- list.push(buf);
- assert.strictEqual(list.consume(6).toString(), 'foofoo');
- assert.strictEqual(list.consume(6).toString(), 'foofoo');
-}
-
-{
- const list = new BufferList();
- list.push(buf);
- list.push(buf);
- assert.strictEqual(list.consume(5).toString(), 'foofo');
-}
diff --git a/tests/node_compat/test/parallel/test-stream-readable-destroy.js b/tests/node_compat/test/parallel/test-stream-readable-destroy.js
index a8b7b8932..75cec92dc 100644
--- a/tests/node_compat/test/parallel/test-stream-readable-destroy.js
+++ b/tests/node_compat/test/parallel/test-stream-readable-destroy.js
@@ -325,7 +325,7 @@ const assert = require('assert');
assert.rejects((async () => {
// eslint-disable-next-line no-unused-vars, no-empty
for await (const chunk of read) { }
- })(), /AbortError/);
+ })(), /AbortError/).then(common.mustCall());
setTimeout(() => controller.abort(), 0);
}
diff --git a/tests/node_compat/test/parallel/test-stream-uint8array.js b/tests/node_compat/test/parallel/test-stream-uint8array.js
index 3ac81e672..aa8dbd3d8 100644
--- a/tests/node_compat/test/parallel/test-stream-uint8array.js
+++ b/tests/node_compat/test/parallel/test-stream-uint8array.js
@@ -45,7 +45,7 @@ const GHI = new Uint8Array([0x47, 0x48, 0x49]);
assert(!(chunk instanceof Buffer));
assert(chunk instanceof Uint8Array);
assert.strictEqual(chunk, ABC);
- assert.strictEqual(encoding, 'utf8');
+ assert.strictEqual(encoding, undefined);
cb();
})
});
diff --git a/tests/node_compat/test/parallel/test-stream-writable-decoded-encoding.js b/tests/node_compat/test/parallel/test-stream-writable-decoded-encoding.js
index e8fbbb0fa..d6c77c9a7 100644
--- a/tests/node_compat/test/parallel/test-stream-writable-decoded-encoding.js
+++ b/tests/node_compat/test/parallel/test-stream-writable-decoded-encoding.js
@@ -63,3 +63,50 @@ class MyWritable extends stream.Writable {
m.write('some-text', 'utf8');
m.end();
}
+
+{
+ assert.throws(() => {
+ const m = new MyWritable(null, {
+ defaultEncoding: 'my invalid encoding',
+ });
+ m.end();
+ }, {
+ code: 'ERR_UNKNOWN_ENCODING',
+ });
+}
+
+{
+ const w = new MyWritable(function(isBuffer, type, enc) {
+ assert(!isBuffer);
+ assert.strictEqual(type, 'string');
+ assert.strictEqual(enc, 'hex');
+ }, {
+ defaultEncoding: 'hex',
+ decodeStrings: false
+ });
+ w.write('asd');
+ w.end();
+}
+
+{
+ const w = new MyWritable(function(isBuffer, type, enc) {
+ assert(!isBuffer);
+ assert.strictEqual(type, 'string');
+ assert.strictEqual(enc, 'utf8');
+ }, {
+ defaultEncoding: null,
+ decodeStrings: false
+ });
+ w.write('asd');
+ w.end();
+}
+
+{
+ const m = new MyWritable(function(isBuffer, type, enc) {
+ assert.strictEqual(type, 'object');
+ assert.strictEqual(enc, 'utf8');
+ }, { defaultEncoding: 'hex',
+ objectMode: true });
+ m.write({ foo: 'bar' }, 'utf8');
+ m.end();
+}
diff --git a/tests/node_compat/test/parallel/test-stream-writable-end-cb-error.js b/tests/node_compat/test/parallel/test-stream-writable-end-cb-error.js
index f4d5a3995..ecb597f15 100644
--- a/tests/node_compat/test/parallel/test-stream-writable-end-cb-error.js
+++ b/tests/node_compat/test/parallel/test-stream-writable-end-cb-error.js
@@ -43,7 +43,7 @@ const stream = require('stream');
let called = false;
writable.end('asd', common.mustCall((err) => {
called = true;
- assert.strictEqual(err, undefined);
+ assert.strictEqual(err, null);
}));
writable.on('error', common.mustCall((err) => {
diff --git a/tests/node_compat/test/parallel/test-stream2-readable-from-list.js b/tests/node_compat/test/parallel/test-stream2-readable-from-list.js
deleted file mode 100644
index fea8aefda..000000000
--- a/tests/node_compat/test/parallel/test-stream2-readable-from-list.js
+++ /dev/null
@@ -1,108 +0,0 @@
-// 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 `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
-
-// Copyright Joyent, Inc. and other Node contributors.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to permit
-// persons to whom the Software is furnished to do so, subject to the
-// following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-// Flags: --expose-internals
-'use strict';
-require('../common');
-const assert = require('assert');
-const fromList = require('stream').Readable._fromList;
-const BufferList = require('internal/streams/buffer_list');
-const util = require('util');
-
-function bufferListFromArray(arr) {
- const bl = new BufferList();
- for (let i = 0; i < arr.length; ++i)
- bl.push(arr[i]);
- return bl;
-}
-
-{
- // Verify behavior with buffers
- let list = [ Buffer.from('foog'),
- Buffer.from('bark'),
- Buffer.from('bazy'),
- Buffer.from('kuel') ];
- list = bufferListFromArray(list);
-
- assert.strictEqual(
- util.inspect([ list ], { compact: false }),
- `[
- BufferList {
- head: [Object],
- tail: [Object],
- length: 4
- }
-]`);
-
- // Read more than the first element.
- let ret = fromList(6, { buffer: list, length: 16 });
- assert.strictEqual(ret.toString(), 'foogba');
-
- // Read exactly the first element.
- ret = fromList(2, { buffer: list, length: 10 });
- assert.strictEqual(ret.toString(), 'rk');
-
- // Read less than the first element.
- ret = fromList(2, { buffer: list, length: 8 });
- assert.strictEqual(ret.toString(), 'ba');
-
- // Read more than we have.
- ret = fromList(100, { buffer: list, length: 6 });
- assert.strictEqual(ret.toString(), 'zykuel');
-
- // all consumed.
- assert.deepStrictEqual(list, new BufferList());
-}
-
-{
- // Verify behavior with strings
- let list = [ 'foog',
- 'bark',
- 'bazy',
- 'kuel' ];
- list = bufferListFromArray(list);
-
- // Read more than the first element.
- let ret = fromList(6, { buffer: list, length: 16, decoder: true });
- assert.strictEqual(ret, 'foogba');
-
- // Read exactly the first element.
- ret = fromList(2, { buffer: list, length: 10, decoder: true });
- assert.strictEqual(ret, 'rk');
-
- // Read less than the first element.
- ret = fromList(2, { buffer: list, length: 8, decoder: true });
- assert.strictEqual(ret, 'ba');
-
- // Read more than we have.
- ret = fromList(100, { buffer: list, length: 6, decoder: true });
- assert.strictEqual(ret, 'zykuel');
-
- // all consumed.
- assert.deepStrictEqual(list, new BufferList());
-}
diff --git a/tests/node_compat/test/parallel/test-stream2-writable.js b/tests/node_compat/test/parallel/test-stream2-writable.js
index 665ff507f..4f5ba53fc 100644
--- a/tests/node_compat/test/parallel/test-stream2-writable.js
+++ b/tests/node_compat/test/parallel/test-stream2-writable.js
@@ -201,7 +201,8 @@ for (let i = 0; i < chunks.length; i++) {
{
// Verify write callbacks
const callbacks = chunks.map(function(chunk, i) {
- return [i, function() {
+ return [i, function(err) {
+ assert.strictEqual(err, null);
callbacks._called[i] = chunk;
}];
}).reduce(function(set, x) {
@@ -232,7 +233,9 @@ for (let i = 0; i < chunks.length; i++) {
{
// Verify end() callback
const tw = new TestWriter();
- tw.end(common.mustCall());
+ tw.end(common.mustCall(function(err) {
+ assert.strictEqual(err, null);
+ }));
}
const helloWorldBuffer = Buffer.from('hello world');
@@ -240,7 +243,9 @@ const helloWorldBuffer = Buffer.from('hello world');
{
// Verify end() callback with chunk
const tw = new TestWriter();
- tw.end(helloWorldBuffer, common.mustCall());
+ tw.end(helloWorldBuffer, common.mustCall(function(err) {
+ assert.strictEqual(err, null);
+ }));
}
{
diff --git a/tests/node_compat/test/parallel/test-url-format-whatwg.js b/tests/node_compat/test/parallel/test-url-format-whatwg.js
index 9552fd7da..ff8f1201c 100644
--- a/tests/node_compat/test/parallel/test-url-format-whatwg.js
+++ b/tests/node_compat/test/parallel/test-url-format-whatwg.js
@@ -147,3 +147,8 @@ assert.strictEqual(
url.format(new URL('http://user:pass@xn--0zwm56d.com:8080/path'), { unicode: true }),
'http://user:pass@测试.com:8080/path'
);
+
+assert.strictEqual(
+ url.format(new URL('tel:123')),
+ url.format(new URL('tel:123'), { unicode: true })
+);
diff --git a/tests/node_compat/test/parallel/test-url-parse-invalid-input.js b/tests/node_compat/test/parallel/test-url-parse-invalid-input.js
index 98d2d7e2d..7e8aa5c04 100644
--- a/tests/node_compat/test/parallel/test-url-parse-invalid-input.js
+++ b/tests/node_compat/test/parallel/test-url-parse-invalid-input.js
@@ -81,3 +81,33 @@ if (common.hasIntl) {
(e) => e.code === 'ERR_INVALID_URL',
'parsing http://\u00AD/bad.com/');
}
+
+/*
+ FIXME(kt3k): node -e <script> doesn't work in deno
+{
+ const badURLs = [
+ 'https://evil.com:.example.com',
+ 'git+ssh://git@github.com:npm/npm',
+ ];
+ badURLs.forEach((badURL) => {
+ common.spawnPromisified(process.execPath, ['-e', `url.parse(${JSON.stringify(badURL)})`])
+ .then(common.mustCall(({ code, stdout, stderr }) => {
+ assert.strictEqual(code, 0);
+ assert.strictEqual(stdout, '');
+ assert.match(stderr, /\[DEP0170\] DeprecationWarning:/);
+ }));
+ });
+
+ // Warning should only happen once per process.
+ const expectedWarning = [
+ `The URL ${badURLs[0]} is invalid. Future versions of Node.js will throw an error.`,
+ 'DEP0170',
+ ];
+ common.expectWarning({
+ DeprecationWarning: expectedWarning,
+ });
+ badURLs.forEach((badURL) => {
+ url.parse(badURL);
+ });
+}
+*/
diff --git a/tests/node_compat/test/parallel/test-url-parse-query.js b/tests/node_compat/test/parallel/test-url-parse-query.js
index 2621a5542..6f6c425bb 100644
--- a/tests/node_compat/test/parallel/test-url-parse-query.js
+++ b/tests/node_compat/test/parallel/test-url-parse-query.js
@@ -11,7 +11,7 @@ const assert = require('assert');
const url = require('url');
function createWithNoPrototype(properties = []) {
- const noProto = Object.create(null);
+ const noProto = { __proto__: null };
properties.forEach((property) => {
noProto[property.key] = property.value;
});
diff --git a/tests/node_compat/test/parallel/test-url-pathtofileurl.js b/tests/node_compat/test/parallel/test-url-pathtofileurl.js
index 5bbabc225..d0f2f4b97 100644
--- a/tests/node_compat/test/parallel/test-url-pathtofileurl.js
+++ b/tests/node_compat/test/parallel/test-url-pathtofileurl.js
@@ -36,13 +36,30 @@ const url = require('url');
// Missing server:
assert.throws(() => url.pathToFileURL('\\\\\\no-server'), {
- code: 'ERR_INVALID_ARG_VALUE'
+ code: 'ERR_INVALID_ARG_VALUE',
});
// Missing share or resource:
assert.throws(() => url.pathToFileURL('\\\\host'), {
- code: 'ERR_INVALID_ARG_VALUE'
+ code: 'ERR_INVALID_ARG_VALUE',
});
+
+ // Regression test for direct String.prototype.startsWith call
+ assert.throws(() => url.pathToFileURL([
+ '\\\\',
+ { [Symbol.toPrimitive]: () => 'blep\\blop' },
+ ]), {
+ code: 'ERR_INVALID_ARG_TYPE',
+ });
+ assert.throws(() => url.pathToFileURL(['\\\\', 'blep\\blop']), {
+ code: 'ERR_INVALID_ARG_TYPE',
+ });
+ assert.throws(() => url.pathToFileURL({
+ [Symbol.toPrimitive]: () => '\\\\blep\\blop',
+ }), {
+ code: 'ERR_INVALID_ARG_TYPE',
+ });
+
} else {
// UNC paths on posix are considered a single path that has backslashes:
const fileURL = url.pathToFileURL('\\\\nas\\share\\path.txt').href;
@@ -151,3 +168,19 @@ const url = require('url');
assert.strictEqual(actual, expected);
}
}
+
+// Test for non-string parameter
+{
+ for (const badPath of [
+ undefined, null, true, 42, 42n, Symbol('42'), NaN, {}, [], () => {},
+ Promise.resolve('foo'),
+ new Date(),
+ new String('notPrimitive'),
+ { toString() { return 'amObject'; } },
+ { [Symbol.toPrimitive]: (hint) => 'amObject' },
+ ]) {
+ assert.throws(() => url.pathToFileURL(badPath), {
+ code: 'ERR_INVALID_ARG_TYPE',
+ });
+ }
+}
diff --git a/tests/node_compat/test/parallel/test-url-relative.js b/tests/node_compat/test/parallel/test-url-relative.js
index 8d0bc4127..3b8524c2d 100644
--- a/tests/node_compat/test/parallel/test-url-relative.js
+++ b/tests/node_compat/test/parallel/test-url-relative.js
@@ -62,13 +62,15 @@ const relativeTests = [
['http://localhost', 'file://foo/Users', 'file://foo/Users'],
['https://registry.npmjs.org', '@foo/bar', 'https://registry.npmjs.org/@foo/bar'],
];
-relativeTests.forEach(function(relativeTest) {
+for (let i = 0; i < relativeTests.length; i++) {
+ const relativeTest = relativeTests[i];
+
const a = url.resolve(relativeTest[0], relativeTest[1]);
const e = relativeTest[2];
assert.strictEqual(a, e,
`resolve(${relativeTest[0]}, ${relativeTest[1]})` +
` == ${e}\n actual=${a}`);
-});
+}
//
// Tests below taken from Chiron
@@ -381,19 +383,23 @@ const relativeTests2 = [
// No path at all
['#hash1', '#hash2', '#hash1'],
];
-relativeTests2.forEach(function(relativeTest) {
+for (let i = 0; i < relativeTests2.length; i++) {
+ const relativeTest = relativeTests2[i];
+
const a = url.resolve(relativeTest[1], relativeTest[0]);
const e = url.format(relativeTest[2]);
assert.strictEqual(a, e,
`resolve(${relativeTest[0]}, ${relativeTest[1]})` +
` == ${e}\n actual=${a}`);
-});
+}
// If format and parse are inverse operations then
// resolveObject(parse(x), y) == parse(resolve(x, y))
// format: [from, path, expected]
-relativeTests.forEach(function(relativeTest) {
+for (let i = 0; i < relativeTests.length; i++) {
+ const relativeTest = relativeTests[i];
+
let actual = url.resolveObject(url.parse(relativeTest[0]), relativeTest[1]);
let expected = url.parse(relativeTest[2]);
@@ -406,7 +412,8 @@ relativeTests.forEach(function(relativeTest) {
assert.strictEqual(actual, expected,
`format(${actual}) == ${expected}\n` +
`actual: ${actual}`);
-});
+
+}
// format: [to, from, result]
// the test: ['.//g', 'f:/a', 'f://g'] is a fundamental problem
@@ -422,7 +429,9 @@ if (relativeTests2[181][0] === './/g' &&
relativeTests2[181][2] === 'f://g') {
relativeTests2.splice(181, 1);
}
-relativeTests2.forEach(function(relativeTest) {
+for (let i = 0; i < relativeTests2.length; i++) {
+ const relativeTest = relativeTests2[i];
+
let actual = url.resolveObject(url.parse(relativeTest[1]), relativeTest[0]);
let expected = url.parse(relativeTest[2]);
@@ -438,4 +447,4 @@ relativeTests2.forEach(function(relativeTest) {
assert.strictEqual(actual, expected,
`format(${relativeTest[1]}) == ${expected}\n` +
`actual: ${actual}`);
-});
+}
diff --git a/tests/node_compat/test/parallel/test-whatwg-events-add-event-listener-options-signal.js b/tests/node_compat/test/parallel/test-whatwg-events-add-event-listener-options-signal.js
index 4378b7290..74055b00e 100644
--- a/tests/node_compat/test/parallel/test-whatwg-events-add-event-listener-options-signal.js
+++ b/tests/node_compat/test/parallel/test-whatwg-events-add-event-listener-options-signal.js
@@ -11,6 +11,7 @@ require('../common');
const {
strictEqual,
+ throws,
} = require('assert');
// Manually ported from: wpt@dom/events/AddEventListenerOptions-signal.any.js
@@ -164,3 +165,11 @@ const {
}, { once: true });
et.dispatchEvent(new Event('foo'));
}
+{
+ const et = new EventTarget();
+ [1, 1n, {}, [], null, true, 'hi', Symbol(), () => {}].forEach((signal) => {
+ throws(() => et.addEventListener('foo', () => {}, { signal }), {
+ name: 'TypeError',
+ });
+ });
+}