blob: 12120e97376424835892602d9e7b20fe7723ba31 (
plain)
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
|
'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const cbTypeError = /^TypeError: "callback" argument must be a function$/;
const callbackThrowValues = [null, true, false, 0, 1, 'foo', /foo/, [], {}];
const warn = 'Calling an asynchronous function without callback is deprecated.';
function testMakeStatsCallback(cb) {
return function() {
// fs.stat() calls makeStatsCallback() on its second argument
fs.stat(__filename, cb);
};
}
common.expectWarning('DeprecationWarning', warn);
// Verify the case where a callback function is provided
assert.doesNotThrow(testMakeStatsCallback(common.mustCall()));
// Passing undefined/nothing calls rethrow() internally, which emits a warning
assert.doesNotThrow(testMakeStatsCallback());
function invalidCallbackThrowsTests() {
callbackThrowValues.forEach((value) => {
assert.throws(testMakeStatsCallback(value), cbTypeError);
});
}
invalidCallbackThrowsTests();
|