0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-fs-mkdir-rmdir.js
Vse Mozhet Byt 50b35460e3 test: fix nits in test-fs-mkdir-rmdir.js
* Add common.mustCall().
* Add check for error existence, not only for error details.
* Use test(), not match() in a boolean context.
* Properly reverse meanings of assert messages.

PR-URL: https://github.com/nodejs/node/pull/13680
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2017-06-16 17:47:55 +03:00

39 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const d = path.join(common.tmpDir, 'dir');
common.refreshTmpDir();
// Make sure the directory does not exist
assert(!common.fileExists(d));
// Create the directory now
fs.mkdirSync(d);
// Make sure the directory exists
assert(common.fileExists(d));
// Try creating again, it should fail with EEXIST
assert.throws(function() {
fs.mkdirSync(d);
}, /EEXIST: file already exists, mkdir/);
// Remove the directory now
fs.rmdirSync(d);
// Make sure the directory does not exist
assert(!common.fileExists(d));
// Similarly test the Async version
fs.mkdir(d, 0o666, common.mustCall(function(err) {
assert.ifError(err);
fs.mkdir(d, 0o666, common.mustCall(function(err) {
assert.ok(err, 'got no error');
assert.ok(/^EEXIST/.test(err.message), 'got no EEXIST message');
assert.strictEqual(err.code, 'EEXIST', 'got no EEXIST code');
assert.strictEqual(err.path, d, 'got no proper path for EEXIST');
fs.rmdir(d, assert.ifError);
}));
}));