fs.directory returns empty string if path has no parent directory

This commit is contained in:
Corey Johnson
2012-07-03 14:43:56 -07:00
parent e36b5521bd
commit 08b0a686ed
2 changed files with 6 additions and 3 deletions

View File

@@ -21,8 +21,9 @@ describe "fs", ->
describe "when called with a directory path", ->
it "return the path it was given", ->
expect(fs.directory(require.resolve('fixtures/dir'))).toBe require.resolve('fixtures')
expect(fs.directory(require.resolve('fixtures/dir/'))).toBe require.resolve('fixtures')
expect(fs.directory("/a/b/c")).toBe "/a/b"
expect(fs.directory("/a")).toBe ""
expect(fs.directory("a")).toBe ""
describe ".exists(path)", ->
it "returns true when path exsits", ->

View File

@@ -21,7 +21,9 @@ module.exports =
# parent directory if the file is a directory. A terminal directory
# separator is ignored.
directory: (path) ->
path.replace(new RegExp("/#{@base(path)}\/?$"), '')
parentPath = path.replace(new RegExp("/#{@base(path)}\/?$"), '')
return "" if path == parentPath
parentPath
# Returns true if the file specified by path exists
exists: (path) ->