@@ -4,8 +4,7 @@ const path = require('path').posix || require('path')
44const { join } = require ( 'isomorphic-git/internal-apis' )
55
66describe ( 'utils/join' , ( ) => {
7- describe ( 'when "internal join" generates paths the same as "path.join"' , ( ) => {
8- // Tests adapted from path-browserify
7+ it ( 'should join "good" paths the same as path.join' , async ( ) => {
98 const fixtures = [
109 [ '/foo/bar' , 'baz' ] ,
1110 [ 'foo/bar' , 'baz' ] ,
@@ -19,39 +18,60 @@ describe('utils/join', () => {
1918 [ '/' , '.' ] ,
2019 [ '/' , '.git' ] ,
2120 [ '.' , '.git' ] ,
22- [ ] ,
23- [ 'foo/x' , './bar' ] ,
24- [ 'foo/x/' , './bar' ] ,
25- [ 'foo/x/' , '.' , 'bar' ] ,
26- [ '.' , '.' , '.' ] ,
27- [ '.' , './' , '.' ] ,
28- [ '.' , '/./' , '.' ] ,
29- [ '.' , '/////./' , '.' ] ,
30- [ '.' ] ,
31- [ '' , '.' ] ,
32- [ 'foo' , '/bar' ] ,
33- [ 'foo' , '' ] ,
34- [ 'foo' , '' , '/bar' ] ,
35- [ '/' ] ,
36- [ '/' , '.' ] ,
37- [ '' ] ,
38- [ '' , '' ] ,
39- [ '' , 'foo' ] ,
40- [ '' , '' , 'foo' ] ,
41- [ ' /foo' ] ,
42- [ ' ' , 'foo' ] ,
43- [ ' ' , '.' ] ,
44- [ ' ' , '' ] ,
45- [ '/' , '/foo' ] ,
46- [ '/' , '//foo' ] ,
47- [ '/' , '' , '/foo' ] ,
4821 ]
49- fixtures . forEach ( fixture => {
50- it ( `"${ JSON . stringify ( fixture ) } " should join to "${ path . join (
51- ...fixture
52- ) } "`, ( ) => {
53- expect ( join ( ...fixture ) ) . toEqual ( path . join ( ...fixture ) )
54- } )
55- } )
22+ for ( const fixture of fixtures ) {
23+ expect ( join ( ...fixture ) ) . toEqual ( path . join ( ...fixture ) )
24+ }
25+ } )
26+ it ( 'should join degenerate paths the same as path.join in these cases' , async ( ) => {
27+ // Tests adapted from path-browserify
28+ const fixtures = [
29+ [ [ ] , '.' ] ,
30+ [ [ 'foo/x' , './bar' ] , 'foo/x/bar' ] ,
31+ [ [ 'foo/x/' , './bar' ] , 'foo/x/bar' ] ,
32+ [ [ 'foo/x/' , '.' , 'bar' ] , 'foo/x/bar' ] ,
33+ [ [ '.' , '.' , '.' ] , '.' ] ,
34+ [ [ '.' , './' , '.' ] , '.' ] ,
35+ [ [ '.' , '/./' , '.' ] , '.' ] ,
36+ [ [ '.' , '/////./' , '.' ] , '.' ] ,
37+ [ [ '.' ] , '.' ] ,
38+ [ [ '' , '.' ] , '.' ] ,
39+ [ [ 'foo' , '/bar' ] , 'foo/bar' ] ,
40+ [ [ 'foo' , '' ] , 'foo' ] ,
41+ [ [ 'foo' , '' , '/bar' ] , 'foo/bar' ] ,
42+ [ [ '/' ] , '/' ] ,
43+ [ [ '/' , '.' ] , '/' ] ,
44+ [ [ '' ] , '.' ] ,
45+ [ [ '' , '' ] , '.' ] ,
46+ [ [ '' , 'foo' ] , 'foo' ] ,
47+ [ [ '' , '' , 'foo' ] , 'foo' ] ,
48+ [ [ ' /foo' ] , ' /foo' ] ,
49+ [ [ ' ' , 'foo' ] , ' /foo' ] ,
50+ [ [ ' ' , '.' ] , ' ' ] ,
51+ [ [ ' ' , '' ] , ' ' ] ,
52+ [ [ '/' , '/foo' ] , '/foo' ] ,
53+ [ [ '/' , '//foo' ] , '/foo' ] ,
54+ [ [ '/' , '' , '/foo' ] , '/foo' ] ,
55+ ]
56+ for ( const [ args , result ] of fixtures ) {
57+ expect ( join ( ...args ) ) . toEqual ( result )
58+ expect ( join ( ...args ) ) . toEqual ( path . join ( ...args ) )
59+ }
60+ } )
61+ it ( 'should join degenerate paths differently from path.join in these cases' , async ( ) => {
62+ // Tests adapted from path-browserify
63+ const disagreeFixtures = [
64+ [ [ './' ] , '.' ] ,
65+ [ [ '.' , './' ] , '.' ] ,
66+ [ [ '' , '/foo' ] , 'foo' ] ,
67+ [ [ '' , '' , '/foo' ] , 'foo' ] ,
68+ [ [ 'foo/' , '' ] , 'foo' ] ,
69+ [ [ '' , '/' , 'foo' ] , 'foo' ] ,
70+ [ [ '' , '/' , '/foo' ] , 'foo' ] ,
71+ ]
72+ for ( const [ args , result ] of disagreeFixtures ) {
73+ expect ( join ( ...args ) ) . toEqual ( result )
74+ expect ( join ( ...args ) ) . not . toEqual ( path . join ( ...args ) )
75+ }
5676 } )
5777} )
0 commit comments