diff --git a/packages/http-server/src/__tests__/integration/http-server.integration.ts b/packages/http-server/src/__tests__/integration/http-server.integration.ts index 2844a6acb2c1..ee6b0c75c69a 100644 --- a/packages/http-server/src/__tests__/integration/http-server.integration.ts +++ b/packages/http-server/src/__tests__/integration/http-server.integration.ts @@ -135,7 +135,7 @@ describe('HttpServer (integration)', () => { .to.have.property('address') .which.is.an.Object(); await server.stop(); - expect(server.address).to.be.undefined(); + expect(server.address).to.be.null(); }); it('exports listening', async () => { diff --git a/packages/http-server/src/http-server.ts b/packages/http-server/src/http-server.ts index ae803ddd6dbd..8cb6947c5ca2 100644 --- a/packages/http-server/src/http-server.ts +++ b/packages/http-server/src/http-server.ts @@ -50,7 +50,7 @@ export type HttpProtocol = 'http' | 'https'; // Will be extended to `http2` in t export class HttpServer { private _listening: boolean = false; private _protocol: HttpProtocol; - private _address: string | AddressInfo; + private _address: string | AddressInfo | null; private requestListener: RequestListener; readonly server: http.Server | https.Server; private serverOptions: HttpServerOptions; @@ -132,12 +132,12 @@ export class HttpServer { * URL of the HTTP / HTTPS server */ public get url(): string { - if (typeof this._address === 'string') { + if (typeof this._address === 'string' || this._address == null) { /* istanbul ignore if */ if (isWin32()) { - return this._address; + return this._address || ''; } - const basePath = encodeURIComponent(this._address); + const basePath = encodeURIComponent(this._address || ''); return `${this.protocol}+unix://${basePath}`; } let host = this.host; @@ -160,8 +160,8 @@ export class HttpServer { /** * Address of the HTTP / HTTPS server */ - public get address(): string | AddressInfo | undefined { - return this._listening ? this._address : undefined; + public get address(): string | AddressInfo | null { + return this._listening ? this._address : null; } }