TypeScript improvements and tslib dep (#2808)

Resolves "Module not found: Can't resolve 'tslib' in '...@aspnet\signalr\dist\esm'"
This commit is contained in:
BrennanConroy 2018-08-28 09:43:12 -07:00 committed by Nate McMaster
parent 46dd1c9291
commit fd53f84f63
29 changed files with 8919 additions and 9203 deletions

13
.vscode/launch.json vendored
View File

@ -1,6 +1,7 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
@ -17,6 +18,18 @@
"address": "localhost",
"port": 5858,
"outFiles": []
},
{
"type": "node",
"request": "launch",
"name": "Jest - Current File",
"program": "${workspaceFolder}/clients/ts/common/node_modules/jest/bin/jest",
"cwd": "${workspaceFolder}/clients/ts",
"args": [
"${relativeFile}"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}

View File

@ -15,7 +15,7 @@
</PropertyGroup>
<Target Name="RestoreNpm" Condition="'$(PreflightRestore)' != 'True'">
<Message Text="Restoring NPM modules" Importance="high" />
<Exec Command="npm install --no-optional" WorkingDirectory="$(RepositoryRoot)clients/ts" />
<Exec Command="npm install --no-optional" WorkingDirectory="$(RepositoryRoot)clients/ts/common" />
<Exec Command="npm install --no-optional" WorkingDirectory="$(RepositoryRoot)clients/ts/FunctionalTests" />
<Exec Command="npm install --no-optional" WorkingDirectory="$(RepositoryRoot)clients/ts/signalr" />
<Exec Command="npm install --no-optional" WorkingDirectory="$(RepositoryRoot)clients/ts/signalr-protocol-msgpack" />

View File

@ -10,6 +10,10 @@
"es6-promise": {
"version": "4.2.2",
"bundled": true
},
"tslib": {
"version": "1.9.3",
"bundled": true
}
}
},
@ -111,6 +115,10 @@
"safe-buffer": "~5.1.0"
}
},
"tslib": {
"version": "1.9.3",
"bundled": true
},
"util-deprecate": {
"version": "1.0.2",
"bundled": true
@ -516,6 +524,12 @@
"strip-json-comments": "^2.0.0"
}
},
"typescript": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.0.1.tgz",
"integrity": "sha512-zQIMOmC+372pC/CCVLqnQ0zSBiY7HHodU7mpQdjiZddek4GMj31I3dUJ7gAs9o65X7mnRma6OokOkc6f9jjfBg==",
"dev": true
},
"v8flags": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/v8flags/-/v8flags-3.0.1.tgz",

View File

