Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v8.x backport] test: remove common.noop #14174

Closed
wants to merge 1 commit into from
Closed
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
21 changes: 4 additions & 17 deletions test/common/README.md
Original file line number Diff line number Diff line change
@@ -209,26 +209,26 @@ Gets IP of localhost
Array of IPV6 hosts.

### mustCall([fn][, exact])
* `fn` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) default = `common.noop`
* `fn` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) default = () => {}
* `exact` [<Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) default = 1
* return [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)

Returns a function that calls `fn`. If the returned function has not been called
exactly `expected` number of times when the test is complete, then the test will
fail.

If `fn` is not provided, `common.noop` will be used.
If `fn` is not provided, an empty function will be used.

### mustCallAtLeast([fn][, minimum])
* `fn` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) default = `common.noop`
* `fn` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) default = () => {}
* `minimum` [<Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) default = 1
* return [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)

Returns a function that calls `fn`. If the returned function has not been called
at least `minimum` number of times when the test is complete, then the test will
fail.

If `fn` is not provided, `common.noop` will be used.
If `fn` is not provided, an empty function will be used.

### mustNotCall([msg])
* `msg` [<String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) default = 'function should not have been called'
@@ -243,19 +243,6 @@ Returns a function that triggers an `AssertionError` if it is invoked. `msg` is

Returns `true` if the exit code `exitCode` and/or signal name `signal` represent the exit code and/or signal name of a node process that aborted, `false` otherwise.

### noop

A non-op `Function` that can be used for a variety of scenarios.

For instance,

<!-- eslint-disable strict, no-undef -->
```js
const common = require('../common');

someAsyncAPI('foo', common.mustCall(common.noop));
```

### opensslCli
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)

1 change: 0 additions & 1 deletion test/common/index.js
Original file line number Diff line number Diff line change
@@ -37,7 +37,6 @@ const testRoot = process.env.NODE_TEST_DIR ?

const noop = () => {};

exports.noop = noop;
exports.fixturesDir = path.join(__dirname, '..', 'fixtures');
exports.tmpDirName = 'tmp';
// PORT should match the definition in test/testpy/__init__.py.
4 changes: 2 additions & 2 deletions test/message/unhandled_promise_trace_warnings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Flags: --trace-warnings
'use strict';
const common = require('../common');
require('../common');
const p = Promise.reject(new Error('This was rejected'));
setImmediate(() => p.catch(common.noop));
setImmediate(() => p.catch(() => {}));
9 changes: 5 additions & 4 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
@@ -571,29 +571,30 @@ a.throws(makeBlock(a.deepEqual, args, []));

