diff --git a/lib/internal/url.js b/lib/internal/url.js index e97fb3931607f2..ba54aa8c233354 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -74,6 +74,15 @@ class TupleOrigin { result += `:${this.port}`; return result; } + + inspect() { + return `TupleOrigin { + scheme: ${this.scheme}, + host: ${this.host}, + port: ${this.port}, + domain: ${this.domain} + }`; + } } class URL { diff --git a/test/parallel/test-util-inspect-tuple-origin.js b/test/parallel/test-util-inspect-tuple-origin.js new file mode 100644 index 00000000000000..7529273756afe9 --- /dev/null +++ b/test/parallel/test-util-inspect-tuple-origin.js @@ -0,0 +1,37 @@ +'use strict'; + +require('../common'); +const assert = require('assert'); +const inspect = require('util').inspect; +const URL = require('url').URL; + +assert.strictEqual( + inspect(URL.originFor('http://test.com:8000')), + `TupleOrigin { + scheme: http, + host: test.com, + port: 8000, + domain: null + }` + ); + +assert.strictEqual( + inspect(URL.originFor('http://test.com')), + `TupleOrigin { + scheme: http, + host: test.com, + port: undefined, + domain: null + }` + ); + + +assert.strictEqual( + inspect(URL.originFor('https://test.com')), + `TupleOrigin { + scheme: https, + host: test.com, + port: undefined, + domain: null + }` + );