node/test/parallel/test-fs-realpath-on-substed-drive.js
Bartosz Sosnowski 08996fde3c fs: restore JS implementation of realpath
This reverts parts of b488b19eaf
restoring javascript implementation of realpath and realpathSync.

Fixes: https://github.com/nodejs/node/issues/7175
Fixes: https://github.com/nodejs/node/issues/6861
Fixes: https://github.com/nodejs/node/issues/7294
Fixes: https://github.com/nodejs/node/issues/7192
Fixes: https://github.com/nodejs/node/issues/7044
Fixes: https://github.com/nodejs/node/issues/6624
Fixes: https://github.com/nodejs/node/issues/6978
PR-URL: https://github.com/nodejs/node/pull/7899
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2016-08-12 13:07:55 +02:00

54 lines
1.3 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const spawnSync = require('child_process').spawnSync;
if (!common.isWindows) {
common.skip('Test for Windows only');
return;
}
let result;
// create a subst drive
const driveLetters = 'ABCDEFGHIJKLMNOPQRSTUWXYZ';
let drive;
for (var i = 0; i < driveLetters.length; ++i) {
drive = `${driveLetters[i]}:`;
result = spawnSync('subst', [drive, common.fixturesDir]);
if (result.status === 0)
break;
}
if (i === driveLetters.length) {
common.skip('Cannot create subst drive');
return;
}
// schedule cleanup (and check if all callbacks where called)
process.on('exit', function() {
spawnSync('subst', ['/d', drive]);
});
// test:
const filename = `${drive}\\empty.js`;
const filenameBuffer = Buffer.from(filename);
result = fs.realpathSync(filename);
assert.strictEqual(result, filename);
result = fs.realpathSync(filename, 'buffer');
assert(Buffer.isBuffer(result));
assert(result.equals(filenameBuffer));
fs.realpath(filename, common.mustCall(function(err, result) {
assert(!err);
assert.strictEqual(result, filename);
}));
fs.realpath(filename, 'buffer', common.mustCall(function(err, result) {
assert(!err);
assert(Buffer.isBuffer(result));
assert(result.equals(filenameBuffer));
}));