From 37c70ee198388ffc5ba5a56c3c51a72f5053637a Mon Sep 17 00:00:00 2001 From: garygsc Date: Sat, 26 Oct 2019 13:17:23 -0600 Subject: [PATCH] test: use arrow functions in async-hooks tests Convert all anonymous callback functions in `test/async-hooks/*.js` to use arrow functions. `writing-tests.md` states to use arrow functions when appropriate. PR-URL: https://github.com/nodejs/node/pull/30137 Reviewed-By: Anna Henningsen Reviewed-By: Gireesh Punathil Reviewed-By: Trivikram Kamat --- test/async-hooks/test-disable-in-init.js | 2 +- test/async-hooks/test-graph.http.js | 8 ++++---- test/async-hooks/test-graph.pipeconnect.js | 4 ++-- test/async-hooks/test-nexttick-default-trigger.js | 4 ++-- test/async-hooks/test-pipeconnectwrap.js | 4 ++-- test/async-hooks/test-queue-microtask.js | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/async-hooks/test-disable-in-init.js b/test/async-hooks/test-disable-in-init.js index b7ab31e6d97dc2..17537c62f30885 100644 --- a/test/async-hooks/test-disable-in-init.js +++ b/test/async-hooks/test-disable-in-init.js @@ -7,7 +7,7 @@ const fs = require('fs'); let nestedCall = false; async_hooks.createHook({ - init: common.mustCall(function() { + init: common.mustCall(() => { nestedHook.disable(); if (!nestedCall) { nestedCall = true; diff --git a/test/async-hooks/test-graph.http.js b/test/async-hooks/test-graph.http.js index 12862467a6947e..db0c1265670a6f 100644 --- a/test/async-hooks/test-graph.http.js +++ b/test/async-hooks/test-graph.http.js @@ -11,11 +11,11 @@ const http = require('http'); const hooks = initHooks(); hooks.enable(); -const server = http.createServer(common.mustCall(function(req, res) { +const server = http.createServer(common.mustCall((req, res) => { res.end(); - this.close(common.mustCall()); + server.close(common.mustCall()); })); -server.listen(0, common.mustCall(function() { +server.listen(0, common.mustCall(() => { http.get({ host: '::1', family: 6, @@ -23,7 +23,7 @@ server.listen(0, common.mustCall(function() { }, common.mustCall()); })); -process.on('exit', function() { +process.on('exit', () => { hooks.disable(); verifyGraph( diff --git a/test/async-hooks/test-graph.pipeconnect.js b/test/async-hooks/test-graph.pipeconnect.js index 03d2902c835d48..440ea906a17c4d 100644 --- a/test/async-hooks/test-graph.pipeconnect.js +++ b/test/async-hooks/test-graph.pipeconnect.js @@ -12,9 +12,9 @@ tmpdir.refresh(); const hooks = initHooks(); hooks.enable(); -net.createServer(function(c) { +const server = net.createServer((c) => { c.end(); - this.close(); + server.close(); }).listen(common.PIPE, common.mustCall(onlisten)); function onlisten() { diff --git a/test/async-hooks/test-nexttick-default-trigger.js b/test/async-hooks/test-nexttick-default-trigger.js index 1bc93f29737389..7d6d98c9abc902 100644 --- a/test/async-hooks/test-nexttick-default-trigger.js +++ b/test/async-hooks/test-nexttick-default-trigger.js @@ -14,11 +14,11 @@ hooks.enable(); const rootAsyncId = async_hooks.executionAsyncId(); -process.nextTick(common.mustCall(function() { +process.nextTick(common.mustCall(() => { assert.strictEqual(async_hooks.triggerAsyncId(), rootAsyncId); })); -process.on('exit', function() { +process.on('exit', () => { hooks.sanityCheck(); const as = hooks.activitiesOfTypes('TickObject'); diff --git a/test/async-hooks/test-pipeconnectwrap.js b/test/async-hooks/test-pipeconnectwrap.js index f086807e393145..b57cc63cf59e46 100644 --- a/test/async-hooks/test-pipeconnectwrap.js +++ b/test/async-hooks/test-pipeconnectwrap.js @@ -17,9 +17,9 @@ let pipe1, pipe2; let pipeserver; let pipeconnect; -net.createServer(common.mustCall(function(c) { +const server = net.createServer(common.mustCall((c) => { c.end(); - this.close(); + server.close(); process.nextTick(maybeOnconnect.bind(null, 'server')); })).listen(common.PIPE, common.mustCall(onlisten)); diff --git a/test/async-hooks/test-queue-microtask.js b/test/async-hooks/test-queue-microtask.js index dfa537752e37fc..1e2029efe4ad0e 100644 --- a/test/async-hooks/test-queue-microtask.js +++ b/test/async-hooks/test-queue-microtask.js @@ -11,11 +11,11 @@ hooks.enable(); const rootAsyncId = async_hooks.executionAsyncId(); -queueMicrotask(common.mustCall(function() { +queueMicrotask(common.mustCall(() => { assert.strictEqual(async_hooks.triggerAsyncId(), rootAsyncId); })); -process.on('exit', function() { +process.on('exit', () => { hooks.sanityCheck(); const as = hooks.activitiesOfTypes('Microtask');