From 90a79b39673e71b960a5ac3bf29db12aa02bc45f Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 16 Dec 2016 22:05:01 -0800 Subject: [PATCH] test: refactor test-timers-this MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * use common.mustCall() and eliminate exit handler * provide timer durtion of 1ms where previously omitted * var -> const PR-URL: https://github.com/nodejs/node/pull/10315 Reviewed-By: Michaƫl Zasso Reviewed-By: Jeremiah Senkpiel --- test/parallel/test-timers-this.js | 56 +++++++++++-------------------- 1 file changed, 20 insertions(+), 36 deletions(-) diff --git a/test/parallel/test-timers-this.js b/test/parallel/test-timers-this.js index e21167581e8944..6bd4033756626e 100644 --- a/test/parallel/test-timers-this.js +++ b/test/parallel/test-timers-this.js @@ -1,45 +1,29 @@ 'use strict'; -require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); -let immediateThis, intervalThis, timeoutThis; -let immediateArgsThis, intervalArgsThis, timeoutArgsThis; +const immediateHandler = setImmediate(common.mustCall(function() { + assert.strictEqual(this, immediateHandler); +})); -var immediateHandler = setImmediate(function() { - immediateThis = this; -}); +const immediateArgsHandler = setImmediate(common.mustCall(function() { + assert.strictEqual(this, immediateArgsHandler); +}), 'args ...'); -var immediateArgsHandler = setImmediate(function() { - immediateArgsThis = this; -}, 'args ...'); - -var intervalHandler = setInterval(function() { +const intervalHandler = setInterval(common.mustCall(function() { clearInterval(intervalHandler); + assert.strictEqual(this, intervalHandler); +}), 1); - intervalThis = this; -}); - -var intervalArgsHandler = setInterval(function() { +const intervalArgsHandler = setInterval(common.mustCall(function() { clearInterval(intervalArgsHandler); + assert.strictEqual(this, intervalArgsHandler); +}), 1, 'args ...'); - intervalArgsThis = this; -}, 0, 'args ...'); - -var timeoutHandler = setTimeout(function() { - timeoutThis = this; -}); - -var timeoutArgsHandler = setTimeout(function() { - timeoutArgsThis = this; -}, 0, 'args ...'); - -process.once('exit', function() { - assert.strictEqual(immediateThis, immediateHandler); - assert.strictEqual(immediateArgsThis, immediateArgsHandler); - - assert.strictEqual(intervalThis, intervalHandler); - assert.strictEqual(intervalArgsThis, intervalArgsHandler); +const timeoutHandler = setTimeout(common.mustCall(function() { + assert.strictEqual(this, timeoutHandler); +}), 1); - assert.strictEqual(timeoutThis, timeoutHandler); - assert.strictEqual(timeoutArgsThis, timeoutArgsHandler); -}); +const timeoutArgsHandler = setTimeout(common.mustCall(function() { + assert.strictEqual(this, timeoutArgsHandler); +}), 1, 'args ...');