Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSify test/Core #7428

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Core/CorsProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class CorsProxy {
* Domains that should be proxied for, as set by config files. Stored as an array of hosts - if a TLD is specified,
* subdomains will also be proxied.
*/
proxyDomains: string[] | undefined = undefined;
proxyDomains: string[] = [];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CorsProxySpec could be used almost without modifications by initializing proxyDomains to the empty array instead of undefined.

Allowing proxyDomains to be undefined means we have to insert a bunch of if (isDefined(corsProxy.proxyDomain)) { } around the content of the tests.


/**
* True if we expect that the proxy will proxy any URL - note that if the server isn't set up to do this, having
Expand Down Expand Up @@ -75,7 +75,7 @@ export default class CorsProxy {
}
this.baseProxyUrl = baseProxyUrl;

if (this.proxyDomains === null || this.proxyDomains === undefined) {
if (this.proxyDomains === null || this.proxyDomains.length === 0) {
this.proxyDomains = proxyDomains;
}
}
Expand Down
37 changes: 5 additions & 32 deletions test/Core/CorsProxySpec.js → test/Core/CorsProxySpec.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
"use strict";

var CorsProxy = require("../../lib/Core/CorsProxy");
import CorsProxy from "../../lib/Core/CorsProxy";

describe("CorsProxy", function () {
var corsProxy, loadDeferred, loadJson;
var originalPageIsHttps, originalAlwaysUseProxy;
let corsProxy: CorsProxy;

beforeEach(function () {
loadDeferred = {};
loadDeferred.promise = new Promise((resolve, reject) => {
loadDeferred.resolve = resolve;
loadDeferred.reject = reject;
});
loadJson = jasmine
.createSpy("loadJson")
.and.returnValue(loadDeferred.promise);
corsProxy = new CorsProxy(loadJson);

originalPageIsHttps = corsProxy.pageIsHttps;
originalAlwaysUseProxy = corsProxy.alwaysUseProxy;
corsProxy.pageIsHttps = false;
corsProxy.alwaysUseProxy = false;
});

afterEach(function () {
corsProxy.pageIsHttps = originalPageIsHttps;
corsProxy.alwaysUseProxy = originalAlwaysUseProxy;
corsProxy.proxyDomains.length = 0;
corsProxy.corsDomains.length = 0;
corsProxy = new CorsProxy();
});

describe("init", function () {
it("should use baseProxyUrl for subsequent proxy calls", function () {
corsProxy.init("", "proxy2/", {});
corsProxy.init("", "proxy2/", []);

expect(corsProxy.getURL("example")).toBe("proxy2/example");
});
Expand Down Expand Up @@ -111,11 +88,7 @@ describe("CorsProxy", function () {

describe("shouldUseProxy", function () {
beforeEach(function () {
corsProxy.init();
});

it("returns false for an undefined input", function () {
expect(corsProxy.shouldUseProxy()).toBe(false);
corsProxy.init(undefined);
});

it("returns false for a relative path", function () {
Expand Down
11 changes: 0 additions & 11 deletions test/Core/sortedIndicesSpec.js

This file was deleted.

9 changes: 9 additions & 0 deletions test/Core/sortedIndicesSpec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import sortedIndices from "../../lib/Core/sortedIndices";

describe("sortedIndices", function () {
it("works", function () {
const data = ["c", "a", "b", "d"];
const indices = sortedIndices(data);
expect(indices).toEqual([1, 2, 0, 3]);
});
});