Skip to content

Commit 8831732

Browse files
captainsafiaaddaleax
authored andcommitted
url: add inspect function to TupleOrigin
This adds a simple inspect function the the TupleOrigin class. This adds tests for the newly added inspect function in the TupleOrigin class. PR-URL: #10039 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]>
1 parent 38ed3fb commit 8831732

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

lib/internal/url.js

+9
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ class TupleOrigin {
6969
result += `:${this.port}`;
7070
return result;
7171
}
72+
73+
inspect() {
74+
return `TupleOrigin {
75+
scheme: ${this.scheme},
76+
host: ${this.host},
77+
port: ${this.port},
78+
domain: ${this.domain}
79+
}`;
80+
}
7281
}
7382

7483
class URL {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
require('../common');
4+
const assert = require('assert');
5+
const inspect = require('util').inspect;
6+
const URL = require('url').URL;
7+
8+
assert.strictEqual(
9+
inspect(URL.originFor('http://test.com:8000')),
10+
`TupleOrigin {
11+
scheme: http,
12+
host: test.com,
13+
port: 8000,
14+
domain: null
15+
}`
16+
);
17+
18+
assert.strictEqual(
19+
inspect(URL.originFor('http://test.com')),
20+
`TupleOrigin {
21+
scheme: http,
22+
host: test.com,
23+
port: undefined,
24+
domain: null
25+
}`
26+
);
27+
28+
29+
assert.strictEqual(
30+
inspect(URL.originFor('https://test.com')),
31+
`TupleOrigin {
32+
scheme: https,
33+
host: test.com,
34+
port: undefined,
35+
domain: null
36+
}`
37+
);

0 commit comments

Comments
 (0)