Merge pull request #2123 from aspnet/release/2.1

Final TS tidyup (#2120)
This commit is contained in:
Andrew Stanton-Nurse 2018-04-20 16:34:19 -07:00 committed by GitHub
commit 968e31970e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 39 additions and 42 deletions

View File

@ -1,20 +1,20 @@
// 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.
import { BinaryMessageFormat } from "../src/BinaryMessageFormat"
import { BinaryMessageFormat } from "../src/BinaryMessageFormat";
describe("Binary Message Formatter", () => {
([
[[], <Uint8Array[]>[]],
[[0x00], <Uint8Array[]>[ new Uint8Array([])]],
[[0x01, 0xff], <Uint8Array[]>[ new Uint8Array([0xff])]],
[[], [] as Uint8Array[]],
[[0x00], [ new Uint8Array([])] as Uint8Array[]],
[[0x01, 0xff], [ new Uint8Array([0xff])] as Uint8Array[]],
[[0x01, 0xff,
0x01, 0x7f], <Uint8Array[]>[ new Uint8Array([0xff]), new Uint8Array([0x7f])]],
] as [number[], Uint8Array[]][]).forEach(([payload, expected_messages]) => {
0x01, 0x7f], [ new Uint8Array([0xff]), new Uint8Array([0x7f])] as Uint8Array[]],
] as Array<[number[], Uint8Array[]]>).forEach(([payload, expectedMessages]) => {
it(`should parse '${payload}' correctly`, () => {
let messages = BinaryMessageFormat.parse(new Uint8Array(payload).buffer);
expect(messages).toEqual(expected_messages);
})
const messages = BinaryMessageFormat.parse(new Uint8Array(payload).buffer);
expect(messages).toEqual(expectedMessages);
});
});
([
@ -26,34 +26,34 @@ describe("Binary Message Formatter", () => {
[[0x80, 0x80, 0x80, 0x80, 0x08], new Error("Messages bigger than 2GB are not supported.")],
[[0x80, 0x80, 0x80, 0x80, 0x80], new Error("Messages bigger than 2GB are not supported.")],
[[0x02, 0x00], new Error("Incomplete message.")],
[[0xff, 0xff, 0xff, 0xff, 0x07], new Error("Incomplete message.")]
] as [number[], Error][]).forEach(([payload, expected_error]) => {
[[0xff, 0xff, 0xff, 0xff, 0x07], new Error("Incomplete message.")],
] as Array<[number[], Error]>).forEach(([payload, expectedError]) => {
it(`should fail to parse '${payload}'`, () => {
expect(() => BinaryMessageFormat.parse(new Uint8Array(payload).buffer)).toThrow(expected_error);
})
expect(() => BinaryMessageFormat.parse(new Uint8Array(payload).buffer)).toThrow(expectedError);
});
});
([
[[], [0x00]],
[[0x20], [0x01, 0x20]],
] as [number[], number[]][]).forEach(([input, expected_payload]) => {
] as Array<[number[], number[]]>).forEach(([input, expectedPayload]) => {
it(`should write '${input}'`, () => {
let actual = new Uint8Array(BinaryMessageFormat.write(new Uint8Array(input)));
let expected = new Uint8Array(expected_payload);
const actual = new Uint8Array(BinaryMessageFormat.write(new Uint8Array(input)));
const expected = new Uint8Array(expectedPayload);
expect(actual).toEqual(expected);
})
});
});
([0x0000, 0x0001, 0x007f, 0x0080, 0x3fff, 0x4000, 0xc0de] as number[]).forEach(size => {
([0x0000, 0x0001, 0x007f, 0x0080, 0x3fff, 0x4000, 0xc0de] as number[]).forEach((size) => {
it(`messages should be roundtrippable (message size: '${size}')`, () => {
const message = [];
for (let i = 0; i < size; i++) {
message.push(i & 0xff);
}
var payload = new Uint8Array(message);
const payload = new Uint8Array(message);
expect(payload).toEqual(BinaryMessageFormat.parse(BinaryMessageFormat.write(payload))[0]);
})
});
});
});
});

View File

