forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-timers-negative-duration-warning.js
More file actions
67 lines (50 loc) · 1.5 KB
/
test-timers-negative-duration-warning.js
File metadata and controls
67 lines (50 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'use strict';
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');
}
const testCases = ['timeout', 'interval', 'refresh'];
function runTests() {
const args = process.argv.slice(2);
const testChoice = args[0];
if (!testChoice) {
const filePath = path.join(__filename);
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.');
});
}
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);
}
);
}
runTests();