2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-07-27 22:25:26 +05:30
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const fs = require('fs');
|
2017-03-30 23:06:47 +02:00
|
|
|
const callbackThrowValues = [null, true, false, 0, 1, 'foo', /foo/, [], {}];
|
2015-02-18 12:55:13 -05:00
|
|
|
|
2017-03-30 23:06:47 +02:00
|
|
|
const { sep } = require('path');
|
2017-05-11 18:52:20 +03:00
|
|
|
const warn = 'Calling an asynchronous function without callback is deprecated.';
|
2017-03-30 23:06:47 +02:00
|
|
|
|
|
|
|
common.refreshTmpDir();
|
|
|
|
|
|
|
|
function testMakeCallback(cb) {
|
2015-02-18 12:55:13 -05:00
|
|
|
return function() {
|
2017-03-30 23:06:47 +02:00
|
|
|
// fs.mkdtemp() calls makeCallback() on its third argument
|
|
|
|
fs.mkdtemp(`${common.tmpDir}${sep}`, {}, cb);
|
2015-02-18 12:55:13 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-05-11 18:52:20 +03:00
|
|
|
common.expectWarning('DeprecationWarning', warn);
|
|
|
|
|
|
|
|
// Passing undefined/nothing calls rethrow() internally, which emits a warning
|
|
|
|
assert.doesNotThrow(testMakeCallback());
|
|
|
|
|
2017-03-30 23:06:47 +02:00
|
|
|
function invalidCallbackThrowsTests() {
|
|
|
|
callbackThrowValues.forEach((value) => {
|
2017-08-26 07:46:47 -04:00
|
|
|
common.expectsError(testMakeCallback(value), {
|
|
|
|
code: 'ERR_INVALID_CALLBACK',
|
|
|
|
type: TypeError
|
|
|
|
});
|
2017-03-30 23:06:47 +02:00
|
|
|
});
|
2016-07-27 22:25:26 +05:30
|
|
|
}
|
2017-03-30 23:06:47 +02:00
|
|
|
|
|
|
|
invalidCallbackThrowsTests();
|