-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(join): numerous bug fixes to the join algorithm
This fix addresses issues with absolute paths and null/empty paths in the join algorithm. The normalize function was also renamed to relativeToFile. This is a breaking change.
- Loading branch information
1 parent
0cfaeb1
commit 0114d32
Showing
3 changed files
with
146 additions
and
39 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 |
---|---|---|
@@ -1,19 +1,117 @@ | ||
import { normalize, join } from '../src/index'; | ||
import { relativeToFile, join } from '../src/index'; | ||
|
||
describe('normalize', () => { | ||
it('can make a path relative to a file', () => { | ||
var baseUrl = 'some/file.html'; | ||
describe('relativeToFile', () => { | ||
it('can make a dot path relative to a simple file', () => { | ||
var file = 'some/file.html'; | ||
var path = './other/module'; | ||
|
||
expect(normalize(path, baseUrl)).toBe('some/other/module'); | ||
expect(relativeToFile(path, file)).toBe('some/other/module'); | ||
}); | ||
|
||
it('can make a dot path relative to an absolute file', () => { | ||
var file = 'http://durandal.io/some/file.html'; | ||
var path = './other/module'; | ||
|
||
expect(relativeToFile(path, file)).toBe('http://durandal.io/some/other/module'); | ||
}); | ||
|
||
it('can make a double dot path relative to an absolute file', () => { | ||
var file = 'http://durandal.io/some/file.html'; | ||
var path = '../other/module'; | ||
|
||
expect(relativeToFile(path, file)).toBe('http://durandal.io/other/module'); | ||
}); | ||
|
||
it('returns path if null file provided', () => { | ||
var file = null; | ||
var path = 'module'; | ||
|
||
expect(relativeToFile(path, file)).toBe('module'); | ||
}); | ||
|
||
it('returns path if empty file provided', () => { | ||
var file = ''; | ||
var path = 'module'; | ||
|
||
expect(relativeToFile(path, file)).toBe('module'); | ||
}); | ||
}); | ||
|
||
describe('join', () => { | ||
it('can join two paths', () => { | ||
it('can combine two simple paths', () => { | ||
var path1 = 'one'; | ||
var path2 = 'two'; | ||
|
||
expect(join(path1, path2)).toBe('one/two'); | ||
}); | ||
|
||
it('can combine an absolute path and a simple path', () => { | ||
var path1 = 'http://durandal.io'; | ||
var path2 = 'two'; | ||
|
||
expect(join(path1, path2)).toBe('http://durandal.io/two'); | ||
}); | ||
|
||
it('can combine an absolute path and a simple path with slash', () => { | ||
var path1 = 'http://durandal.io'; | ||
var path2 = '/two'; | ||
|
||
expect(join(path1, path2)).toBe('http://durandal.io/two'); | ||
}); | ||
|
||
it('can combine an absolute path and a simple path with a dot', () => { | ||
var path1 = 'http://durandal.io'; | ||
var path2 = './two'; | ||
|
||
expect(join(path1, path2)).toBe('http://durandal.io/two'); | ||
}); | ||
|
||
it('can combine a simple path and a relative path', () => { | ||
var path1 = 'one'; | ||
var path2 = '../two'; | ||
|
||
expect(join(path1, path2)).toBe('two'); | ||
}); | ||
|
||
it('can combine an absolute path and a relative path', () => { | ||
var path1 = 'http://durandal.io/somewhere'; | ||
var path2 = '../two'; | ||
|
||
expect(join(path1, path2)).toBe('http://durandal.io/two'); | ||
}); | ||
|
||
it('can combine a complex path and a relative path', () => { | ||
var path1 = 'one/three'; | ||
var path2 = '../two'; | ||
|
||
expect(join(path1, path2)).toBe('one/two'); | ||
}); | ||
|
||
it('returns path2 if path1 null', () => { | ||
var path1 = null; | ||
var path2 = 'two'; | ||
|
||
expect(join(path1, path2)).toBe('two'); | ||
}); | ||
|
||
it('returns path2 if path1 empty', () => { | ||
var path1 = ''; | ||
var path2 = 'two'; | ||
|
||
expect(join(path1, path2)).toBe('two'); | ||
}); | ||
|
||
it('returns path1 if path2 null', () => { | ||
var path1 = 'one'; | ||
var path2 = null; | ||
|
||
expect(join(path1, path2)).toBe('one'); | ||
}); | ||
|
||
it('returns path1 if path2 empty', () => { | ||
var path1 = 'one'; | ||
var path2 = ''; | ||
|
||
expect(join(path1, path2)).toBe('one'); | ||
}); | ||
}); |