@ -17,13 +17,14 @@
"jasmine": "^3.1.0",
"tap-parser": "^7.0.0",
"tee": "^0.2.0",
"ts-node": "^4.1.0"
"ts-node": "^4.1.0",
"typescript": "^3.0.1"
},
"scripts": {
"clean": "node ../node_modules/rimraf/bin.js ./wwwroot/dist ./obj/js",
"clean": "node ../common/node_modules/rimraf/bin.js ./wwwroot/dist ./obj/js",
"build": "npm run clean && npm run build:lint && npm run build:webpack",
"build:lint": "node ../node_modules/tslint/bin/tslint -c ../tslint.json -p ./tsconfig.json",
"build:webpack": "node ../node_modules/webpack-cli/bin/cli.js",
"build:lint": "node ../common/node_modules/tslint/bin/tslint -c ../tslint.json -p ./tsconfig.json",
"build:webpack": "node ../common/node_modules/webpack-cli/bin/cli.js",
"pretest": "npm run build",
"test": "dotnet build && npm run test-only",
"test-only": "ts-node --project ./selenium/tsconfig-selenium.json ./selenium/run-tests.ts",

View File

@ -1,7 +1,10 @@
// 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, IHttpConnectionOptions, LogLevel, TransferFormat } from "@aspnet/signalr";
// This code uses a lot of `.then` instead of `await` and TSLint doesn't like it.
// tslint:disable:no-floating-promises
import { HttpTransportType, IHttpConnectionOptions, TransferFormat } from "@aspnet/signalr";
import { eachTransport, ECHOENDPOINT_URL } from "./Common";
import { TestLogger } from "./TestLogger";
@ -23,15 +26,13 @@ describe("connection", () => {
...commonOptions,
});
let received = "";
connection.onreceive = (data) => {
received += data;
connection.onreceive = async (data: any) => {
if (data === message) {
connection.stop();
}
};
connection.onclose = (error) => {
connection.onclose = (error: any) => {
expect(error).toBeUndefined();
done();
};
@ -55,22 +56,20 @@ describe("connection", () => {
transport: transportType,
});
let received = "";
connection.onreceive = (data) => {
received += data;
connection.onreceive = (data: any) => {
if (data === message) {
connection.stop();
}
};
connection.onclose = (error) => {
connection.onclose = (error: any) => {
expect(error).toBeUndefined();
done();
};
connection.start(TransferFormat.Text).then(() => {
connection.send(message);
}).catch((e) => {
}).catch((e: any) => {
fail(e);
done();
});
@ -85,15 +84,17 @@ describe("connection", () => {
transport: transportType,
});
connection.onreceive = (data) => {
connection.onreceive = (data: any) => {
if (data === message) {
connection.stop();
}
};
// @ts-ignore: We don't use the error parameter intentionally.
connection.onclose = (error) => {
// Search the logs for the message content
expect(TestLogger.instance.currentLog.messages.length).toBeGreaterThan(0);
// @ts-ignore: We don't use the _ or __ parameters intentionally.
for (const [_, __, logMessage] of TestLogger.instance.currentLog.messages) {
expect(logMessage).not.toContain(message);
}
@ -118,16 +119,18 @@ describe("connection", () => {
transport: transportType,
});
connection.onreceive = (data) => {
connection.onreceive = (data: any) => {
if (data === message) {
connection.stop();
}
};
// @ts-ignore: We don't use the error parameter intentionally.
connection.onclose = (error) => {
// Search the logs for the message content
let matches = 0;
expect(TestLogger.instance.currentLog.messages.length).toBeGreaterThan(0);
// @ts-ignore: We don't use the _ or __ parameters intentionally.
for (const [_, __, logMessage] of TestLogger.instance.currentLog.messages) {
if (logMessage.indexOf(message) !== -1) {
matches += 1;
@ -141,7 +144,7 @@ describe("connection", () => {
connection.start(TransferFormat.Text).then(() => {
connection.send(message);
}).catch((e) => {
}).catch((e: any) => {
fail(e);
done();
});

View File

@ -1,7 +1,10 @@
// 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 { DefaultHttpClient, HttpClient, HttpRequest, HttpResponse, HttpTransportType, HubConnection, HubConnectionBuilder, IHttpConnectionOptions, IStreamSubscriber, JsonHubProtocol, LogLevel } from "@aspnet/signalr";
// This code uses a lot of `.then` instead of `await` and TSLint doesn't like it.
// tslint:disable:no-floating-promises
import { DefaultHttpClient, HttpClient, HttpRequest, HttpResponse, HttpTransportType, HubConnectionBuilder, IHttpConnectionOptions, JsonHubProtocol } from "@aspnet/signalr";
import { MessagePackHubProtocol } from "@aspnet/signalr-protocol-msgpack";
import { eachTransport, eachTransportAndProtocol } from "./Common";
@ -221,7 +224,7 @@ describe("hubConnection", () => {
hubConnection.stop();
done();
},
next(item) {
next() {
hubConnection.stop();
fail();
},
@ -248,7 +251,7 @@ describe("hubConnection", () => {
hubConnection.stop();
done();
},
next(item) {
next() {
hubConnection.stop();
fail();
},

View File

@ -39,6 +39,7 @@ class WebDriverReporter implements jasmine.CustomReporter {
this.taplog(`1..${suiteInfo.totalSpecsDefined}`);
}
// @ts-ignore: We don't use the result parameter
public specStarted(result: jasmine.CustomReporterResult): void {
this.concurrentSpecCount += 1;
if (this.concurrentSpecCount > 1) {
@ -90,6 +91,7 @@ class WebDriverReporter implements jasmine.CustomReporter {
this.specCounter += 1;
}
// @ts-ignore: We don't use the result parameter
public jasmineDone(runDetails: jasmine.RunDetails): void {
this.element.setAttribute("data-done", "1");
}

View File

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
const path = require("path");
const webpack = require("webpack");
const webpack = require("../common/node_modules/webpack");
module.exports = {
entry: path.resolve(__dirname, "ts", "index.ts"),
@ -24,6 +24,10 @@ module.exports = {
}
]
},
resolveLoader: {
// Special resolution rules for loaders (which are in the 'common' directory)
modules: [ path.resolve(__dirname, "..", "common", "node_modules") ],
},
resolve: {
extensions: [".ts", ".js"]
},

8723
clients/ts/common/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,26 @@
{
"name": "common",
"version": "1.0.0",
"description": "Common dependencies used during dev time. DO NOT PUBLISH",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/jest": "^22.2.3",
"@types/node": "^8.5.2",
"@types/webpack": "^4.4.0",
"jest": "^22.4.3",
"rimraf": "^2.6.2",
"ts-jest": "^22.4.6",
"ts-loader": "^4.4.1",
"tslint": "^5.9.1",
"typescript": "^2.7.1",
"uglify-js": "^3.3.5",
"webpack": "^4.12.0",
"webpack-cli": "^3.0.3"
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,28 +1,16 @@
{
"name": "client-ts",
"version": "0.0.0",
"description": "Common dev-time dependencies for SignalR NPM packages. NOT FOR PUBLISHING",
"main": "index.js",
"description": "Provides a root to run npm scripts from. DO NOT PUBLISH",
"private": true,
"scripts": {
"build": "cd ./signalr && npm run build && cd ../signalr-protocol-msgpack && npm run build",
"test": "jest"
"pretest": "node ./common/node_modules/tslint/bin/tslint -c ./tslint.json -p ./signalr/tests/tsconfig.json && node ./common/node_modules/tslint/bin/tslint -c ./tslint.json -p ./signalr-protocol-msgpack/tests/tsconfig.json",
"test": "node ./common/node_modules/jest/bin/jest.js",
"coverage": "node ./common/node_modules/jest/bin/jest.js --coverage"
},
"author": "Microsoft",
"license": "Apache-2.0",
"devDependencies": {
"@types/jest": "^22.2.3",
"@types/node": "^8.5.2",
"@types/webpack": "^4.4.0",
"jest": "^22.4.3",
"rimraf": "^2.6.2",
"ts-jest": "^22.4.4",
"ts-loader": "^4.4.1",
"tslint": "^5.9.1",
"typescript": "^2.7.1",
"uglify-js": "^3.3.5",
"webpack": "^4.16.1",
"webpack-cli": "^3.0.3"
},
"jest": {
"globals": {
"ts-jest": {
@ -32,12 +20,13 @@
}
},
"transform": {
"^.+\\.tsx?$": "ts-jest"
"^.+\\.tsx?$": "./common/node_modules/ts-jest"
},
"testEnvironment": "node",
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleNameMapper": {
"^@aspnet/signalr$": "<rootDir>/signalr/src/index.ts"
"^ts-jest$": "<rootDir>/common/node_modules/ts-jest",
"^@aspnet/signalr$": "<rootDir>/signalr/dist/cjs/index.js"
},
"moduleFileExtensions": [
"ts",

View File

@ -1,43 +0,0 @@
// 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 path from 'path';
import resolve from 'rollup-plugin-node-resolve'
import sourceMaps from 'rollup-plugin-sourcemaps'
import commonjs from 'rollup-plugin-commonjs'
let polyfills = [ 'es6-promise', 'buffer', 'base64-js', 'ieee754' ];
let allowed_externals = [ ];
export default function(rootDir, moduleGlobals) {
let pkg = require(path.join(rootDir, "package.json"));
return {
input: path.join(rootDir, "dist", "cjs", "browser-index.js"),
output: {
file: pkg.umd,
format: "umd",
name: pkg.umd_name,
sourcemap: true,
banner: "/** \r\n" +
" * @overview ASP.NET Core SignalR JavaScript Client.\r\n" +
" * @version 0.0.0-DEV_BUILD.\r\n" +
" * @license\r\n" +
" * Copyright (c) .NET Foundation. All rights reserved.\r\n" +
" * Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.\r\n" +
" */",
globals: moduleGlobals,
},
// Mark everything in the dependencies list as external
external: Object.keys(pkg.dependencies || {}),
plugins: [
commonjs(),
resolve({
preferBuiltins: false
}),
sourceMaps()
]
}
}

View File

@ -11,13 +11,13 @@
"test": "spec"
},
"scripts": {
"clean": "node ../node_modules/rimraf/bin.js ./dist",
"clean": "node ../common/node_modules/rimraf/bin.js ./dist",
"build": "npm run clean && npm run build:lint && npm run build:esm && npm run build:cjs && npm run build:browser && npm run build:uglify",
"build:lint": "node ../node_modules/tslint/bin/tslint -c ../tslint.json -p ./tsconfig.json",
"build:esm": "node ../node_modules/typescript/bin/tsc --project ./tsconfig.json --module es2015 --outDir ./dist/esm -d",
"build:cjs": "node ../node_modules/typescript/bin/tsc --project ./tsconfig.json --module commonjs --outDir ./dist/cjs",
"build:browser": "node ../node_modules/webpack-cli/bin/cli.js",
"build:uglify": "node ../node_modules/uglify-js/bin/uglifyjs --source-map \"url='signalr-protocol-msgpack.min.js.map',content='./dist/browser/signalr-protocol-msgpack.js.map'\" --comments -o ./dist/browser/signalr-protocol-msgpack.min.js ./dist/browser/signalr-protocol-msgpack.js",
"build:lint": "node ../common/node_modules/tslint/bin/tslint -c ../tslint.json -p ./tsconfig.json",
"build:esm": "node ../common/node_modules/typescript/bin/tsc --project ./tsconfig.json --module es2015 --outDir ./dist/esm -d",
"build:cjs": "node ../common/node_modules/typescript/bin/tsc --project ./tsconfig.json --module commonjs --outDir ./dist/cjs",
"build:browser": "node ../common/node_modules/webpack-cli/bin/cli.js",
"build:uglify": "node ../common/node_modules/uglify-js/bin/uglifyjs --source-map \"url='signalr-protocol-msgpack.min.js.map',content='./dist/browser/signalr-protocol-msgpack.js.map'\" --comments -o ./dist/browser/signalr-protocol-msgpack.min.js ./dist/browser/signalr-protocol-msgpack.js",
"prepack": "node ../build/embed-version.js",
"test": "echo \"Run 'npm test' in the 'clients\\ts' folder to test this package\" && exit 1"
},

View File

@ -3,6 +3,7 @@
const path = require("path");
const baseConfig = require("../webpack.config.base");
module.exports = baseConfig(__dirname, "signalr-protocol-msgpack", {
externals: {
msgpack5: "msgpack5",

View File

@ -11,13 +11,13 @@
"test": "spec"
},
"scripts": {
"clean": "node ../node_modules/rimraf/bin.js ./dist",
"clean": "node ../common/node_modules/rimraf/bin.js ./dist",
"build": "npm run clean && npm run build:lint && npm run build:esm && npm run build:cjs && npm run build:browser && npm run build:uglify",
"build:lint": "node ../node_modules/tslint/bin/tslint -c ../tslint.json -p ./tsconfig.json",
"build:esm": "node ../node_modules/typescript/bin/tsc --project ./tsconfig.json --module es2015 --outDir ./dist/esm -d && node ./build/process-dts.js",
"build:cjs": "node ../node_modules/typescript/bin/tsc --project ./tsconfig.json --module commonjs --outDir ./dist/cjs",
"build:browser": "node ../node_modules/webpack-cli/bin/cli.js",
"build:uglify": "node ../node_modules/uglify-js/bin/uglifyjs --source-map \"url='signalr.min.js.map',content='./dist/browser/signalr.js.map'\" --comments -o ./dist/browser/signalr.min.js ./dist/browser/signalr.js",
"build:lint": "node ../common/node_modules/tslint/bin/tslint -c ../tslint.json -p ./tsconfig.json",
"build:esm": "node ../common/node_modules/typescript/bin/tsc --project ./tsconfig.json --module es2015 --outDir ./dist/esm -d && node ./build/process-dts.js",
"build:cjs": "node ../common/node_modules/typescript/bin/tsc --project ./tsconfig.json --module commonjs --outDir ./dist/cjs",
"build:browser": "node ../common/node_modules/webpack-cli/bin/cli.js",
"build:uglify": "node ../common/node_modules/uglify-js/bin/uglifyjs --source-map \"url='signalr.min.js.map',content='./dist/browser/signalr.js.map'\" --comments -o ./dist/browser/signalr.min.js ./dist/browser/signalr.js",
"prepack": "node ../build/embed-version.js",
"test": "echo \"Run 'npm test' in the 'clients\\ts' folder to test this package\" && exit 1"
},

View File

@ -3,6 +3,7 @@
/** Error thrown when an HTTP request fails. */
export class HttpError extends Error {
// @ts-ignore: Intentionally unused.
// tslint:disable-next-line:variable-name
private __proto__: Error;
@ -27,6 +28,7 @@ export class HttpError extends Error {
/** Error thrown when a timeout elapses. */
export class TimeoutError extends Error {
// @ts-ignore: Intentionally unused.
// tslint:disable-next-line:variable-name
private __proto__: Error;

View File

@ -311,6 +311,9 @@ export class HubConnection {
break;
case MessageType.Close:
this.logger.log(LogLevel.Information, "Close message received from server.");
// We don't want to wait on the stop itself.
// tslint:disable-next-line:no-floating-promises
this.connection.stop(message.error ? new Error("Server returned an error on close: " + message.error) : null);
break;
default:
@ -334,12 +337,18 @@ export class HubConnection {
this.logger.log(LogLevel.Error, message);
const error = new Error(message);
// We don't want to wait on the stop itself.
// tslint:disable-next-line:no-floating-promises
this.connection.stop(error);
throw error;
}
if (responseMessage.error) {
const message = "Server returned handshake error: " + responseMessage.error;
this.logger.log(LogLevel.Error, message);
// We don't want to wait on the stop itself.
// tslint:disable-next-line:no-floating-promises
this.connection.stop(new Error(message));
} else {
this.logger.log(LogLevel.Debug, "Server handshake complete.");
@ -357,7 +366,8 @@ export class HubConnection {
private serverTimeout() {
// The server hasn't talked to us in a while. It doesn't like us anymore ... :(
// Terminate the connection
// Terminate the connection, but we don't need to wait on the promise.
// tslint:disable-next-line:no-floating-promises
this.connection.stop(new Error("Server timeout elapsed without receiving a message from the server."));
}
@ -369,6 +379,9 @@ export class HubConnection {
// This is not supported in v1. So we return an error to avoid blocking the server waiting for the response.
const message = "Server requested a response, which is not supported in this version of the client.";
this.logger.log(LogLevel.Error, message);
// We don't need to wait on this Promise.
// tslint:disable-next-line:no-floating-promises
this.connection.stop(new Error(message));
}
} else {

View File

@ -11,6 +11,7 @@ export class NullLogger implements ILogger {
private constructor() {}
/** @inheritDoc */
public log(logLevel: LogLevel, message: string): void {
// tslint:disable-next-line
public log(_logLevel: LogLevel, _message: string): void {
}
}

View File

@ -19,7 +19,6 @@ export class LongPollingTransport implements ITransport {
private readonly logMessageContent: boolean;
private url: string;
private pollXhr: XMLHttpRequest;
private pollAbort: AbortController;
private shutdownTimer: any; // We use 'any' because this is an object in NodeJS. But it still gets passed to clearTimeout, so it doesn't really matter
private shutdownTimeout: number;
@ -84,6 +83,7 @@ export class LongPollingTransport implements ITransport {
this.running = true;
}
// tslint:disable-next-line:no-floating-promises
this.poll(this.url, pollOptions, closeError);
return Promise.resolve();
}
@ -188,7 +188,7 @@ export class LongPollingTransport implements ITransport {
};
const token = await this.accessTokenFactory();
this.updateHeaderToken(deleteOptions, token);
const response = await this.httpClient.delete(this.url, deleteOptions);
await this.httpClient.delete(this.url, deleteOptions);
this.logger.log(LogLevel.Trace, "(LongPolling transport) DELETE request accepted.");
} finally {

View File

@ -45,6 +45,7 @@ export interface IStreamResult<T> {
*
* @typeparam T The type of the items being sent by the server.
*/
// @ts-ignore: We can't remove this, it's a breaking change, but it's not used.
export interface ISubscription<T> {
/** Disconnects the {@link @aspnet/signalr.IStreamSubscriber} associated with this subscription from the stream. */
dispose(): void;

View File

@ -41,7 +41,8 @@ export class WebSocketTransport implements ITransport {
webSocket.binaryType = "arraybuffer";
}
webSocket.onopen = (event: Event) => {
// tslint:disable-next-line:variable-name
webSocket.onopen = (_event: Event) => {
this.logger.log(LogLevel.Information, `WebSocket connected to ${url}`);
this.webSocket = webSocket;
resolve();

View File

@ -7,7 +7,6 @@ import { IHttpConnectionOptions } from "../src/IHttpConnectionOptions";
import { HttpTransportType, ITransport, TransferFormat } from "../src/ITransport";
import { HttpError } from "../src/Errors";
import { LogLevel } from "../src/ILogger";
import { eachEndpointUrl, eachTransport } from "./Common";
import { TestHttpClient } from "./TestHttpClient";
import { PromiseSource } from "./Utils";
@ -117,11 +116,13 @@ describe("HttpConnection", () => {
const options: IHttpConnectionOptions = {
...commonOptions,
httpClient: new TestHttpClient()
.on("POST", (r) => {
.on("POST", async () => {
// tslint:disable-next-line:no-floating-promises
connection.stop();
return "{}";
})
.on("GET", (r) => {
.on("GET", async () => {
// tslint:disable-next-line:no-floating-promises
connection.stop();
return "";
}),
@ -267,7 +268,7 @@ describe("HttpConnection", () => {
});
}
it(`cannot be started if server's only transport (${HttpTransportType[requestedTransport]}) is masked out by the transport option`, async() => {
it(`cannot be started if server's only transport (${HttpTransportType[requestedTransport]}) is masked out by the transport option`, async () => {
const negotiateResponse = {
availableTransports: [
{ transport: "WebSockets", transferFormats: [ "Text", "Binary" ] },

View File

@ -57,7 +57,7 @@ describe("HubConnection", () => {
});
} finally {
// Close the connection
hubConnection.stop();
await hubConnection.stop();
}
});
});
@ -85,7 +85,7 @@ describe("HubConnection", () => {
} finally {
// Close the connection
hubConnection.stop();
await hubConnection.stop();
}
});
@ -107,7 +107,7 @@ describe("HubConnection", () => {
// message only contained handshake response
expect(protocolCalled).toEqual(false);
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -130,7 +130,7 @@ describe("HubConnection", () => {
// message only contained handshake response
expect(protocolCalled).toEqual(false);
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -158,7 +158,7 @@ describe("HubConnection", () => {
// left over data is the message pack message
expect(receivedProcotolData.byteLength).toEqual(102);
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -177,7 +177,7 @@ describe("HubConnection", () => {
expect(receivedProcotolData).toEqual("{\"type\":6}" + TextMessageFormat.RecordSeparator);
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -193,7 +193,7 @@ describe("HubConnection", () => {
await expect(invokePromise).rejects.toThrow("foo");
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -209,7 +209,7 @@ describe("HubConnection", () => {
expect(await invokePromise).toBe("foo");
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -221,7 +221,7 @@ describe("HubConnection", () => {
connection.receiveHandshakeResponse();
const invokePromise = hubConnection.invoke("testMethod");
hubConnection.stop();
await hubConnection.stop();
expect(invokePromise).rejects.toThrow("Invocation canceled due to connection being closed.");
});
@ -239,7 +239,7 @@ describe("HubConnection", () => {
expect(invokePromise).rejects.toThrow("Connection lost");
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
});
@ -268,7 +268,7 @@ describe("HubConnection", () => {
expect(warnings).toEqual(["No client method with the name 'message' found."]);
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -300,7 +300,7 @@ describe("HubConnection", () => {
expect(warnings).toEqual(["No client method with the name 'message' found."]);
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -336,7 +336,7 @@ describe("HubConnection", () => {
expect(count).toBe(2);
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -372,7 +372,7 @@ describe("HubConnection", () => {
expect(count).toBe(3);
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -397,7 +397,7 @@ describe("HubConnection", () => {
expect(count).toBe(1);
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -420,7 +420,7 @@ describe("HubConnection", () => {
expect(value).toBe("test");
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -435,7 +435,7 @@ describe("HubConnection", () => {
expect(closeError.message).toEqual("Server returned handshake error: Error!");
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -459,7 +459,7 @@ describe("HubConnection", () => {
expect(isClosed).toEqual(true);
expect(closeError).toEqual(null);
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -484,7 +484,7 @@ describe("HubConnection", () => {
expect(isClosed).toEqual(true);
expect(closeError.message).toEqual("Server returned an error on close: Error!");
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -510,7 +510,7 @@ describe("HubConnection", () => {
expect(numInvocations1).toBe(1);
expect(numInvocations2).toBe(1);
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -544,7 +544,7 @@ describe("HubConnection", () => {
expect(numInvocations).toBe(1);
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -556,7 +556,7 @@ describe("HubConnection", () => {
hubConnection.on("message", (t) => { });
hubConnection.on("message", () => { });
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -601,7 +601,7 @@ describe("HubConnection", () => {
hubConnection.off(null, () => { });
hubConnection.off(undefined, () => { });
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
});
@ -627,9 +627,9 @@ describe("HubConnection", () => {
});
// Close the connection
hubConnection.stop();
await hubConnection.stop();
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -647,7 +647,7 @@ describe("HubConnection", () => {
expect(observer.completed).rejects.toThrow("Error: foo");
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -665,7 +665,7 @@ describe("HubConnection", () => {
expect(await observer.completed).toEqual([]);
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -677,11 +677,11 @@ describe("HubConnection", () => {
const observer = new TestObserver();
hubConnection.stream<any>("testMethod")
.subscribe(observer);
hubConnection.stop();
await hubConnection.stop();
expect(observer.completed).rejects.toThrow("Error: Invocation canceled due to connection being closed.");
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -699,7 +699,7 @@ describe("HubConnection", () => {
expect(observer.completed).rejects.toThrow("Error: Connection lost");
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -725,7 +725,7 @@ describe("HubConnection", () => {
connection.receive({ type: MessageType.Completion, invocationId: connection.lastInvocationId });
expect(await observer.completed).toEqual([1, 2, 3]);
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -740,7 +740,7 @@ describe("HubConnection", () => {
// triggers observer.error()
connection.onclose(new Error("Connection lost"));
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -755,11 +755,11 @@ describe("HubConnection", () => {
// Expectation is connection.receive will not to throw
connection.receive({ type: MessageType.Completion, invocationId: connection.lastInvocationId });
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
it("can be canceled", () => {
it("can be canceled", async () => {
const connection = new TestConnection();
const hubConnection = createHubConnection(connection);
try {
@ -785,7 +785,7 @@ describe("HubConnection", () => {
type: MessageType.CancelInvocation,
});
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
});
@ -802,7 +802,7 @@ describe("HubConnection", () => {
connection.onclose();
expect(invocations).toBe(2);
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -817,7 +817,7 @@ describe("HubConnection", () => {
connection.onclose(new Error("Test error."));
expect(error.message).toBe("Test error.");
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -831,7 +831,7 @@ describe("HubConnection", () => {
connection.onclose();
// expect no errors
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
});
@ -850,7 +850,7 @@ describe("HubConnection", () => {
expect(await invokePromise).toBe("foo");
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -874,13 +874,13 @@ describe("HubConnection", () => {
await connection.receive({ type: MessageType.Ping });
await delay(50);
connection.stop();
await connection.stop();
const error = await p.promise;
expect(error).toBeUndefined();
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -906,13 +906,13 @@ describe("HubConnection", () => {
await connection.receive({ type: MessageType.Ping });
await delay(50);
connection.stop();
await connection.stop();
const error = await p.promise;
expect(error).toBeUndefined();
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
@ -931,7 +931,7 @@ describe("HubConnection", () => {
expect(error).toEqual(new Error("Server timeout elapsed without receiving a message from the server."));
} finally {
hubConnection.stop();
await hubConnection.stop();
}
});
});

View File

@ -5,12 +5,13 @@
"target": "es5",
"sourceMap": true,
"moduleResolution": "node",
"importHelpers": true,
"inlineSources": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"suppressImplicitAnyIndexErrors": true,
"noEmitOnError": true,
"stripInternal": true,

View File

@ -1,7 +1,12 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "commonjs"
"module": "commonjs",
"noUnusedLocals": false,
"noUnusedParameters": false,
"typeRoots": [
"./common/node_modules/@types"
]
},
"include": [
"./*/tests/**/*"

View File

@ -6,6 +6,7 @@
"interface-name": false,
"unified-signatures": false,
"max-classes-per-file": false,
"no-floating-promises": true,
"no-empty": false,
"no-bitwise": false,
"no-console": false

View File

@ -1,103 +0,0 @@
<html>
<head>
<title>Test Page</title>
<style>
.test-success {
color: green;
}
.test-failed {
color: red;
}
</style>
</head>
<body>
<h1>Test Page</h1>
<p>This page validates that the UMD builds of the signalr-client and signalr-protocol-msgpack modules are available in the global scope when in a browser.</p>
<h2>Test Results</h2>
<ul id="results-list">
</ul>
<script src="./signalr-protocol-msgpack/node_modules/msgpack5/dist/msgpack5.js"></script>
<script type="text/javascript">
function getParameterByName(name, url) {
if (!url) {
url = window.location.href;
}
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
function importSignalR() {
var minified = getParameterByName('min') === 'true' ? '.min' : '';
document.write('<script type="text/javascript" src="./signalr/dist/browser/signalr' + minified + '.js"><\/script>');
document.write('<script type="text/javascript" src="./signalr-protocol-msgpack/dist/browser/signalr-protocol-msgpack' + minified + '.js"><\/script>');
}
var resultsList = document.getElementById("results-list");
// Run tests
function test(name, impl) {
var result = ""
var success = false;
try {
impl();
result = "success";
success = true;
} catch(e) {
console.error(e);
result = "error: " + e;
success = false;
}
var cssClass = success ? "test-success": "test-failed";
resultsList.innerHTML += "<li class=\"" + cssClass + "\">" + name + ": " + result + "</li>";
}
test("Promise may not be available before the polyfill", function() {
if(!Promise) {
throw "Promise is falsey: " + Promise;
}
});
test("Buffer is not available before the polyfill", function() {
if(typeof Buffer !== "undefined") {
throw "Buffer is truthy: " + Buffer;
}
});
importSignalR();
</script>
<script>
test("Promise is available after the polyfill", function() {
if(!Promise) {
throw "Promise is falsey: " + Promise;
}
});
test("Buffer is not available after the polyfill", function() {
if(typeof Buffer !== "undefined") {
throw "Buffer is truthy: " + Buffer;
}
});
test("signalR is available", function() {
if(!window.signalR){
throw "window.signalR is falsey: " + window.signalR;
}
});
test("msgpack5 is available", function() {
if(!window.msgpack5){
throw "window.msgpack5 is falsey: " + window.msgpack5;
}
});
test("signalR.protocols.msgpack.MessagePackHubProtocol is available", function() {
if(!window.signalR.protocols.msgpack.MessagePackHubProtocol){
throw "signalR.protocols.msgpack is falsey: " + signalR.protocols.msgpack.MessagePackHubProtocol;
}
});
</script>
</body>
</html>

View File

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
const path = require("path");
const webpack = require("webpack");
const webpack = require("./common/node_modules/webpack");
module.exports = function (modulePath, browserBaseName, options) {
const pkg = require(path.resolve(modulePath, "package.json"));
@ -17,6 +17,10 @@ module.exports = function (modulePath, browserBaseName, options) {
process: false,
Buffer: false,
},
resolveLoader: {
// Special resolution rules for loaders (which are in the 'common' directory)
modules: [ path.resolve(__dirname, "common", "node_modules") ],
},
module: {
rules: [
{