@@ -4,7 +4,8 @@ const path = require('path').posix || require('path')
44const { join } = require ( 'isomorphic-git/internal-apis' )
55
66describe ( 'utils/join' , ( ) => {
7- it ( 'should join "good" paths the same as path.join' , async ( ) => {
7+ describe ( 'when "internal join" generates paths the same as "path.join"' , ( ) => {
8+ // Tests adapted from path-browserify
89 const fixtures = [
910 [ '/foo/bar' , 'baz' ] ,
1011 [ 'foo/bar' , 'baz' ] ,
@@ -18,60 +19,39 @@ describe('utils/join', () => {
1819 [ '/' , '.' ] ,
1920 [ '/' , '.git' ] ,
2021 [ '.' , '.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' ] ,
2148 ]
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- }
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+ } )
7656 } )
7757} )
0 commit comments