From c9450cef1b6a5fb0a310927f313c997106f5ab14 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 29 Sep 2016 17:22:36 -0700 Subject: [PATCH] test: clean up test-timers-immediate Clean up test-timers-immediate. Use of `let` also requires a tweak to ESLint rules (but it's one that we should do as timers is pretty much the reason it exists). PR-URL: https://github.com/nodejs/node/pull/8857 Reviewed-By: James M Snell Reviewed-By: Ilkka Myller Reviewed-By: Luigi Pinca --- .eslintrc | 2 +- test/parallel/test-timers-immediate.js | 35 +++++++++++--------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/.eslintrc b/.eslintrc index 6ae06ef7dde353..d65f8d546c069d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -103,7 +103,7 @@ rules: no-dupe-class-members: 2 no-new-symbol: 2 no-this-before-super: 2 - prefer-const: 2 + prefer-const: [2, {ignoreReadBeforeAssign: true}] rest-spread-spacing: 2 template-curly-spacing: 2 diff --git a/test/parallel/test-timers-immediate.js b/test/parallel/test-timers-immediate.js index d160adc998fe1b..9632022917f152 100644 --- a/test/parallel/test-timers-immediate.js +++ b/test/parallel/test-timers-immediate.js @@ -1,25 +1,20 @@ 'use strict'; -require('../common'); -var assert = require('assert'); - -let immediateA = false; -let immediateB = false; -let immediateC = []; -let immediateD = []; - -setImmediate(function() { - try { - immediateA = process.hrtime(before); - } catch (e) { - console.log('failed to get hrtime with offset'); - } - clearImmediate(immediateB); -}); +const common = require('../common'); +const assert = require('assert'); + +let immediateB; +let immediateC; +let immediateD; -const before = process.hrtime(); +let mainFinished = false; + +setImmediate(common.mustCall(function() { + assert.strictEqual(mainFinished, true); + clearImmediate(immediateB); +})); immediateB = setImmediate(function() { - immediateB = true; + common.fail('this immediate should not run'); }); setImmediate(function(x, y, z) { @@ -31,8 +26,8 @@ setImmediate(function(x, y, z, a, b) { }, 1, 2, 3, 4, 5); process.on('exit', function() { - assert.ok(immediateA, 'Immediate should happen after normal execution'); - assert.notStrictEqual(immediateB, true, 'immediateB should not fire'); assert.deepStrictEqual(immediateC, [1, 2, 3], 'immediateC args should match'); assert.deepStrictEqual(immediateD, [1, 2, 3, 4, 5], '5 args should match'); }); + +mainFinished = true;