-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The Electron SDK uses `basename` to get the file name without path but this returned the full path on Windows. This PR adds Windows support to the regex and adds some tests.
- Loading branch information
Showing
2 changed files
with
38 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { basename, dirname } from '../src/path'; | ||
|
||
describe('path', () => { | ||
describe('basename', () => { | ||
test('unix', () => { | ||
expect(basename('/foo/bar/baz/asdf/quux.html')).toEqual('quux.html'); | ||
expect(basename('foo/bar/baz/asdf/quux.html')).toEqual('quux.html'); | ||
expect(basename('../baz/asdf/quux.html')).toEqual('quux.html'); | ||
expect(basename('quux.html')).toEqual('quux.html'); | ||
}); | ||
test('windows', () => { | ||
expect(basename('c:\\foo\\bar\\baz\\asdf\\quux.html')).toEqual('quux.html'); | ||
expect(basename('\\foo\\bar\\baz\\asdf\\quux.html')).toEqual('quux.html'); | ||
expect(basename('..\\bar\\baz\\asdf\\quux.html')).toEqual('quux.html'); | ||
expect(basename('quux.html')).toEqual('quux.html'); | ||
}); | ||
}); | ||
|
||
describe('dirname', () => { | ||
test('unix', () => { | ||
expect(dirname('/foo/bar/baz/asdf/quux.html')).toEqual('/foo/bar/baz/asdf'); | ||
expect(dirname('foo/bar/baz/asdf/quux.html')).toEqual('foo/bar/baz/asdf'); | ||
expect(dirname('../baz/asdf/quux.html')).toEqual('../baz/asdf'); | ||
expect(dirname('/quux.html')).toEqual('/'); | ||
}); | ||
test('windows', () => { | ||
expect(dirname('C:\\foo\\bar\\baz\\asdf\\quux.html')).toEqual('C:\\foo\\bar\\baz\\asdf'); | ||
expect(dirname('\\foo\\bar\\baz\\asdf\\quux.html')).toEqual('\\foo\\bar\\baz\\asdf'); | ||
expect(dirname('..\\bar\\baz\\asdf\\quux.html')).toEqual('..\\bar\\baz\\asdf'); | ||
expect(dirname('quux.html')).toEqual('.'); | ||
}); | ||
}); | ||
}); |