@@ -3,43 +3,61 @@ import { Endpoint } from "@aws-sdk/types";
33import { parseUrl } from "./" ;
44
55describe ( "parseUrl" , ( ) => {
6- const testCases = new Map < string , Endpoint > ( [
7- [
8- "https://www.example.com/path/to%20the/file.ext?snap=cr%C3%A4ckle&snap=p%C3%B4p&fizz=buzz&quux" ,
9- {
10- protocol : "https:" ,
11- hostname : "www.example.com" ,
12- path : "/path/to%20the/file.ext" ,
13- query : {
14- snap : [ "cräckle" , "pôp" ] ,
15- fizz : "buzz" ,
16- quux : null ,
6+ describe ( "should correctly parse string" , ( ) => {
7+ const successCases : [ string , Endpoint ] [ ] = [
8+ [
9+ "https://www.example.com/path/to%20the/file.ext?snap=cr%C3%A4ckle&snap=p%C3%B4p&fizz=buzz&quux" ,
10+ {
11+ protocol : "https:" ,
12+ hostname : "www.example.com" ,
13+ path : "/path/to%20the/file.ext" ,
14+ query : {
15+ snap : [ "cräckle" , "pôp" ] ,
16+ fizz : "buzz" ,
17+ quux : null ,
18+ } ,
1719 } ,
18- } ,
19- ] ,
20- [
21- "http://example.com:54321" ,
22- {
23- protocol : "http:" ,
24- hostname : "example.com" ,
25- port : 54321 ,
26- path : "/" ,
27- } ,
28- ] ,
29- [
30- "https://example.com?foo=bar" ,
31- {
32- protocol : "https:" ,
33- hostname : "example.com" ,
34- path : "/" ,
35- query : { foo : "bar" } ,
36- } ,
37- ] ,
38- ] ) ;
20+ ] ,
21+ [
22+ "http://example.com:54321" ,
23+ {
24+ protocol : "http:" ,
25+ hostname : "example.com" ,
26+ port : 54321 ,
27+ path : "/" ,
28+ } ,
29+ ] ,
30+ [
31+ "https://example.com?foo=bar" ,
32+ {
33+ protocol : "https:" ,
34+ hostname : "example.com" ,
35+ path : "/" ,
36+ query : { foo : "bar" } ,
37+ } ,
38+ ] ,
39+ ] ;
40+
41+ successCases . forEach ( ( [ url , parsed ] ) => {
42+ it ( url , ( ) => {
43+ expect ( parseUrl ( url ) ) . toEqual ( parsed ) ;
44+ } ) ;
45+ } ) ;
46+ } ) ;
47+
48+ describe ( "should throw error" , ( ) => {
49+ const failureCases : [ string , Error ] [ ] = [
50+ [ "example.com" , new TypeError ( "Invalid URL: example.com" ) ] ,
51+ [ "endpoint" , new TypeError ( "Invalid URL: endpoint" ) ] ,
52+ ] ;
3953
40- for ( const [ url , parsed ] of testCases ) {
41- it ( `should correctly parse ${ url } ` , ( ) => {
42- expect ( parseUrl ( url ) ) . toEqual ( parsed ) ;
54+ failureCases . forEach ( ( [ url , error ] ) => {
55+ it ( url , ( ) => {
56+ expect ( ( ) => {
57+ const output = parseUrl ( url ) ;
58+ console . log ( output ) ;
59+ } ) . toThrow ( error ) ;
60+ } ) ;
4361 } ) ;
44- }
62+ } ) ;
4563} ) ;
0 commit comments