-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
130 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const fs = require('fs') | ||
const util = require('util') | ||
|
||
const stat = util.promisify(fs.stat) | ||
|
||
const fileExists = (file) => stat(file).then((stat) => stat.isFile()).catch(() => false) | ||
|
||
module.exports = fileExists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const { test } = require('tap') | ||
const fileExists = require('../../../lib/utils/file-exists.js') | ||
|
||
test('returns true when arg is a file', async (t) => { | ||
const path = t.testdir({ | ||
foo: 'just some file' | ||
}) | ||
|
||
const result = await fileExists(`${path}/foo`) | ||
t.equal(result, true, 'file exists') | ||
t.end() | ||
}) | ||
|
||
test('returns false when arg is not a file', async (t) => { | ||
const path = t.testdir({ | ||
foo: {} | ||
}) | ||
|
||
const result = await fileExists(`${path}/foo`) | ||
t.equal(result, false, 'file does not exist') | ||
t.end() | ||
}) | ||
|
||
test('returns false when arg does not exist', async (t) => { | ||
const path = t.testdir() | ||
|
||
const result = await fileExists(`${path}/foo`) | ||
t.equal(result, false, 'file does not exist') | ||
t.end() | ||
}) |