Log unhandled exceptions to help see errors in tests (#2815)
This commit is contained in:
parent
b981e24a53
commit
3b853daa1a
|
|
@ -2,6 +2,9 @@
|
||||||
// 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 { AbortController } from "../src/AbortController";
|
import { AbortController } from "../src/AbortController";
|
||||||
|
import { registerUnhandledRejectionHandler } from "./Utils";
|
||||||
|
|
||||||
|
registerUnhandledRejectionHandler();
|
||||||
|
|
||||||
describe("AbortSignal", () => {
|
describe("AbortSignal", () => {
|
||||||
describe("aborted", () => {
|
describe("aborted", () => {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@
|
||||||
|
|
||||||
import { HttpRequest } from "../src/HttpClient";
|
import { HttpRequest } from "../src/HttpClient";
|
||||||
import { TestHttpClient } from "./TestHttpClient";
|
import { TestHttpClient } from "./TestHttpClient";
|
||||||
|
import { registerUnhandledRejectionHandler } from "./Utils";
|
||||||
|
|
||||||
|
registerUnhandledRejectionHandler();
|
||||||
|
|
||||||
describe("HttpClient", () => {
|
describe("HttpClient", () => {
|
||||||
describe("get", () => {
|
describe("get", () => {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import { EventSourceConstructor, WebSocketConstructor } from "../src/Polyfills";
|
||||||
|
|
||||||
import { eachEndpointUrl, eachTransport, VerifyLogger } from "./Common";
|
import { eachEndpointUrl, eachTransport, VerifyLogger } from "./Common";
|
||||||
import { TestHttpClient } from "./TestHttpClient";
|
import { TestHttpClient } from "./TestHttpClient";
|
||||||
import { PromiseSource } from "./Utils";
|
import { PromiseSource, registerUnhandledRejectionHandler } from "./Utils";
|
||||||
|
|
||||||
const commonOptions: IHttpConnectionOptions = {
|
const commonOptions: IHttpConnectionOptions = {
|
||||||
logger: NullLogger.instance,
|
logger: NullLogger.instance,
|
||||||
|
|
@ -28,6 +28,8 @@ const defaultNegotiateResponse: INegotiateResponse = {
|
||||||
connectionId: defaultConnectionId,
|
connectionId: defaultConnectionId,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
registerUnhandledRejectionHandler();
|
||||||
|
|
||||||
describe("HttpConnection", () => {
|
describe("HttpConnection", () => {
|
||||||
it("cannot be created with relative url if document object is not present", () => {
|
it("cannot be created with relative url if document object is not present", () => {
|
||||||
expect(() => new HttpConnection("/test", commonOptions))
|
expect(() => new HttpConnection("/test", commonOptions))
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,14 @@ import { IStreamSubscriber } from "../src/Stream";
|
||||||
import { TextMessageFormat } from "../src/TextMessageFormat";
|
import { TextMessageFormat } from "../src/TextMessageFormat";
|
||||||
|
|
||||||
import { VerifyLogger } from "./Common";
|
import { VerifyLogger } from "./Common";
|
||||||
import { delay, PromiseSource } from "./Utils";
|
import { delay, PromiseSource, registerUnhandledRejectionHandler } from "./Utils";
|
||||||
|
|
||||||
function createHubConnection(connection: IConnection, logger?: ILogger | null, protocol?: IHubProtocol | null) {
|
function createHubConnection(connection: IConnection, logger?: ILogger | null, protocol?: IHubProtocol | null) {
|
||||||
return HubConnection.create(connection, logger || NullLogger.instance, protocol || new JsonHubProtocol());
|
return HubConnection.create(connection, logger || NullLogger.instance, protocol || new JsonHubProtocol());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerUnhandledRejectionHandler();
|
||||||
|
|
||||||
describe("HubConnection", () => {
|
describe("HubConnection", () => {
|
||||||
|
|
||||||
describe("start", () => {
|
describe("start", () => {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import { NullLogger } from "../src/Loggers";
|
||||||
|
|
||||||
import { VerifyLogger } from "./Common";
|
import { VerifyLogger } from "./Common";
|
||||||
import { TestHttpClient } from "./TestHttpClient";
|
import { TestHttpClient } from "./TestHttpClient";
|
||||||
import { PromiseSource } from "./Utils";
|
import { PromiseSource, registerUnhandledRejectionHandler } from "./Utils";
|
||||||
|
|
||||||
const longPollingNegotiateResponse = {
|
const longPollingNegotiateResponse = {
|
||||||
availableTransports: [
|
availableTransports: [
|
||||||
|
|
@ -25,6 +25,8 @@ const commonHttpOptions: IHttpConnectionOptions = {
|
||||||
logMessageContent: true,
|
logMessageContent: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
registerUnhandledRejectionHandler();
|
||||||
|
|
||||||
describe("HubConnectionBuilder", () => {
|
describe("HubConnectionBuilder", () => {
|
||||||
eachMissingValue((val, name) => {
|
eachMissingValue((val, name) => {
|
||||||
it(`configureLogging throws if logger is ${name}`, () => {
|
it(`configureLogging throws if logger is ${name}`, () => {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,9 @@ import { CompletionMessage, InvocationMessage, MessageType, StreamItemMessage }
|
||||||
import { JsonHubProtocol } from "../src/JsonHubProtocol";
|
import { JsonHubProtocol } from "../src/JsonHubProtocol";
|
||||||
import { TextMessageFormat } from "../src/TextMessageFormat";
|
import { TextMessageFormat } from "../src/TextMessageFormat";
|
||||||
import { VerifyLogger } from "./Common";
|
import { VerifyLogger } from "./Common";
|
||||||
|
import { registerUnhandledRejectionHandler } from "./Utils";
|
||||||
|
|
||||||
|
registerUnhandledRejectionHandler();
|
||||||
|
|
||||||
describe("JsonHubProtocol", () => {
|
describe("JsonHubProtocol", () => {
|
||||||
it("can write/read non-blocking Invocation message", async () => {
|
it("can write/read non-blocking Invocation message", async () => {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,9 @@ import { LongPollingTransport } from "../src/LongPollingTransport";
|
||||||
|
|
||||||
import { VerifyLogger } from "./Common";
|
import { VerifyLogger } from "./Common";
|
||||||
import { TestHttpClient } from "./TestHttpClient";
|
import { TestHttpClient } from "./TestHttpClient";
|
||||||
import { PromiseSource, SyncPoint } from "./Utils";
|
import { PromiseSource, registerUnhandledRejectionHandler, SyncPoint } from "./Utils";
|
||||||
|
|
||||||
|
registerUnhandledRejectionHandler();
|
||||||
|
|
||||||
describe("LongPollingTransport", () => {
|
describe("LongPollingTransport", () => {
|
||||||
it("shuts down polling by aborting in-progress request", async () => {
|
it("shuts down polling by aborting in-progress request", async () => {
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@ import { ServerSentEventsTransport } from "../src/ServerSentEventsTransport";
|
||||||
import { VerifyLogger } from "./Common";
|
import { VerifyLogger } from "./Common";
|
||||||
import { TestEventSource, TestMessageEvent } from "./TestEventSource";
|
import { TestEventSource, TestMessageEvent } from "./TestEventSource";
|
||||||
import { TestHttpClient } from "./TestHttpClient";
|
import { TestHttpClient } from "./TestHttpClient";
|
||||||
|
import { registerUnhandledRejectionHandler } from "./Utils";
|
||||||
|
|
||||||
|
registerUnhandledRejectionHandler();
|
||||||
|
|
||||||
describe("ServerSentEventsTransport", () => {
|
describe("ServerSentEventsTransport", () => {
|
||||||
it("does not allow non-text formats", async () => {
|
it("does not allow non-text formats", async () => {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@
|
||||||
// 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 { TextMessageFormat } from "../src/TextMessageFormat";
|
import { TextMessageFormat } from "../src/TextMessageFormat";
|
||||||
|
import { registerUnhandledRejectionHandler } from "./Utils";
|
||||||
|
|
||||||
|
registerUnhandledRejectionHandler();
|
||||||
|
|
||||||
describe("TextMessageFormat", () => {
|
describe("TextMessageFormat", () => {
|
||||||
([
|
([
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,16 @@
|
||||||
|
|
||||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000;
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000;
|
||||||
|
|
||||||
|
export function registerUnhandledRejectionHandler(): void {
|
||||||
|
process.on("unhandledRejection", (error) => {
|
||||||
|
if (error && error.stack) {
|
||||||
|
console.error(error.stack);
|
||||||
|
} else {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function delay(durationInMilliseconds: number): Promise<void> {
|
export function delay(durationInMilliseconds: number): Promise<void> {
|
||||||
const source = new PromiseSource<void>();
|
const source = new PromiseSource<void>();
|
||||||
setTimeout(() => source.resolve(), durationInMilliseconds);
|
setTimeout(() => source.resolve(), durationInMilliseconds);
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,9 @@ import { WebSocketTransport } from "../src/WebSocketTransport";
|
||||||
import { VerifyLogger } from "./Common";
|
import { VerifyLogger } from "./Common";
|
||||||
import { TestMessageEvent } from "./TestEventSource";
|
import { TestMessageEvent } from "./TestEventSource";
|
||||||
import { TestCloseEvent, TestErrorEvent, TestEvent, TestWebSocket } from "./TestWebSocket";
|
import { TestCloseEvent, TestErrorEvent, TestEvent, TestWebSocket } from "./TestWebSocket";
|
||||||
|
import { registerUnhandledRejectionHandler } from "./Utils";
|
||||||
|
|
||||||
|
registerUnhandledRejectionHandler();
|
||||||
|
|
||||||
describe("WebSocketTransport", () => {
|
describe("WebSocketTransport", () => {
|
||||||
it("sets websocket binarytype to arraybuffer on Binary transferformat", async () => {
|
it("sets websocket binarytype to arraybuffer on Binary transferformat", async () => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue