From 4b54520a4aeaf4e5a09273e327920ba70d6a682a Mon Sep 17 00:00:00 2001 From: Luca Maraschi Date: Mon, 27 Mar 2017 23:55:54 +0200 Subject: [PATCH] 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 Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Yuta Hiroto Reviewed-By: Richard Lau Reviewed-By: Jeremiah Senkpiel --- test/parallel/test-fs-mkdtemp-prefix-check.js | 25 +++++++++++++++++++ .../test-mkdtemp-sync-prefix-check.js | 13 ---------- 2 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 test/parallel/test-fs-mkdtemp-prefix-check.js delete mode 100644 test/parallel/test-mkdtemp-sync-prefix-check.js diff --git a/test/parallel/test-fs-mkdtemp-prefix-check.js b/test/parallel/test-fs-mkdtemp-prefix-check.js new file mode 100644 index 00000000000000..786d0fe7bae169 --- /dev/null +++ b/test/parallel/test-fs-mkdtemp-prefix-check.js @@ -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); +}); diff --git a/test/parallel/test-mkdtemp-sync-prefix-check.js b/test/parallel/test-mkdtemp-sync-prefix-check.js deleted file mode 100644 index 825f622f069b5e..00000000000000 --- a/test/parallel/test-mkdtemp-sync-prefix-check.js +++ /dev/null @@ -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$/ - ); -});