test: refactor mkdtemp test and added async
This test refactored the original test for mkdtempSync prefix validation and added the test also for the async function mkdtemp. PR-URL: https://github.com/nodejs/node/pull/12080 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
This commit is contained in:
parent
f4e8a6f1f0
commit
085c1f8f60
25
test/parallel/test-fs-mkdtemp-prefix-check.js
Normal file
25
test/parallel/test-fs-mkdtemp-prefix-check.js
Normal file
@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
|
||||
const expectedError = /^TypeError: filename prefix is required$/;
|
||||
const prefixValues = [undefined, null, 0, true, false, 1, ''];
|
||||
|
||||
function fail(value) {
|
||||
assert.throws(
|
||||
() => fs.mkdtempSync(value, {}),
|
||||
expectedError
|
||||
);
|
||||
}
|
||||
|
||||
function failAsync(value) {
|
||||
assert.throws(
|
||||
() => fs.mkdtemp(value, common.mustNotCall()), expectedError
|
||||
);
|
||||
}
|
||||
|
||||
prefixValues.forEach((prefixValue) => {
|
||||
fail(prefixValue);
|
||||
failAsync(prefixValue);
|
||||
});
|
@ -1,13 +0,0 @@
|
||||
'use strict';
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
|
||||
const assertValues = [undefined, null, 0, true, false, 1];
|
||||
|
||||
assertValues.forEach((assertValue) => {
|
||||
assert.throws(
|
||||
() => fs.mkdtempSync(assertValue, {}),
|
||||
/^TypeError: filename prefix is required$/
|
||||
);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user