Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions test/parallel/test-btoa-atob.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ assert.strictEqual(atob({ toString: () => '' }), '');
assert.strictEqual(atob({ [Symbol.toPrimitive]: () => '' }), '');

assert.throws(() => atob(Symbol()), /TypeError/);
[
const testCases = [
undefined, false, () => {}, {}, [1],
0, 1, 0n, 1n, -Infinity,
'a', 'a\n\n\n', '\ra\r\r', ' a ', '\t\t\ta', 'a\f\f\f', '\ta\r \n\f',
].forEach((value) =>
// See #2 - https://html.spec.whatwg.org/multipage/webappapis.html#dom-atob
];

// See #2 - https://html.spec.whatwg.org/multipage/webappapis.html#dom-atob
for (const value of testCases) {
assert.throws(() => atob(value), {
constructor: DOMException,
name: 'InvalidCharacterError',
code: 5,
}));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ function test(stringVariant) {
child.on('exit', common.mustCall((code) => assert.strictEqual(code, 0)));
}

['pipe', 'inherit', 'ignore'].forEach(test);
const testCases = ['pipe', 'inherit', 'ignore'];
for (const value of testCases) {
test(value);
}
4 changes: 2 additions & 2 deletions test/parallel/test-child-process-ipc-next-tick.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ if (process.argv[2] === 'child') {

child.on('message', common.mustCall((msg) => {
assert.strictEqual(msg, 'ready');
values.forEach((value) => {
for (const value of values) {
child.send(value);
});
};
}));
}
4 changes: 3 additions & 1 deletion test/parallel/test-debugger-pid.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ interfacer.stderr.setEncoding('utf-8');
const onData = (data) => {
data = (buffer + data).split('\n');
buffer = data.pop();
data.forEach((line) => interfacer.emit('line', line));
for (const line of data) {
interfacer.emit('line', line);
}
};
interfacer.stdout.on('data', onData);
interfacer.stderr.on('data', onData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ require('../common');

const assert = require('assert');
const { internalBinding } = require('internal/test/binding');
[
const testCases = [
internalBinding('udp_wrap').UDP.prototype.bind6,
internalBinding('tcp_wrap').TCP.prototype.bind6,
internalBinding('udp_wrap').UDP.prototype.send6,
internalBinding('tcp_wrap').TCP.prototype.bind,
internalBinding('udp_wrap').UDP.prototype.close,
internalBinding('tcp_wrap').TCP.prototype.open,
].forEach((binding, i) => {
];
for (const [i, binding] of testCases.entries()) {
assert.strictEqual('prototype' in binding, false, `Test ${i} failed`);
});
}
4 changes: 2 additions & 2 deletions test/parallel/test-events-uncaught-exception-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const EventEmitter = require('events');
process.on('uncaughtException', common.mustCall((err) => {
const [firstLine, ...lines] = err.stack.split('\n');
assert.strictEqual(firstLine, 'Error');
lines.forEach((line) => {
for (const line of lines) {
assert.match(line, /^ {4}at/);
});
}
}));

new EventEmitter().emit('error', new Error());
7 changes: 4 additions & 3 deletions test/parallel/test-fs-buffertype-writesync.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ require('../common');
const assert = require('assert');
const fs = require('fs');

[
const testCases = [
true, false, 0, 1, Infinity, () => {}, {}, [], undefined, null,
].forEach((value) => {
];
for (const value of testCases) {
assert.throws(
() => fs.writeSync(1, value),
{ message: /"buffer"/, code: 'ERR_INVALID_ARG_TYPE' }
);
});
}
14 changes: 7 additions & 7 deletions test/parallel/test-fs-cp-sync-verbatim-symlinks-invalid.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import fixtures from '../common/fixtures.js';
tmpdir.refresh();

const src = fixtures.path('copy/kitchen-sink');
[1, [], {}, null, 1n, undefined, null, Symbol(), '', () => {}]
.forEach((verbatimSymlinks) => {
assert.throws(
() => cpSync(src, src, { verbatimSymlinks }),
{ code: 'ERR_INVALID_ARG_TYPE' }
);
});
const testCases = [1, [], {}, null, 1n, undefined, null, Symbol(), '', () => {}];
for (const verbatimSymlinks of testCases) {
assert.throws(
() => cpSync(src, src, { verbatimSymlinks }),
{ code: 'ERR_INVALID_ARG_TYPE' }
);
}
5 changes: 3 additions & 2 deletions test/parallel/test-fs-readlink-type-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const common = require('../common');
const assert = require('assert');
const fs = require('fs');

[false, 1, {}, [], null, undefined].forEach((i) => {
const testCases = [false, 1, {}, [], null, undefined];
for (const i of testCases) {
assert.throws(
() => fs.readlink(i, common.mustNotCall()),
{
Expand All @@ -19,4 +20,4 @@ const fs = require('fs');
name: 'TypeError'
}
);
});
}
5 changes: 3 additions & 2 deletions test/parallel/test-fs-rmdir-type-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const common = require('../common');
const assert = require('assert');
const fs = require('fs');

[false, 1, [], {}, null, undefined].forEach((i) => {
const testCases = [false, 1, [], {}, null, undefined];
for (const i of testCases) {
assert.throws(
() => fs.rmdir(i, common.mustNotCall()),
{
Expand All @@ -19,4 +20,4 @@ const fs = require('fs');
name: 'TypeError'
}
);
});
}
5 changes: 3 additions & 2 deletions test/parallel/test-fs-unlink-type-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const common = require('../common');
const assert = require('assert');
const fs = require('fs');

[false, 1, {}, [], null, undefined].forEach((i) => {
const testCases = [false, 1, {}, [], null, undefined];
for (const i of testCases) {
assert.throws(
() => fs.unlink(i, common.mustNotCall()),
{
Expand All @@ -19,4 +20,4 @@ const fs = require('fs');
name: 'TypeError'
}
);
});
}
4 changes: 2 additions & 2 deletions test/parallel/test-http-correct-hostname.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if (common.hasCrypto) {
modules.https = https;
}

Object.keys(modules).forEach((module) => {
for (const module of Object.keys(modules)) {
const doNotCall = common.mustNotCall(
`${module}.request should not connect to ${module}://example.com%60x.example.com`
);
Expand All @@ -25,4 +25,4 @@ Object.keys(modules).forEach((module) => {
'example.com`x.example.com',
]);
req.abort();
});
};
5 changes: 3 additions & 2 deletions test/parallel/test-http-hostname-typechecking.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const http = require('http');
// when passed as the value of either options.hostname or options.host
const vals = [{}, [], NaN, Infinity, -Infinity, true, false, 1, 0, new Date()];

vals.forEach((v) => {

for (const v of vals) {
const received = common.invalidArgTypeHelper(v);
assert.throws(
() => http.request({ hostname: v }),
Expand All @@ -31,7 +32,7 @@ vals.forEach((v) => {
received
}
);
});
}

// These values are OK and should not throw synchronously.
// Only testing for 'hostname' validation so ignore connection errors.
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-http-req-close-robust-from-tampering.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const { connect } = require('net');
// cause an error.

const server = createServer(common.mustCall((req, res) => {
req.client._events.close.forEach((fn) => { fn.bind(req)(); });
const closeHandlers = req.client._events.close;
for (const fn of closeHandlers) { fn.bind(req)(); }
}));

server.unref();
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-http-server-unconsume.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const assert = require('assert');
const http = require('http');
const net = require('net');

['on', 'addListener', 'prependListener'].forEach((testFn) => {
const testCases = ['on', 'addListener', 'prependListener'];
for (const testFn of testCases) {
let received = '';

const server = http.createServer(function(req, res) {
Expand All @@ -30,4 +31,4 @@ const net = require('net');
}));
}));
}));
});
};
5 changes: 3 additions & 2 deletions test/parallel/test-http2-server-settimeout-no-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ const http2 = require('http2');
const verifyCallbacks = common.mustCall((server) => {
const testTimeout = 10;

[true, 1, {}, [], null, 'test'].forEach((notFunction) => {
const testCases = [true, 1, {}, [], null, 'test'];
for (const notFunction of testCases) {
assert.throws(
() => server.setTimeout(testTimeout, notFunction),
{
name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
}
);
});
};

// No callback
const returnedVal = server.setTimeout(testTimeout);
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-http2-status-code-invalid.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ function expectsError(code) {
server.on('stream', common.mustCall((stream) => {

// Anything lower than 100 and greater than 599 is rejected
[ 99, 700, 1000 ].forEach((i) => {
const testCases = [ 99, 700, 1000 ];
for (const i of testCases) {
assert.throws(() => stream.respond({ ':status': i }), expectsError(i));
});
}

stream.respond();
stream.end();
Expand Down
Loading