Skip to content

Commit 4800b62

Browse files
GaryGSCaddaleax
authored andcommittedNov 30, 2019
test: use arrow functions in addons tests
Convert all anonymous callback functions in `test/addons/**/*.js` to use arrow functions, except for those in `test/addons/make-callback/test.js` (which reference `this`) `writing-tests.md` states to use arrow functions when appropriate. PR-URL: #30131 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]>
1 parent 8fcb450 commit 4800b62

14 files changed

+24
-24
lines changed
 

‎test/addons/async-hello-world/test-makecallback.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const common = require('../../common');
33
const assert = require('assert');
44
const { runMakeCallback } = require(`./build/${common.buildType}/binding`);
55

6-
runMakeCallback(5, common.mustCall(function(err, val) {
6+
runMakeCallback(5, common.mustCall((err, val) => {
77
assert.strictEqual(err, null);
88
assert.strictEqual(val, 10);
99
process.nextTick(common.mustCall());

‎test/addons/async-hello-world/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const common = require('../../common');
33
const assert = require('assert');
44
const { runCall } = require(`./build/${common.buildType}/binding`);
55

6-
runCall(5, common.mustCall(function(err, val) {
6+
runCall(5, common.mustCall((err, val) => {
77
assert.strictEqual(err, null);
88
assert.strictEqual(val, 10);
99
process.nextTick(common.mustCall());

‎test/addons/load-long-path/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ fs.writeFileSync(addonDestinationPath, contents);
4848

4949
// Run test
5050
const child = fork(__filename, ['child'], { stdio: 'inherit' });
51-
child.on('exit', common.mustCall(function(code) {
51+
child.on('exit', common.mustCall((code) => {
5252
assert.strictEqual(code, 0);
5353
}));

‎test/addons/make-callback-domain-warning/test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ function makeCallback(object, cb) {
1010
}
1111

1212
let latestWarning = null;
13-
process.on('warning', function(warning) {
13+
process.on('warning', (warning) => {
1414
latestWarning = warning;
1515
});
1616

1717
const d = domain.create();
1818

1919
// When domain is disabled, no warning will be emitted
20-
makeCallback({ domain: d }, common.mustCall(function() {
20+
makeCallback({ domain: d }, common.mustCall(() => {
2121
assert.strictEqual(latestWarning, null);
2222

23-
d.run(common.mustCall(function() {
23+
d.run(common.mustCall(() => {
2424
// No warning will be emitted when no domain property is applied
25-
makeCallback({}, common.mustCall(function() {
25+
makeCallback({}, common.mustCall(() => {
2626
assert.strictEqual(latestWarning, null);
2727

2828
// Warning is emitted when domain property is used and domain is enabled
29-
makeCallback({ domain: d }, common.mustCall(function() {
29+
makeCallback({ domain: d }, common.mustCall(() => {
3030
assert.strictEqual(latestWarning.name, 'DeprecationWarning');
3131
assert.strictEqual(latestWarning.code, 'DEP0097');
3232
}));

‎test/addons/make-callback-recurse/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ assert.throws(() => {
7171
if (arg === 1) {
7272
// The tests are first run on bootstrap during LoadEnvironment() in
7373
// src/node.cc. Now run the tests through node::MakeCallback().
74-
setImmediate(function() {
74+
setImmediate(() => {
7575
makeCallback({}, common.mustCall(() => {
7676
verifyExecutionOrder(2);
7777
}));

‎test/addons/openssl-client-cert-engine/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ const server = https.createServer(serverOptions, common.mustCall((req, res) => {
4343
headers: {}
4444
};
4545

46-
const req = https.request(clientOptions, common.mustCall(function(response) {
46+
const req = https.request(clientOptions, common.mustCall((response) => {
4747
let body = '';
4848
response.setEncoding('utf8');
49-
response.on('data', function(chunk) {
49+
response.on('data', (chunk) => {
5050
body += chunk;
5151
});
5252

53-
response.on('end', common.mustCall(function() {
53+
response.on('end', common.mustCall(() => {
5454
assert.strictEqual(body, 'hello world');
5555
server.close();
5656
}));

‎test/addons/openssl-key-engine/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ const server = https.createServer(serverOptions, common.mustCall((req, res) => {
4545
headers: {}
4646
};
4747

48-
const req = https.request(clientOptions, common.mustCall(function(response) {
48+
const req = https.request(clientOptions, common.mustCall((response) => {
4949
let body = '';
5050
response.setEncoding('utf8');
51-
response.on('data', function(chunk) {
51+
response.on('data', (chunk) => {
5252
body += chunk;
5353
});
5454

55-
response.on('end', common.mustCall(function() {
55+
response.on('end', common.mustCall(() => {
5656
assert.strictEqual(body, 'hello world');
5757
server.close();
5858
}));

‎test/addons/repl-domain-abort/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if (common.isWindows)
3131
buildPath = buildPath.replace(/\\/g, '/');
3232
let cb_ran = false;
3333

34-
process.on('exit', function() {
34+
process.on('exit', () => {
3535
assert(cb_ran);
3636
console.log('ok');
3737
});

‎test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if (!binding.ensureAllocation(2 * kStringMaxLength))
2525
common.skip(skipMessage);
2626

2727
const stringLengthHex = kStringMaxLength.toString(16);
28-
common.expectsError(function() {
28+
common.expectsError(() => {
2929
buf.toString('ascii');
3030
}, {
3131
message: `Cannot create a string longer than 0x${stringLengthHex} ` +

‎test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if (!binding.ensureAllocation(2 * kStringMaxLength))
2525
common.skip(skipMessage);
2626

2727
const stringLengthHex = kStringMaxLength.toString(16);
28-
common.expectsError(function() {
28+
common.expectsError(() => {
2929
buf.toString('base64');
3030
}, {
3131
message: `Cannot create a string longer than 0x${stringLengthHex} ` +

‎test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (!binding.ensureAllocation(2 * kStringMaxLength))
2727
common.skip(skipMessage);
2828

2929
const stringLengthHex = kStringMaxLength.toString(16);
30-
common.expectsError(function() {
30+
common.expectsError(() => {
3131
buf.toString('latin1');
3232
}, {
3333
message: `Cannot create a string longer than 0x${stringLengthHex} ` +

‎test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if (!binding.ensureAllocation(2 * kStringMaxLength))
2525
common.skip(skipMessage);
2626

2727
const stringLengthHex = kStringMaxLength.toString(16);
28-
common.expectsError(function() {
28+
common.expectsError(() => {
2929
buf.toString('hex');
3030
}, {
3131
message: `Cannot create a string longer than 0x${stringLengthHex} ` +

‎test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ if (!binding.ensureAllocation(2 * kStringMaxLength))
2727

2828
const stringLengthHex = kStringMaxLength.toString(16);
2929

30-
assert.throws(function() {
30+
assert.throws(() => {
3131
buf.toString();
32-
}, function(e) {
32+
}, (e) => {
3333
if (e.message !== 'Array buffer allocation failed') {
3434
common.expectsError({
3535
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
@@ -43,7 +43,7 @@ assert.throws(function() {
4343
}
4444
});
4545

46-
common.expectsError(function() {
46+
common.expectsError(() => {
4747
buf.toString('utf8');
4848
}, {
4949
message: `Cannot create a string longer than 0x${stringLengthHex} ` +

‎test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if (!binding.ensureAllocation(2 * kStringMaxLength))
2626

2727
const stringLengthHex = kStringMaxLength.toString(16);
2828

29-
common.expectsError(function() {
29+
common.expectsError(() => {
3030
buf.toString('utf16le');
3131
}, {
3232
message: `Cannot create a string longer than 0x${stringLengthHex} ` +

0 commit comments

Comments
 (0)
Please sign in to comment.