From 990a19fc7e7ca24a592d9f94c4f62428c25379b1 Mon Sep 17 00:00:00 2001 From: Julian Duque Date: Thu, 1 Dec 2016 11:42:19 -0600 Subject: [PATCH] test: refactor test for net listen on fd0 Replace var to const/let, use common.mustCall on callbacks and move process.on('exit') to the .on('error') handler PR-URL: https://github.com/nodejs/node/pull/10025 Reviewed-By: Santiago Gimeno Reviewed-By: Gibson Fahnestock Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- test/parallel/test-net-listen-fd0.js | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/test/parallel/test-net-listen-fd0.js b/test/parallel/test-net-listen-fd0.js index b484c6306f8463..f34f12ec22c771 100644 --- a/test/parallel/test-net-listen-fd0.js +++ b/test/parallel/test-net-listen-fd0.js @@ -1,20 +1,12 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); -var gotError = false; - -process.on('exit', function() { - assert(gotError instanceof Error); -}); - -// this should fail with an async EINVAL error, not throw an exception -net.createServer(common.fail).listen({fd: 0}).on('error', function(e) { - switch (e.code) { - case 'EINVAL': - case 'ENOTSOCK': - gotError = e; - break; - } -}); +// This should fail with an async EINVAL error, not throw an exception +net.createServer(common.fail) + .listen({fd: 0}) + .on('error', common.mustCall(function(e) { + assert(e instanceof Error); + assert(['EINVAL', 'ENOTSOCK'].includes(e.code)); + }));