소스 검색

update tests to pass on travis

Garrett Johnson 5 년 전
부모
커밋
d16bbd781f
2개의 변경된 파일27개의 추가작업 그리고 10개의 파일을 삭제
  1. 2 2
      src/utilities/urlJoin.js
  2. 25 8
      test/urlJoin.test.js

+ 2 - 2
src/utilities/urlJoin.js

@@ -23,10 +23,10 @@ export function urlJoin( ...args ) {
 	} else {
 
 		const parts = lastRoot <= 0 ? args : args.slice( lastRoot );
-		const protocol = parts[ 0 ].match( protocolRegex )[ 0 ].replace( /\//g, '\\' );
+		const protocol = parts[ 0 ].match( protocolRegex )[ 0 ];
 		parts[ 0 ] = parts[ 0 ].substring( protocol.length );
 
-		return protocol + path.join( ...parts );
+		return path.normalize( protocol + path.join( ...parts ) );
 
 	}
 

+ 25 - 8
test/urlJoin.test.js

@@ -1,3 +1,4 @@
+import path from 'path';
 import { urlJoin } from '../src/utilities/urlJoin.js';
 
 describe( 'urlJoin', () => {
@@ -6,15 +7,21 @@ describe( 'urlJoin', () => {
 
 		expect(
 			urlJoin( 'path', 'to', 'file.json' )
-		).toBe( 'path\\to\\file.json' );
+		).toBe(
+			path.normalize( 'path\\to\\file.json' )
+		);
 
 		expect(
 			urlJoin( 'path//', 'to\\other\\', 'file.json' )
-		).toBe( 'path\\to\\other\\file.json' );
+		).toBe(
+			path.normalize( 'path\\to\\other\\file.json' )
+		);
 
 		expect(
 			urlJoin( '//path', 'to', 'file.json' )
-		).toBe( '\\\\path\\to\\file.json' );
+		).toBe(
+			path.normalize( '\\\\path\\to\\file.json' )
+		);
 
 	} );
 
@@ -22,23 +29,33 @@ describe( 'urlJoin', () => {
 
 		expect(
 			urlJoin( 'http://path', 'to', 'file.json' )
-		).toBe( 'http:\\\\path\\to\\file.json' );
+		).toBe(
+			path.normalize( 'http:\\\\path\\to\\file.json' )
+		);
 
 		expect(
 			urlJoin( 'http://path', 'http://path2', 'to', 'file.json' )
-		).toBe( 'http:\\\\path2\\to\\file.json' );
+		).toBe(
+			path.normalize( 'http:\\\\path2\\to\\file.json' )
+		);
 
 		expect(
 			urlJoin( 'https://path', 'to', 'file.json' )
-		).toBe( 'https:\\\\path\\to\\file.json' );
+		).toBe(
+			path.normalize( 'https:\\\\path\\to\\file.json' )
+		);
 
 		expect(
 			urlJoin( 'ftp://path', 'to', 'file.json' )
-		).toBe( 'ftp:\\\\path\\to\\file.json' );
+		).toBe(
+			path.normalize( 'ftp:\\\\path\\to\\file.json' )
+		);
 
 		expect(
 			urlJoin( 'ftp://http://path', 'to', 'file.json' )
-		).toBe( 'ftp:\\\\http:\\path\\to\\file.json' );
+		).toBe(
+			path.normalize( 'ftp:\\\\http:\\path\\to\\file.json' )
+		);
 
 	} );