|
| 1 | +// Flags: --expose-internals |
1 | 2 | 'use strict'; |
2 | 3 |
|
3 | 4 | require('../common'); |
4 | 5 |
|
5 | 6 | const URL = require('url').URL; |
6 | 7 | const assert = require('assert'); |
| 8 | +const urlToOptions = require('internal/url').urlToOptions; |
7 | 9 |
|
8 | 10 | const url = new URL('http://user:[email protected]:21/aaa/zzz?l=24#test'); |
9 | 11 | const oldParams = url.searchParams; // for test of [SameObject] |
@@ -125,3 +127,18 @@ assert.strictEqual(url.toString(), |
125 | 127 | 'https://user2:[email protected]:23/aaa/bbb?k=99#abcd'); |
126 | 128 | assert.strictEqual((delete url.searchParams), true); |
127 | 129 | assert.strictEqual(url.searchParams, oldParams); |
| 130 | + |
| 131 | +// Test urlToOptions |
| 132 | +{ |
| 133 | + const opts = |
| 134 | + urlToOptions(new URL('http://user:[email protected]:21/aaa/zzz?l=24#test')); |
| 135 | + assert.strictEqual(opts instanceof URL, false); |
| 136 | + assert.strictEqual(opts.protocol, 'http:'); |
| 137 | + assert.strictEqual(opts.auth, 'user:pass'); |
| 138 | + assert.strictEqual(opts.hostname, 'foo.bar.com'); |
| 139 | + assert.strictEqual(opts.port, 21); |
| 140 | + assert.strictEqual(opts.path, '/aaa/zzz?l=24'); |
| 141 | + assert.strictEqual(opts.pathname, '/aaa/zzz'); |
| 142 | + assert.strictEqual(opts.search, '?l=24'); |
| 143 | + assert.strictEqual(opts.hash, '#test'); |
| 144 | +} |
0 commit comments