Add eachHttpClient test option to get basic coverage for new fetchhttpclient

This commit is contained in:
Harley Adams 2019-07-29 11:07:42 -07:00 committed by Brennan
parent 71a8092cb9
commit 2be0ffae19
3 changed files with 117 additions and 101 deletions

View File

@ -1,8 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
import { HttpTransportType, IHubProtocol, JsonHubProtocol } from "@microsoft/signalr"; import { DefaultHttpClient, FetchHttpClient, HttpClient, HttpTransportType, IHubProtocol, JsonHubProtocol, XhrHttpClient } from "@microsoft/signalr";
import { MessagePackHubProtocol } from "@microsoft/signalr-protocol-msgpack"; import { MessagePackHubProtocol } from "@microsoft/signalr-protocol-msgpack";
import { TestLogger } from "./TestLogger";
// On slower CI machines, these tests sometimes take longer than 5s // On slower CI machines, these tests sometimes take longer than 5s
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20 * 1000; jasmine.DEFAULT_TIMEOUT_INTERVAL = 20 * 1000;
@ -100,3 +101,11 @@ export function eachTransportAndProtocol(action: (transport: HttpTransportType,
export function getGlobalObject(): any { export function getGlobalObject(): any {
return typeof window !== "undefined" ? window : global; return typeof window !== "undefined" ? window : global;
} }
export function eachHttpClient(action: (transport: HttpClient) => void) {
const httpClients: HttpClient[] = [new FetchHttpClient(TestLogger.instance), new XhrHttpClient(TestLogger.instance), new DefaultHttpClient(TestLogger.instance)];
return httpClients.forEach((t) => {
return action(t);
});
}

View File

@ -5,7 +5,7 @@
// tslint:disable:no-floating-promises // tslint:disable:no-floating-promises
import { HttpTransportType, IHttpConnectionOptions, TransferFormat } from "@microsoft/signalr"; import { HttpTransportType, IHttpConnectionOptions, TransferFormat } from "@microsoft/signalr";
import { eachTransport, ECHOENDPOINT_URL } from "./Common"; import { eachHttpClient, eachTransport, ECHOENDPOINT_URL } from "./Common";
import { TestLogger } from "./TestLogger"; import { TestLogger } from "./TestLogger";
// We want to continue testing HttpConnection, but we don't export it anymore. So just pull it in directly from the source file. // We want to continue testing HttpConnection, but we don't export it anymore. So just pull it in directly from the source file.
@ -44,6 +44,7 @@ describe("connection", () => {
}); });
eachTransport((transportType) => { eachTransport((transportType) => {
eachHttpClient((httpClient) => {
describe(`over ${HttpTransportType[transportType]}`, () => { describe(`over ${HttpTransportType[transportType]}`, () => {
it("can send and receive messages", (done) => { it("can send and receive messages", (done) => {
const message = "Hello World!"; const message = "Hello World!";
@ -51,6 +52,7 @@ describe("connection", () => {
// and the leading '/' should be automatically added to the url // and the leading '/' should be automatically added to the url
const connection = new HttpConnection(ECHOENDPOINT_URL, { const connection = new HttpConnection(ECHOENDPOINT_URL, {
...commonOptions, ...commonOptions,
httpClient,
transport: transportType, transport: transportType,
}); });
@ -79,6 +81,7 @@ describe("connection", () => {
// DON'T use commonOptions because we want to specifically test the scenario where logMessageContent is not set. // DON'T use commonOptions because we want to specifically test the scenario where logMessageContent is not set.
const connection = new HttpConnection(ECHOENDPOINT_URL, { const connection = new HttpConnection(ECHOENDPOINT_URL, {
httpClient,
logger: TestLogger.instance, logger: TestLogger.instance,
transport: transportType, transport: transportType,
}); });
@ -114,6 +117,7 @@ describe("connection", () => {
// DON'T use commonOptions because we want to specifically test the scenario where logMessageContent is set to true (even if commonOptions changes). // DON'T use commonOptions because we want to specifically test the scenario where logMessageContent is set to true (even if commonOptions changes).
const connection = new HttpConnection(ECHOENDPOINT_URL, { const connection = new HttpConnection(ECHOENDPOINT_URL, {
httpClient,
logMessageContent: true, logMessageContent: true,
logger: TestLogger.instance, logger: TestLogger.instance,
transport: transportType, transport: transportType,
@ -152,3 +156,4 @@ describe("connection", () => {
}); });
}); });
}); });
});

View File

@ -10,6 +10,7 @@ export { AbortSignal } from "./AbortController";
export { AbortError, HttpError, TimeoutError } from "./Errors"; export { AbortError, HttpError, TimeoutError } from "./Errors";
export { HttpClient, HttpRequest, HttpResponse } from "./HttpClient"; export { HttpClient, HttpRequest, HttpResponse } from "./HttpClient";
export { DefaultHttpClient } from "./DefaultHttpClient"; export { DefaultHttpClient } from "./DefaultHttpClient";
export { FetchHttpClient } from "./FetchHttpClient";
export { IHttpConnectionOptions } from "./IHttpConnectionOptions"; export { IHttpConnectionOptions } from "./IHttpConnectionOptions";
export { HubConnection, HubConnectionState } from "./HubConnection"; export { HubConnection, HubConnectionState } from "./HubConnection";
export { HubConnectionBuilder } from "./HubConnectionBuilder"; export { HubConnectionBuilder } from "./HubConnectionBuilder";
@ -22,3 +23,4 @@ export { NullLogger } from "./Loggers";
export { JsonHubProtocol } from "./JsonHubProtocol"; export { JsonHubProtocol } from "./JsonHubProtocol";
export { Subject } from "./Subject"; export { Subject } from "./Subject";
export { IRetryPolicy, RetryContext } from "./IRetryPolicy"; export { IRetryPolicy, RetryContext } from "./IRetryPolicy";
export { XhrHttpClient } from "./XhrHttpClient";