Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: check if git is present before running the tests
Signed-off-by: Darshan Sen <[email protected]>
  • Loading branch information
RaisinTen committed Mar 21, 2022
commit b76ef18fae205f4dcdad5f206ce3c7ebbd3275f3
24 changes: 15 additions & 9 deletions test/parallel/test-fs-rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ let count = 0;
const nextDirPath = (name = 'rm') =>
path.join(tmpdir.path, `${name}-${count++}`);

const isGitPresent = (() => {
try { execSync('git --version'); return true; } catch { return false; }
})();

function makeNonEmptyDirectory(depth, files, folders, dirname, createSymLinks) {
fs.mkdirSync(dirname, { recursive: true });
fs.writeFileSync(path.join(dirname, 'text.txt'), 'hello', 'utf8');
Expand Down Expand Up @@ -132,7 +136,7 @@ function removeAsync(dir) {

// Removing a .git directory should not throw an EPERM.
// Refs: https://github.com/isaacs/rimraf/issues/21.
{
if (isGitPresent) {
const gitDirectory = nextDirPath();
fs.mkdirSync(gitDirectory);
execSync(`git -C ${gitDirectory} init`);
Expand Down Expand Up @@ -192,7 +196,7 @@ function removeAsync(dir) {

// Removing a .git directory should not throw an EPERM.
// Refs: https://github.com/isaacs/rimraf/issues/21.
{
if (isGitPresent) {
const gitDirectory = nextDirPath();
fs.mkdirSync(gitDirectory);
execSync(`git -C ${gitDirectory} init`);
Expand Down Expand Up @@ -253,13 +257,15 @@ function removeAsync(dir) {

// Removing a .git directory should not throw an EPERM.
// Refs: https://github.com/isaacs/rimraf/issues/21.
(async () => {
const gitDirectory = nextDirPath();
fs.mkdirSync(gitDirectory);
execSync(`git -C ${gitDirectory} init`);
await fs.promises.rm(gitDirectory, { recursive: true });
assert.strictEqual(fs.existsSync(gitDirectory), false);
})().then(common.mustCall());
if (isGitPresent) {
(async () => {
const gitDirectory = nextDirPath();
fs.mkdirSync(gitDirectory);
execSync(`git -C ${gitDirectory} init`);
await fs.promises.rm(gitDirectory, { recursive: true });
assert.strictEqual(fs.existsSync(gitDirectory), false);
})().then(common.mustCall());
}

// Test input validation.
{
Expand Down