Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
Adding infrastructure to write node (a.k.a. unit) tests for ts client (
Browse files Browse the repository at this point in the history
  • Loading branch information
moozzyk committed Jan 18, 2017
1 parent 8b6c25a commit ac8a6c9
Show file tree
Hide file tree
Showing 14 changed files with 656 additions and 11 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"test": "test"
},
"scripts": {
"gulp": "gulp"
"gulp": "gulp",
"pretest": "tsc -p test/Microsoft.AspNetCore.Client.SignalR.TS.Tests",
"test": "jasmine JASMINE_CONFIG_PATH=test/Microsoft.AspNetCore.Client.SignalR.TS.Tests/jasmine.json"
},
"repository": {
"type": "git",
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.AspNetCore.SignalR.Client.TS/Common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
declare type DataReceived = (data: any) => void;
declare type ErrorHandler = (e: any) => void;
declare type ConnectionClosed = (e?: any) => void;
export declare type DataReceived = (data: any) => void;
export declare type ErrorHandler = (e: any) => void;
export declare type ConnectionClosed = (e?: any) => void;
1 change: 1 addition & 0 deletions src/Microsoft.AspNetCore.SignalR.Client.TS/Connection.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DataReceived, ConnectionClosed } from "./Common"
import { ITransport, WebSocketTransport, ServerSentEventsTransport, LongPollingTransport } from "./Transports"
import { IHttpClient, HttpClient } from "./HttpClient"
import { ISignalROptions } from "./ISignalROptions"
Expand Down
3 changes: 2 additions & 1 deletion src/Microsoft.AspNetCore.SignalR.Client.TS/HubConnection.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ConnectionClosed } from "./Common"
import { Connection } from "./Connection"

interface InvocationDescriptor {
Expand Down Expand Up @@ -28,7 +29,7 @@ export class HubConnection {
thisHubConnection.dataReceived(data);
};

this.callbacks = new Map<string, (InvocationResultDescriptor) => void>();
this.callbacks = new Map<string, (invocationDescriptor: InvocationResultDescriptor) => void>();
this.methods = new Map<string, (...args: any[]) => void>();
this.id = 0;
}
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.AspNetCore.SignalR.Client.TS/Transports.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DataReceived, ErrorHandler } from "./Common"
import { IHttpClient } from "./HttpClient"

export interface ITransport {
Expand Down
11 changes: 10 additions & 1 deletion src/Microsoft.AspNetCore.SignalR.Client.TS/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
"compilerOptions": {
"module": "umd",
"target": "es6",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"outDir": "../../artifacts/lib/signalr-client-modules"
},
"include": [ "*.ts" ]
"include": [
"./**/*",
"../../typings/*"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {IHttpClient} from "../../src/Microsoft.AspNetCore.SignalR.Client.TS/HttpClient"
import { Connection } from "../../src/Microsoft.AspNetCore.SignalR.Client.TS/Connection"
import { ISignalROptions } from "../../src/Microsoft.AspNetCore.SignalR.Client.TS/ISignalROptions"

describe("Connection", () => {
it("starting connection fails if getting id fails", async (done) => {
let options: ISignalROptions = {
httpClient: <IHttpClient>{
get(url: string): Promise<string> {
if (url.indexOf("/getid") >= 0) {
return Promise.reject("error");
}
return Promise.resolve("");
}
}
} as ISignalROptions;

let connection = new Connection("http://tempuri.org", undefined, options);

try {
await connection.start();
fail();
done();
}
catch (e) {
expect(e).toBe("error");
done();
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"spec_dir": "artifacts/test/Microsoft.AspNetCore.Client.SignalR.TS.Tests",
"spec_files": [
"./**/*[sS]pec.js"
]
}
18 changes: 18 additions & 0 deletions test/Microsoft.AspNetCore.Client.SignalR.TS.Tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compileOnSave": true,
"compilerOptions": {
"module": "umd",
"target": "es6",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"outDir": "../../artifacts/test/Microsoft.AspNetCore.Client.SignalR.TS.Tests/"
},
"include": [
"./**/*",
"../../typings/*"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,3 @@ function eachTransport(action) {
let transportNames = ["webSockets", "serverSentEvents", "longPolling"];
transportNames.forEach(t => action(t));
}

function fail() {
it.expect(true).toBe(false);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare class EventSource extends EventTarget {
readonly CONNECTING: number;
readonly OPEN: number;

close();
close(): void;

onerror: (this: this, ev: ErrorEvent) => any;
onmessage: (this: this, ev: MessageEvent) => any;
Expand Down
Loading

0 comments on commit ac8a6c9

Please sign in to comment.