-
Notifications
You must be signed in to change notification settings - Fork 29.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35f3752
commit 807b7c3
Showing
5 changed files
with
200 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
test/parallel/test-timers-nan-duration-emit-once-per-process.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const NOT_A_NUMBER = NaN; | ||
|
||
function timerNotCanceled() { | ||
assert.fail('Timer should be canceled'); | ||
} | ||
|
||
process.on( | ||
'warning', | ||
common.mustCall((warning) => { | ||
if (warning.name === 'DeprecationWarning') return; | ||
|
||
const lines = warning.message.split('\n'); | ||
|
||
assert.strictEqual(warning.name, 'TimeoutNaNWarning'); | ||
assert.strictEqual(lines[0], `${NOT_A_NUMBER} is not a number.`); | ||
assert.strictEqual(lines.length, 2); | ||
}, 1) | ||
); | ||
|
||
{ | ||
const timeout = setTimeout(timerNotCanceled, NOT_A_NUMBER); | ||
clearTimeout(timeout); | ||
} | ||
|
||
{ | ||
const interval = setInterval(timerNotCanceled, NOT_A_NUMBER); | ||
clearInterval(interval); | ||
} | ||
|
||
{ | ||
const timeout = setTimeout(timerNotCanceled, NOT_A_NUMBER); | ||
timeout.refresh(); | ||
clearTimeout(timeout); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,73 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
require('../common'); | ||
const assert = require('assert'); | ||
const child_process = require('child_process'); | ||
const path = require('path'); | ||
|
||
const NOT_A_NUMBER = NaN; | ||
|
||
function timerNotCanceled() { | ||
assert.fail('Timer should be canceled'); | ||
} | ||
|
||
process.on( | ||
'warning', | ||
common.mustCall((warning) => { | ||
if (warning.name === 'DeprecationWarning') return; | ||
const testCases = ['timeout', 'interval', 'refresh']; | ||
|
||
const lines = warning.message.split('\n'); | ||
function runTest() { | ||
const args = process.argv.slice(2); | ||
|
||
assert.strictEqual(warning.name, 'TimeoutNaNWarning'); | ||
assert.strictEqual(lines[0], `${NOT_A_NUMBER} is not a number.`); | ||
assert.strictEqual(lines.length, 2); | ||
}, 3) | ||
); | ||
const testChoice = args[0]; | ||
|
||
{ | ||
const timeout = setTimeout(timerNotCanceled, NOT_A_NUMBER); | ||
clearTimeout(timeout); | ||
} | ||
if (!testChoice) { | ||
const filePath = path.join(__filename); | ||
|
||
{ | ||
const interval = setInterval(timerNotCanceled, NOT_A_NUMBER); | ||
clearInterval(interval); | ||
} | ||
testCases.forEach((testCase) => { | ||
const { stdout } = child_process.spawnSync( | ||
process.execPath, | ||
[filePath, testCase], | ||
{ encoding: 'utf8' } | ||
); | ||
|
||
const lines = stdout.split('\n'); | ||
|
||
if (lines[0] === 'DeprecationWarning') return; | ||
|
||
assert.strictEqual(lines[0], 'TimeoutNaNWarning'); | ||
assert.strictEqual(lines[1], `${NOT_A_NUMBER} is not a number.`); | ||
assert.strictEqual(lines[2], 'Timeout duration was set to 1.'); | ||
}); | ||
} | ||
|
||
{ | ||
const timeout = setTimeout(timerNotCanceled, NOT_A_NUMBER); | ||
timeout.refresh(); | ||
clearTimeout(timeout); | ||
if (args[0] === testCases[0]) { | ||
{ | ||
const timeout = setTimeout(timerNotCanceled, NOT_A_NUMBER); | ||
clearTimeout(timeout); | ||
} | ||
} | ||
|
||
if (args[0] === testCases[1]) { | ||
{ | ||
const interval = setInterval(timerNotCanceled, NOT_A_NUMBER); | ||
clearInterval(interval); | ||
} | ||
} | ||
|
||
if (args[0] === testCases[2]) { | ||
{ | ||
const timeout = setTimeout(timerNotCanceled, NOT_A_NUMBER); | ||
timeout.refresh(); | ||
clearTimeout(timeout); | ||
} | ||
} | ||
|
||
process.on( | ||
'warning', | ||
|
||
(warning) => { | ||
console.log(warning.name); | ||
console.log(warning.message); | ||
} | ||
); | ||
} | ||
|
||
runTest(); |
39 changes: 39 additions & 0 deletions
39
test/parallel/test-timers-negative-duration-warning-emit-once-per-process.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const NEGATIVE_NUMBER = -1; | ||
|
||
function timerNotCanceled() { | ||
assert.fail('Timer should be canceled'); | ||
} | ||
|
||
process.on( | ||
'warning', | ||
common.mustCall((warning) => { | ||
if (warning.name === 'DeprecationWarning') return; | ||
|
||
const lines = warning.message.split('\n'); | ||
|
||
assert.strictEqual(warning.name, 'TimeoutNegativeWarning'); | ||
assert.strictEqual(lines[0], `${NEGATIVE_NUMBER} is a negative number.`); | ||
assert.strictEqual(lines.length, 2); | ||
}, 1) | ||
); | ||
|
||
{ | ||
const timeout = setTimeout(timerNotCanceled, NEGATIVE_NUMBER); | ||
clearTimeout(timeout); | ||
} | ||
|
||
{ | ||
const interval = setInterval(timerNotCanceled, NEGATIVE_NUMBER); | ||
clearInterval(interval); | ||
} | ||
|
||
{ | ||
const timeout = setTimeout(timerNotCanceled, NEGATIVE_NUMBER); | ||
timeout.refresh(); | ||
clearTimeout(timeout); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,73 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
require('../common'); | ||
const assert = require('assert'); | ||
const child_process = require('child_process'); | ||
const path = require('path'); | ||
|
||
const NEGATIVE_NUMBER = -1; | ||
|
||
function timerNotCanceled() { | ||
assert.fail('Timer should be canceled'); | ||
} | ||
|
||
process.on( | ||
'warning', | ||
common.mustCall((warning) => { | ||
if (warning.name === 'DeprecationWarning') return; | ||
const testCases = ['timeout', 'interval', 'refresh']; | ||
|
||
const lines = warning.message.split('\n'); | ||
function runTest() { | ||
const args = process.argv.slice(2); | ||
|
||
assert.strictEqual(warning.name, 'TimeoutNegativeWarning'); | ||
assert.strictEqual(lines[0], `${NEGATIVE_NUMBER} is a negative number.`); | ||
assert.strictEqual(lines.length, 2); | ||
}, 3) | ||
); | ||
const testChoice = args[0]; | ||
|
||
{ | ||
const timeout = setTimeout(timerNotCanceled, NEGATIVE_NUMBER); | ||
clearTimeout(timeout); | ||
} | ||
if (!testChoice) { | ||
const filePath = path.join(__filename); | ||
|
||
{ | ||
const interval = setInterval(timerNotCanceled, NEGATIVE_NUMBER); | ||
clearInterval(interval); | ||
} | ||
testCases.forEach((testCase) => { | ||
const { stdout } = child_process.spawnSync( | ||
process.execPath, | ||
[filePath, testCase], | ||
{ encoding: 'utf8' } | ||
); | ||
|
||
const lines = stdout.split('\n'); | ||
|
||
if (lines[0] === 'DeprecationWarning') return; | ||
|
||
assert.strictEqual(lines[0], 'TimeoutNegativeWarning'); | ||
assert.strictEqual(lines[1], `${NEGATIVE_NUMBER} is a negative number.`); | ||
assert.strictEqual(lines[2], 'Timeout duration was set to 1.'); | ||
}); | ||
} | ||
|
||
{ | ||
const timeout = setTimeout(timerNotCanceled, NEGATIVE_NUMBER); | ||
timeout.refresh(); | ||
clearTimeout(timeout); | ||
if (args[0] === testCases[0]) { | ||
{ | ||
const timeout = setTimeout(timerNotCanceled, NEGATIVE_NUMBER); | ||
clearTimeout(timeout); | ||
} | ||
} | ||
|
||
if (args[0] === testCases[1]) { | ||
{ | ||
const interval = setInterval(timerNotCanceled, NEGATIVE_NUMBER); | ||
clearInterval(interval); | ||
} | ||
} | ||
|
||
if (args[0] === testCases[2]) { | ||
{ | ||
const timeout = setTimeout(timerNotCanceled, NEGATIVE_NUMBER); | ||
timeout.refresh(); | ||
clearTimeout(timeout); | ||
} | ||
} | ||
|
||
process.on( | ||
'warning', | ||
|
||
(warning) => { | ||
console.log(warning.name); | ||
console.log(warning.message); | ||
} | ||
); | ||
} | ||
|
||
runTest(); |