mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
41ae423718
common.fileExists() can be replaced with fs.existsSync(). PR-URL: https://github.com/nodejs/node/pull/22151 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
37 lines
823 B
JavaScript
37 lines
823 B
JavaScript
'use strict';
|
|
require('../common');
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
// This test ensures that fs.existsSync doesn't incorrectly return false.
|
|
// (especially on Windows)
|
|
// https://github.com/nodejs/node-v0.x-archive/issues/3739
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
let dir = path.resolve(tmpdir.path);
|
|
|
|
// Make sure that the tmp directory is clean
|
|
tmpdir.refresh();
|
|
|
|
// Make a long path.
|
|
for (let i = 0; i < 50; i++) {
|
|
dir = `${dir}/1234567890`;
|
|
try {
|
|
fs.mkdirSync(dir, '0777');
|
|
} catch (e) {
|
|
if (e.code !== 'EEXIST') {
|
|
throw e;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Test if file exists synchronously
|
|
assert(fs.existsSync(dir), 'Directory is not accessible');
|
|
|
|
// Test if file exists asynchronously
|
|
fs.access(dir, function(err) {
|
|
assert.ifError(err);
|
|
});
|