// check messages from assert.throws()
{
const noop = () => {};
assert.throws(
() => { a.throws(common.noop); },
() => { a.throws((noop)); },
common.expectsError({
code: 'ERR_ASSERTION',
message: /^Missing expected exception\.$/
}));

assert.throws(
() => { a.throws(common.noop, TypeError); },
() => { a.throws(noop, TypeError); },
common.expectsError({
code: 'ERR_ASSERTION',
message: /^Missing expected exception \(TypeError\)\.$/
}));

assert.throws(
() => { a.throws(common.noop, 'fhqwhgads'); },
() => { a.throws(noop, 'fhqwhgads'); },
common.expectsError({
code: 'ERR_ASSERTION',
message: /^Missing expected exception: fhqwhgads$/
}));

assert.throws(
() => { a.throws(common.noop, TypeError, 'fhqwhgads'); },
() => { a.throws(noop, TypeError, 'fhqwhgads'); },
common.expectsError({
code: 'ERR_ASSERTION',
message: /^Missing expected exception \(TypeError\): fhqwhgads$/
4 changes: 2 additions & 2 deletions test/parallel/test-buffer-includes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');

const b = Buffer.from('abcdef');
@@ -274,7 +274,7 @@ for (let lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
const expectedError =
/^TypeError: "val" argument must be string, number, Buffer or Uint8Array$/;
assert.throws(() => {
b.includes(common.noop);
b.includes(() => {});
}, expectedError);
assert.throws(() => {
b.includes({});
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-bad-stdio.js
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ const assert = require('assert');
const cp = require('child_process');

if (process.argv[2] === 'child') {
setTimeout(common.noop, common.platformTimeout(100));
setTimeout(() => {}, common.platformTimeout(100));
return;
}

2 changes: 1 addition & 1 deletion test/parallel/test-child-process-spawnsync-kill-signal.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ const assert = require('assert');
const cp = require('child_process');

if (process.argv[2] === 'child') {
setInterval(common.noop, 1000);
setInterval(() => {}, 1000);
} else {
const { SIGKILL } = process.binding('constants').os.signals;

6 changes: 3 additions & 3 deletions test/parallel/test-cluster-rr-domain-listen.js
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
const common = require('../common');
require('../common');
const cluster = require('cluster');
const domain = require('domain');

@@ -29,10 +29,10 @@ const domain = require('domain');

if (cluster.isWorker) {
const d = domain.create();
d.run(common.noop);
d.run(() => {});

const http = require('http');
http.Server(common.noop).listen(0, '127.0.0.1');
http.Server(() => {}).listen(0, '127.0.0.1');

} else if (cluster.isMaster) {

4 changes: 2 additions & 2 deletions test/parallel/test-cluster-worker-wait-server-close.js
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ if (cluster.isWorker) {
const server = net.createServer(function(socket) {
// Wait for any data, then close connection
socket.write('.');
socket.on('data', common.noop);
socket.on('data', () => {});
}).listen(0, common.localhostIPv4);

server.once('close', function() {
@@ -20,7 +20,7 @@ if (cluster.isWorker) {

// Although not typical, the worker process can exit before the disconnect
// event fires. Use this to keep the process open until the event has fired.
const keepOpen = setInterval(common.noop, 9999);
const keepOpen = setInterval(() => {}, 9999);

// Check worker events and properties
process.once('disconnect', function() {
2 changes: 1 addition & 1 deletion test/parallel/test-common.js
Original file line number Diff line number Diff line change
@@ -101,7 +101,7 @@ const HIJACK_TEST_ARRAY = [ 'foo\n', 'bar\n', 'baz\n' ];
assert.notStrictEqual(originalWrite, stream.write);

HIJACK_TEST_ARRAY.forEach((val) => {
stream.write(val, common.mustCall(common.noop));
stream.write(val, common.mustCall());
});

assert.strictEqual(HIJACK_TEST_ARRAY.length, stream.writeTimes);
2 changes: 1 addition & 1 deletion test/parallel/test-console-instance.js
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ assert.throws(() => {

// Console constructor should throw if stderr exists but is not writable
assert.throws(() => {
out.write = common.noop;
out.write = () => {};
err.write = undefined;
new Console(out, err);
}, /^TypeError: Console expects writable stream instances$/);
6 changes: 3 additions & 3 deletions test/parallel/test-event-emitter-get-max-listeners.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');
const EventEmitter = require('events');

@@ -15,5 +15,5 @@ assert.strictEqual(emitter.getMaxListeners(), 3);

// https://github.com/nodejs/node/issues/523 - second call should not throw.
const recv = {};
EventEmitter.prototype.on.call(recv, 'event', common.noop);
EventEmitter.prototype.on.call(recv, 'event', common.noop);
EventEmitter.prototype.on.call(recv, 'event', () => {});
EventEmitter.prototype.on.call(recv, 'event', () => {});
10 changes: 5 additions & 5 deletions test/parallel/test-event-emitter-listener-count.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';

const common = require('../common');
require('../common');
const assert = require('assert');
const EventEmitter = require('events');

const emitter = new EventEmitter();
emitter.on('foo', common.noop);
emitter.on('foo', common.noop);
emitter.on('baz', common.noop);
emitter.on('foo', () => {});
emitter.on('foo', () => {});
emitter.on('baz', () => {});
// Allow any type
emitter.on(123, common.noop);
emitter.on(123, () => {});

assert.strictEqual(EventEmitter.listenerCount(emitter, 'foo'), 2);
assert.strictEqual(emitter.listenerCount('foo'), 2);
Original file line number Diff line number Diff line change
@@ -18,5 +18,5 @@ process.on('warning', common.mustCall((warning) => {
assert.ok(warning.message.includes('2 null listeners added.'));
}));

e.on(null, common.noop);
e.on(null, common.noop);
e.on(null, () => {});
e.on(null, () => {});
Original file line number Diff line number Diff line change
@@ -20,5 +20,5 @@ process.on('warning', common.mustCall((warning) => {
assert.ok(warning.message.includes('2 Symbol(symbol) listeners added.'));
}));

e.on(symbol, common.noop);
e.on(symbol, common.noop);
e.on(symbol, () => {});
e.on(symbol, () => {});
6 changes: 3 additions & 3 deletions test/parallel/test-event-emitter-max-listeners-warning.js
Original file line number Diff line number Diff line change
@@ -18,6 +18,6 @@ process.on('warning', common.mustCall((warning) => {
assert.ok(warning.message.includes('2 event-type listeners added.'));
}));

e.on('event-type', common.noop);
e.on('event-type', common.noop); // Trigger warning.
e.on('event-type', common.noop); // Verify that warning is emitted only once.
e.on('event-type', () => {});
e.on('event-type', () => {}); // Trigger warning.
e.on('event-type', () => {}); // Verify that warning is emitted only once.
4 changes: 2 additions & 2 deletions test/parallel/test-event-emitter-remove-listeners.js
Original file line number Diff line number Diff line change
@@ -140,7 +140,7 @@ function listener2() {}
{
const ee = new EventEmitter();

assert.deepStrictEqual(ee, ee.removeListener('foo', common.noop));
assert.deepStrictEqual(ee, ee.removeListener('foo', () => {}));
}

// Verify that the removed listener must be a function
@@ -152,7 +152,7 @@ assert.throws(() => {

{
const ee = new EventEmitter();
const listener = common.noop;
const listener = () => {};
ee._events = undefined;
const e = ee.removeListener('foo', listener);
assert.strictEqual(e, ee);
2 changes: 1 addition & 1 deletion test/parallel/test-event-emitter-special-event-names.js
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ const EventEmitter = require('events');
const assert = require('assert');

const ee = new EventEmitter();
const handler = common.noop;
const handler = () => {};

assert.deepStrictEqual(ee.eventNames(), []);

2 changes: 1 addition & 1 deletion test/parallel/test-event-emitter-subclass.js
Original file line number Diff line number Diff line change
@@ -62,6 +62,6 @@ MyEE2.prototype = new EventEmitter();
const ee1 = new MyEE2();
const ee2 = new MyEE2();

ee1.on('x', common.noop);
ee1.on('x', () => {});

assert.strictEqual(ee2.listenerCount('x'), 0);
1 change: 0 additions & 1 deletion test/parallel/test-events-list.js
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ const EventEmitter = require('events');
const assert = require('assert');

const EE = new EventEmitter();
// Do not use common.noop here, these need to be separate listener functions
const m = () => {};
EE.on('foo', () => {});
assert.deepStrictEqual(['foo'], EE.eventNames());
2 changes: 1 addition & 1 deletion test/parallel/test-fs-buffertype-writesync.js
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ const fs = require('fs');
const path = require('path');

const filePath = path.join(common.tmpDir, 'test_buffer_type');
const v = [true, false, 0, 1, Infinity, common.noop, {}, [], undefined, null];
const v = [true, false, 0, 1, Infinity, () => {}, {}, [], undefined, null];

common.refreshTmpDir();

2 changes: 1 addition & 1 deletion test/parallel/test-fs-mkdir.js
Original file line number Diff line number Diff line change
@@ -77,4 +77,4 @@ common.refreshTmpDir();

// Keep the event loop alive so the async mkdir() requests
// have a chance to run (since they don't ref the event loop).
process.nextTick(common.noop);
process.nextTick(() => {});
4 changes: 2 additions & 2 deletions test/parallel/test-handle-wrap-isrefed.js
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ const strictEqual = require('assert').strictEqual;
// tcp
{
const net = require('net');
const server = net.createServer(common.noop).listen(0);
const server = net.createServer(() => {}).listen(0);
strictEqual(Object.getPrototypeOf(server._handle).hasOwnProperty('hasRef'),
true, 'tcp_wrap: hasRef() missing');
strictEqual(server._handle.hasRef(),
@@ -112,7 +112,7 @@ const strictEqual = require('assert').strictEqual;

// timers
{
const timer = setTimeout(common.noop, 500);
const timer = setTimeout(() => {}, 500);
timer.unref();
strictEqual(Object.getPrototypeOf(timer._handle).hasOwnProperty('hasRef'),
true, 'timer_wrap: hasRef() missing');
8 changes: 4 additions & 4 deletions test/parallel/test-http-client-defaults.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
'use strict';

const common = require('../common');
require('../common');
const assert = require('assert');
const ClientRequest = require('http').ClientRequest;

{
const req = new ClientRequest({ createConnection: common.noop });
const req = new ClientRequest({ createConnection: () => {} });
assert.strictEqual(req.path, '/');
assert.strictEqual(req.method, 'GET');
}

{
const req = new ClientRequest({ method: '', createConnection: common.noop });
const req = new ClientRequest({ method: '', createConnection: () => {} });
assert.strictEqual(req.path, '/');
assert.strictEqual(req.method, 'GET');
}

{
const req = new ClientRequest({ path: '', createConnection: common.noop });
const req = new ClientRequest({ path: '', createConnection: () => {} });
assert.strictEqual(req.path, '/');
assert.strictEqual(req.method, 'GET');
}
4 changes: 2 additions & 2 deletions test/parallel/test-http-parser-bad-ref.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

// Flags: --expose_gc

const common = require('../common');
require('../common');
const assert = require('assert');
const HTTPParser = process.binding('http_parser').HTTPParser;

@@ -39,7 +39,7 @@ function demoBug(part1, part2) {
console.log('url', info.url);
};

parser[kOnBody] = common.noop;
parser[kOnBody] = () => {};

parser[kOnMessageComplete] = function() {
messagesComplete++;
4 changes: 2 additions & 2 deletions test/parallel/test-http-upgrade-server.js
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@

'use strict';

const common = require('../common');
require('../common');
const assert = require('assert');

const util = require('util');
@@ -38,7 +38,7 @@ function createTestServer() {
}

function testServer() {
http.Server.call(this, common.noop);
http.Server.call(this, () => {});

this.on('connection', function() {
requests_recv++;
Loading