@@ -13,17 +13,30 @@ const path = require('path');
13
13
const assert = require ( 'assert' ) ;
14
14
const tests = require ( path . join ( common . fixturesDir , 'url-tests.json' ) ) ;
15
15
16
+ function verifyURL ( url , test ) {
17
+ if ( test . href ) assert . strictEqual ( url . href , test . href ) ;
18
+ if ( test . origin ) assert . strictEqual ( url . origin , test . origin ) ;
19
+ if ( test . protocol ) assert . strictEqual ( url . protocol , test . protocol ) ;
20
+ if ( test . username ) assert . strictEqual ( url . username , test . username ) ;
21
+ if ( test . password ) assert . strictEqual ( url . password , test . password ) ;
22
+ if ( test . hostname ) assert . strictEqual ( url . hostname , test . hostname ) ;
23
+ if ( test . host ) assert . strictEqual ( url . host , test . host ) ;
24
+ if ( test . port !== undefined ) assert . strictEqual ( url . port , test . port ) ;
25
+ if ( test . pathname ) assert . strictEqual ( url . pathname , test . pathname ) ;
26
+ if ( test . search ) assert . strictEqual ( url . search , test . search ) ;
27
+ if ( test . hash ) assert . strictEqual ( url . hash , test . hash ) ;
28
+ }
29
+
16
30
for ( const test of tests ) {
17
31
if ( typeof test === 'string' )
18
32
continue ;
19
33
20
34
if ( test . failure ) {
21
- assert . throws ( ( ) => new URL ( test . input , test . base ) , / I n v a l i d U R L / ) ;
35
+ assert . throws ( ( ) => new URL ( test . input , test . base ) ,
36
+ / ^ T y p e E r r o r : I n v a l i d U R L $ / ) ;
22
37
} else {
23
- assert . doesNotThrow ( ( ) => {
24
- const url = new URL ( test . input , test . base ) ;
25
- assert . strictEqual ( url . href , test . href ) ;
26
- } ) ;
38
+ const url = new URL ( test . input , test . base ) ;
39
+ verifyURL ( url , test ) ;
27
40
}
28
41
}
29
42
@@ -115,18 +128,10 @@ const additional_tests = [
115
128
}
116
129
] ;
117
130
118
- additional_tests . forEach ( ( test ) => {
119
- const u = new URL ( test . url ) ;
120
- if ( test . protocol ) assert . strictEqual ( test . protocol , u . protocol ) ;
121
- if ( test . username ) assert . strictEqual ( test . username , u . username ) ;
122
- if ( test . password ) assert . strictEqual ( test . password , u . password ) ;
123
- if ( test . hostname ) assert . strictEqual ( test . hostname , u . hostname ) ;
124
- if ( test . host ) assert . strictEqual ( test . host , u . host ) ;
125
- if ( test . port !== undefined ) assert . strictEqual ( test . port , u . port ) ;
126
- if ( test . pathname ) assert . strictEqual ( test . pathname , u . pathname ) ;
127
- if ( test . search ) assert . strictEqual ( test . search , u . search ) ;
128
- if ( test . hash ) assert . strictEqual ( test . hash , u . hash ) ;
129
- } ) ;
131
+ for ( const test of additional_tests ) {
132
+ const url = new URL ( test . url ) ;
133
+ verifyURL ( url , test ) ;
134
+ }
130
135
131
136
// test inspect
132
137
const allTests = additional_tests . slice ( ) ;
0 commit comments