@ -1,9 +1,11 @@
// 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.
import { CompletionMessage, HubMessage, IHubProtocol, ILogger, InvocationMessage, LogLevel, MessageHeaders, MessageType, NullLogger, StreamInvocationMessage, StreamItemMessage, TransferFormat } from "@aspnet/signalr";
import { Buffer } from "buffer";
import * as msgpack5 from "msgpack5";
import { CompletionMessage, HubMessage, IHubProtocol, ILogger, InvocationMessage, LogLevel, MessageHeaders, MessageType, NullLogger, StreamInvocationMessage, StreamItemMessage, TransferFormat } from "@aspnet/signalr";
import { BinaryMessageFormat } from "./BinaryMessageFormat";
export class MessagePackHubProtocol implements IHubProtocol {

View File

@ -1,7 +1,7 @@
// 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.
import { HttpTransportType, ITransport } from "../src/ITransport";
import { HttpTransportType } from "../src/ITransport";
export function eachTransport(action: (transport: HttpTransportType) => void) {
const transportTypes = [

View File

@ -5,7 +5,7 @@ import { HubConnection } from "../src/HubConnection";
import { IConnection } from "../src/IConnection";
import { HubMessage, IHubProtocol, MessageType } from "../src/IHubProtocol";
import { ILogger, LogLevel } from "../src/ILogger";
import { HttpTransportType, ITransport, TransferFormat } from "../src/ITransport";
import { TransferFormat } from "../src/ITransport";
import { JsonHubProtocol } from "../src/JsonHubProtocol";
import { NullLogger } from "../src/Loggers";
import { IStreamSubscriber } from "../src/Stream";

View File

@ -1,10 +1,9 @@
// 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.
import { HubConnectionBuilder } from "../src/HubConnectionBuilder";
import { HttpRequest, HttpResponse } from "../src/HttpClient";
import { HubConnection } from "../src/HubConnection";
import { HubConnectionBuilder } from "../src/HubConnectionBuilder";
import { IHttpConnectionOptions } from "../src/IHttpConnectionOptions";
import { HubMessage, IHubProtocol } from "../src/IHubProtocol";
import { ILogger, LogLevel } from "../src/ILogger";

View File

@ -3,7 +3,7 @@
import { TextMessageFormat } from "../src/TextMessageFormat";
describe("Text Message Formatter", () => {
describe("TextMessageFormat", () => {
([
["\u001e", [""]],
["\u001e\u001e", ["", ""]],

View File

@ -58,4 +58,4 @@ export class PromiseSource<T = void> {
public reject(reason?: any) {
this.rejecter(reason);
}
}
}

View File

@ -1,4 +1,6 @@
import { ILogger, LogLevel } from "./ILogger";
// 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.
import { TextMessageFormat } from "./TextMessageFormat";
export interface HandshakeRequestMessage {

View File

@ -2,15 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
import { HandshakeProtocol, HandshakeRequestMessage, HandshakeResponseMessage } from "./HandshakeProtocol";
import { HttpConnection } from "./HttpConnection";
import { IConnection } from "./IConnection";
import { CancelInvocationMessage, CompletionMessage, HubMessage, IHubProtocol, InvocationMessage, MessageType, StreamInvocationMessage, StreamItemMessage } from "./IHubProtocol";
import { CancelInvocationMessage, CompletionMessage, IHubProtocol, InvocationMessage, MessageType, StreamInvocationMessage, StreamItemMessage } from "./IHubProtocol";
import { ILogger, LogLevel } from "./ILogger";
import { JsonHubProtocol } from "./JsonHubProtocol";
import { NullLogger } from "./Loggers";
import { IStreamResult } from "./Stream";
import { TextMessageFormat } from "./TextMessageFormat";
import { Arg, createLogger, Subject } from "./Utils";
import { Arg, Subject } from "./Utils";
const DEFAULT_TIMEOUT_IN_MS: number = 30 * 1000;

View File

@ -1,9 +1,9 @@
import { ILogger } from "./ILogger";
import { TransferFormat } from "./ITransport";
// 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.
import { ILogger } from "./ILogger";
import { TransferFormat } from "./ITransport";
export const enum MessageType {
Invocation = 1,
StreamItem = 2,

View File

@ -1,8 +1,6 @@
// 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.
import { IConnection } from "./IConnection";
export enum HttpTransportType {
WebSockets,
ServerSentEvents,

View File

@ -1,7 +1,7 @@
// 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.
import { CloseMessage, CompletionMessage, HubMessage, IHubProtocol, InvocationMessage, MessageType, PingMessage, StreamItemMessage } from "./IHubProtocol";
import { CompletionMessage, HubMessage, IHubProtocol, InvocationMessage, MessageType, StreamItemMessage } from "./IHubProtocol";
import { ILogger, LogLevel } from "./ILogger";
import { TransferFormat } from "./ITransport";
import { NullLogger } from "./Loggers";