node/test/parallel/test-fs-make-callback.js
Rich Trott a1b0d5da07
test: move tmpdir to submodule of common
Move tmpdir functionality to its own module (common/tmpdir).

Backport-PR-URL: https://github.com/nodejs/node/pull/19488
PR-URL: https://github.com/nodejs/node/pull/17856
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2018-03-29 23:28:22 -04:00

33 lines
966 B
JavaScript

'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 { sep } = require('path');
const warn = 'Calling an asynchronous function without callback is deprecated.';
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
function testMakeCallback(cb) {
return function() {
// fs.mkdtemp() calls makeCallback() on its third argument
fs.mkdtemp(`${tmpdir.path}${sep}`, {}, cb);
};
}
common.expectWarning('DeprecationWarning', warn);
// Passing undefined/nothing calls rethrow() internally, which emits a warning
assert.doesNotThrow(testMakeCallback());
function invalidCallbackThrowsTests() {
callbackThrowValues.forEach((value) => {
assert.throws(testMakeCallback(value), cbTypeError);
});
}
invalidCallbackThrowsTests();