Skip to content

Commit 00a3439

Browse files
[release/6.0-rc1] Fix SignalR TS unit tests not running on CI (#35464)
* Fix SignalR TS unit tests not running on CI * fix * fix Co-authored-by: BrennanConroy <[email protected]>
1 parent a14541e commit 00a3439

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

src/SignalR/clients/ts/client-ts.npmproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<Project>
22
<PropertyGroup>
3-
<IsTestProject>true</IsTestProject>
3+
<TestDependsOnAspNetRuntime>false</TestDependsOnAspNetRuntime>
4+
<TestDependsOnAspNetPackages>false</TestDependsOnAspNetPackages>
45
</PropertyGroup>
56

67
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Directory.Build.props))\Directory.Build.props" />
78

89
<PropertyGroup>
10+
<!-- Keep this property after importing Directory.Build.props, it works around arcade assuming test projects have "Test" in the name -->
11+
<IsTestProject>true</IsTestProject>
912
<IsPackable>false</IsPackable>
1013
<IsBuildable>false</IsBuildable>
1114
<!-- Npm tests don't run on Helix currently, so we need to set this to false to still run the tests on non-Helix -->

src/SignalR/clients/ts/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
},
1212
reporters: [
1313
"default",
14-
["./common/node_modules/jest-junit/index.js", { "output": "../../../../artifacts/log/" + `${process.platform}` + ".signalr.junit.xml" }]
14+
["./common/node_modules/jest-junit/index.js", { "outputDirectory": "../../../../artifacts/log/", "outputName": `${process.platform}` + ".signalr.junit.xml" }]
1515
],
1616
transform: {
1717
"^.+\\.tsx?$": "./common/node_modules/ts-jest"

src/SignalR/clients/ts/signalr/src/FetchHttpClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { CookieJar } from "@types/tough-cookie";
77
import { AbortError, HttpError, TimeoutError } from "./Errors";
88
import { HttpClient, HttpRequest, HttpResponse } from "./HttpClient";
99
import { ILogger, LogLevel } from "./ILogger";
10-
import { Platform } from "./Utils";
10+
import { Platform, getGlobalThis } from "./Utils";
1111

1212
export class FetchHttpClient extends HttpClient {
1313
private readonly _abortControllerType: { prototype: AbortController, new(): AbortController };
@@ -33,7 +33,7 @@ export class FetchHttpClient extends HttpClient {
3333
// fetch-cookie will wrap a fetch implementation with a default CookieJar or a provided one
3434
this._fetchType = requireFunc("fetch-cookie")(this._fetchType, this._jar);
3535
} else {
36-
this._fetchType = fetch.bind(globalThis);
36+
this._fetchType = fetch.bind(getGlobalThis());
3737
}
3838
if (typeof AbortController === "undefined") {
3939
// In order to ignore the dynamic require in webpack builds we need to do this magic

src/SignalR/clients/ts/signalr/src/Utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,21 @@ export function getErrorString(e: any): string {
277277
}
278278
return `${e}`;
279279
}
280+
281+
/** @private */
282+
export function getGlobalThis() {
283+
// globalThis is semi-new and not available in Node until v12
284+
if (typeof globalThis !== "undefined") {
285+
return globalThis;
286+
}
287+
if (typeof self !== "undefined") {
288+
return self;
289+
}
290+
if (typeof window !== "undefined") {
291+
return window;
292+
}
293+
if (typeof global !== "undefined") {
294+
return global;
295+
}
296+
throw new Error("could not find global");
297+
}

src/SignalR/clients/ts/signalr/tests/HttpConnection.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ describe("HttpConnection", () => {
230230
const connection = new HttpConnection("http://tempuri.org", options);
231231
await expect(connection.start(TransferFormat.Text))
232232
.rejects
233-
.toThrow("Unable to connect to the server with any of the available transports. WebSockets failed: Error: WebSocket failed to connect. " +
233+
.toThrow("Unable to connect to the server with any of the available transports. Error: WebSockets failed: Error: WebSocket failed to connect. " +
234234
"The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, " +
235235
"or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled. ServerSentEvents failed: Error: 'ServerSentEvents' is disabled by the client. LongPolling failed: Error: 'LongPolling' is disabled by the client.");
236236

@@ -239,7 +239,7 @@ describe("HttpConnection", () => {
239239
/* eslint-disable max-len */
240240
"Failed to start the transport 'WebSockets': Error: WebSocket failed to connect. The connection could not be found on the server, " +
241241
"either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.",
242-
"Failed to start the connection: Error: Unable to connect to the server with any of the available transports. WebSockets failed: " +
242+
"Failed to start the connection: Error: Unable to connect to the server with any of the available transports. Error: WebSockets failed: " +
243243
"Error: WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled. ServerSentEvents failed: Error: 'ServerSentEvents' is disabled by the client. LongPolling failed: Error: 'LongPolling' is disabled by the client.");
244244
/* eslint-enable max-len */
245245
});
@@ -266,13 +266,14 @@ describe("HttpConnection", () => {
266266
const connection = new HttpConnection("http://tempuri.org", options);
267267
await expect(connection.start(TransferFormat.Text))
268268
.rejects
269-
.toThrow("Unable to connect to the server with any of the available transports. WebSockets failed: Error: Don't allow Websockets. ServerSentEvents failed: Error: Don't allow ServerSentEvents. LongPolling failed: Error: 'LongPolling' is disabled by the client.");
269+
.toThrow("Unable to connect to the server with any of the available transports. Error: WebSockets failed: Error: Don't allow Websockets. Error: ServerSentEvents failed: Error: Don't allow ServerSentEvents. LongPolling failed: Error: 'LongPolling' is disabled by the client.");
270270

271271
expect(negotiateCount).toEqual(2);
272272
},
273273
"Failed to start the transport 'WebSockets': Error: Don't allow Websockets.",
274274
"Failed to start the transport 'ServerSentEvents': Error: Don't allow ServerSentEvents.",
275-
"Failed to start the connection: Error: Unable to connect to the server with any of the available transports. WebSockets failed: Error: Don't allow Websockets. ServerSentEvents failed: Error: Don't allow ServerSentEvents. LongPolling failed: Error: 'LongPolling' is disabled by the client.");
275+
"Failed to start the connection: Error: Unable to connect to the server with any of the available transports. Error: WebSockets failed: Error: Don't allow Websockets. " +
276+
"Error: ServerSentEvents failed: Error: Don't allow ServerSentEvents. LongPolling failed: Error: 'LongPolling' is disabled by the client.");
276277
});
277278

278279
it("failed re-negotiate fails start", async () => {
@@ -1331,12 +1332,12 @@ describe("HttpConnection", () => {
13311332

13321333
await expect(connection.start(TransferFormat.Text))
13331334
.rejects
1334-
.toEqual(new Error("Unable to connect to the server with any of the available transports. ServerSentEvents failed: Error: EventSource constructor called."));
1335+
.toEqual(new Error("Unable to connect to the server with any of the available transports. Error: ServerSentEvents failed: Error: EventSource constructor called."));
13351336

13361337
expect(eventSourceConstructorCalled).toEqual(true);
13371338
},
13381339
"Failed to start the transport 'ServerSentEvents': Error: EventSource constructor called.",
1339-
"Failed to start the connection: Error: Unable to connect to the server with any of the available transports. ServerSentEvents failed: Error: EventSource constructor called.");
1340+
"Failed to start the connection: Error: Unable to connect to the server with any of the available transports. Error: ServerSentEvents failed: Error: EventSource constructor called.");
13401341
});
13411342

13421343
it("uses WebSocket constructor from options if provided", async () => {

0 commit comments

Comments
 (0)