Log unhandled exceptions to help see errors in tests (#2815)

This commit is contained in:
BrennanConroy 2018-08-16 10:56:08 -07:00 committed by GitHub
parent b981e24a53
commit 3b853daa1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 40 additions and 4 deletions

View File

@ -2,6 +2,9 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
import { AbortController } from "../src/AbortController";
import { registerUnhandledRejectionHandler } from "./Utils";
registerUnhandledRejectionHandler();
describe("AbortSignal", () => {
describe("aborted", () => {

View File

@ -3,6 +3,9 @@
import { HttpRequest } from "../src/HttpClient";
import { TestHttpClient } from "./TestHttpClient";
import { registerUnhandledRejectionHandler } from "./Utils";
registerUnhandledRejectionHandler();
describe("HttpClient", () => {
describe("get", () => {

View File

@ -12,7 +12,7 @@ import { EventSourceConstructor, WebSocketConstructor } from "../src/Polyfills";
import { eachEndpointUrl, eachTransport, VerifyLogger } from "./Common";
import { TestHttpClient } from "./TestHttpClient";
import { PromiseSource } from "./Utils";
import { PromiseSource, registerUnhandledRejectionHandler } from "./Utils";
const commonOptions: IHttpConnectionOptions = {
logger: NullLogger.instance,
@ -28,6 +28,8 @@ const defaultNegotiateResponse: INegotiateResponse = {
connectionId: defaultConnectionId,
};
registerUnhandledRejectionHandler();
describe("HttpConnection", () => {
it("cannot be created with relative url if document object is not present", () => {
expect(() => new HttpConnection("/test", commonOptions))

View File

@ -12,12 +12,14 @@ import { IStreamSubscriber } from "../src/Stream";
import { TextMessageFormat } from "../src/TextMessageFormat";
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) {
return HubConnection.create(connection, logger || NullLogger.instance, protocol || new JsonHubProtocol());
}
registerUnhandledRejectionHandler();
describe("HubConnection", () => {
describe("start", () => {

View File

@ -12,7 +12,7 @@ import { NullLogger } from "../src/Loggers";
import { VerifyLogger } from "./Common";
import { TestHttpClient } from "./TestHttpClient";
import { PromiseSource } from "./Utils";
import { PromiseSource, registerUnhandledRejectionHandler } from "./Utils";
const longPollingNegotiateResponse = {
availableTransports: [
@ -25,6 +25,8 @@ const commonHttpOptions: IHttpConnectionOptions = {
logMessageContent: true,
};
registerUnhandledRejectionHandler();
describe("HubConnectionBuilder", () => {
eachMissingValue((val, name) => {
it(`configureLogging throws if logger is ${name}`, () => {

View File

@ -5,6 +5,9 @@ import { CompletionMessage, InvocationMessage, MessageType, StreamItemMessage }
import { JsonHubProtocol } from "../src/JsonHubProtocol";
import { TextMessageFormat } from "../src/TextMessageFormat";
import { VerifyLogger } from "./Common";
import { registerUnhandledRejectionHandler } from "./Utils";
registerUnhandledRejectionHandler();
describe("JsonHubProtocol", () => {
it("can write/read non-blocking Invocation message", async () => {

View File

@ -7,7 +7,9 @@ import { LongPollingTransport } from "../src/LongPollingTransport";
import { VerifyLogger } from "./Common";
import { TestHttpClient } from "./TestHttpClient";
import { PromiseSource, SyncPoint } from "./Utils";
import { PromiseSource, registerUnhandledRejectionHandler, SyncPoint } from "./Utils";
registerUnhandledRejectionHandler();
describe("LongPollingTransport", () => {
it("shuts down polling by aborting in-progress request", async () => {

View File

@ -9,6 +9,9 @@ import { ServerSentEventsTransport } from "../src/ServerSentEventsTransport";
import { VerifyLogger } from "./Common";
import { TestEventSource, TestMessageEvent } from "./TestEventSource";
import { TestHttpClient } from "./TestHttpClient";
import { registerUnhandledRejectionHandler } from "./Utils";
registerUnhandledRejectionHandler();
describe("ServerSentEventsTransport", () => {
it("does not allow non-text formats", async () => {

View File

@ -2,6 +2,9 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
import { TextMessageFormat } from "../src/TextMessageFormat";
import { registerUnhandledRejectionHandler } from "./Utils";
registerUnhandledRejectionHandler();
describe("TextMessageFormat", () => {
([

View File

@ -3,6 +3,16 @@
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> {
const source = new PromiseSource<void>();
setTimeout(() => source.resolve(), durationInMilliseconds);

View File

@ -7,6 +7,9 @@ import { WebSocketTransport } from "../src/WebSocketTransport";
import { VerifyLogger } from "./Common";
import { TestMessageEvent } from "./TestEventSource";
import { TestCloseEvent, TestErrorEvent, TestEvent, TestWebSocket } from "./TestWebSocket";
import { registerUnhandledRejectionHandler } from "./Utils";
registerUnhandledRejectionHandler();
describe("WebSocketTransport", () => {
it("sets websocket binarytype to arraybuffer on Binary transferformat", async () => {