Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("reference counter", function () {
function echoEvent() {
// logger.debug(args);
}
const et = new Observable("aaa", "bbb", "zzz");
expect(et.hasObserver()).is.false;
et.addObserver("aaa", echoEvent);
expect(et.hasObserver()).is.true;
expect(et.hasObserver("aaa")).is.true;
expect(et.hasObserver("bbb")).is.false;
et.addObserver("bbb", echoEvent);
const h = et.addObserver("bbb", echoEvent);
expect(et.hasObserver()).is.true;
expect(et.hasObserver("aaa")).is.true;
expect(et.hasObserver("bbb")).is.true;
et.removeObserver("aaa", echoEvent);
expect(et.hasObserver()).is.true;
expect(et.hasObserver("aaa")).is.false;
expect(et.hasObserver("bbb")).is.true;
h.release();
expect(et.hasObserver()).is.false;
import { event as d3Event } from "@hpcc-js/common";
import { Connection, Result } from "@hpcc-js/comms";
import { Dashboard, Dashy, Databomb, ElementContainer, Form, FormField, LogicalFile, RoxieResult, RoxieService, WU, WUResult } from "@hpcc-js/marshaller";
import { Comms } from "@hpcc-js/other";
import { exists, scopedLogger } from "@hpcc-js/util";
import { sample } from "./sample";
const logger = scopedLogger("index.ts");
/* Test race condition ---
import { hookSend, IOptions, ResponseType, SendFunc } from "@hpcc-js/comms";
let delay = 0;
const origSend: SendFunc = hookSend(function mySend(opts: IOptions, action: string, request: any, responseType: ResponseType) {
return new Promise((resolve, reject) => {
origSend(opts, action, request, responseType).then(response => {
delay += 1000;
if (delay > 5000) delay = 0;
setTimeout(() => {
resolve(response);
}, delay);
});
});
});
*/
syncWidgets() {
const prevWidgets = this.widgets();
const diffWidgets = compare(prevWidgets, this._ec.elements().filter(e => e.visualization().visibility() === "normal").map(viz => viz.visualization().chartPanel()));
let refit = false;
for (const w of diffWidgets.removed) {
this.removeWidget(w);
}
for (const w of diffWidgets.added) {
const element: Element = this._ec.element(w);
this.addWidget(w, this.tabTitle(element), "split-bottom", undefined, this.hideSingleTabs() ? undefined : this);
refit = this.syncMinSize(w) || refit; // ensure syncMinSize is called
}
for (const w of diffWidgets.unchanged) {
this.updateTitle(w);
refit = this.syncMinSize(w) || refit; // ensure syncMinSize is called
}
if (arguments.length === 2 && typeof arguments[1] === "object") {
args = arguments[1];
} else {
args = new Array(arguments.length - 1);
for (let i = 1; i < arguments.length; ++i) {
args[i - 1] = arguments[i];
}
}
if (!args || !args.hasOwnProperty) {
args = {};
}
// Array handling
for (const key in args) {
if (isArray(args[key])) {
args[key].forEach(function (row, idx) {
args[key + "[" + idx + "]"] = row;
});
}
}
return tpl
.replace(nargs2, function replaceArg(match, i) {
const result = args.hasOwnProperty(i) ? args[i] : null;
if (result === null || result === undefined) {
return match;
}
return removeHTMLFromString(result);
})
.replace(nargs, function replaceArg(match, i, index) {
const result = args.hasOwnProperty(i) ? args[i] : null;
// tslint:disable: no-require-imports
// DOM Parser polyfill ---
import { root } from "@hpcc-js/util";
import { DOMParser } from "xmldom";
root.DOMParser = DOMParser;
// fetch polyfill ---
import fetch from "node-fetch";
if (typeof root.fetch === "undefined") {
root.fetch = fetch;
// tslint:disable-next-line: no-var-requires
const https = require("https");
root.fetch.__agent = new https.Agent({
rejectUnauthorized: false
});
}
// btoa polyfill ---
import { Buffer } from "safe-buffer";
if (typeof root.btoa === "undefined") {
root.btoa = function (str: string) {
return Buffer.from(str || "", "utf8").toString("base64");
};
}
export * from "./index-common";
// Client Tools ---
export * from "./clienttools/eclcc";
// tslint:disable: no-require-imports
// DOM Parser polyfill ---
import { root } from "@hpcc-js/util";
import { DOMParser } from "xmldom";
root.DOMParser = DOMParser;
// fetch polyfill ---
import fetch from "node-fetch";
if (typeof root.fetch === "undefined") {
root.fetch = fetch;
// tslint:disable-next-line: no-var-requires
const https = require("https");
root.fetch.__agent = new https.Agent({
rejectUnauthorized: false
});
}
// btoa polyfill ---
import { Buffer } from "safe-buffer";
if (typeof root.btoa === "undefined") {
root.btoa = function (str: string) {
return Buffer.from(str || "", "utf8").toString("base64");
};
}
// tslint:disable: no-require-imports
// DOM Parser polyfill ---
import { root } from "@hpcc-js/util";
import { DOMParser } from "xmldom";
root.DOMParser = DOMParser;
// fetch polyfill ---
import fetch from "node-fetch";
if (typeof root.fetch === "undefined") {
root.fetch = fetch;
// tslint:disable-next-line: no-var-requires
const https = require("https");
root.fetch.__agent = new https.Agent({
rejectUnauthorized: false
});
}
// btoa polyfill ---
import { Buffer } from "safe-buffer";
if (typeof root.btoa === "undefined") {
root.btoa = function (str: string) {
return Buffer.from(str || "", "utf8").toString("base64");
};
}
// fetch polyfill ---
import fetch from "node-fetch";
if (typeof root.fetch === "undefined") {
root.fetch = fetch;
// tslint:disable-next-line: no-var-requires
const https = require("https");
root.fetch.__agent = new https.Agent({
rejectUnauthorized: false
});
}
// btoa polyfill ---
import { Buffer } from "safe-buffer";
if (typeof root.btoa === "undefined") {
root.btoa = function (str: string) {
return Buffer.from(str || "", "utf8").toString("base64");
};
}
export * from "./index-common";
// Client Tools ---
export * from "./clienttools/eclcc";
export * from "./clienttools/eclMeta";
// fetch polyfill ---
import fetch from "node-fetch";
if (typeof root.fetch === "undefined") {
root.fetch = fetch;
// tslint:disable-next-line: no-var-requires
const https = require("https");
root.fetch.__agent = new https.Agent({
rejectUnauthorized: false
});
}
// btoa polyfill ---
import { Buffer } from "safe-buffer";
if (typeof root.btoa === "undefined") {
root.btoa = function (str: string) {
return Buffer.from(str || "", "utf8").toString("base64");
};
}
export * from "./index-common";
// Client Tools ---
export * from "./clienttools/eclcc";
export * from "./clienttools/eclMeta";
for (let i = 0; i < 100; ++i) {
func().then(val => {
expect(funcCallCount).to.equal(1);
});
}
for (let i = 1; i < 100; ++i) {
await func().then(val => {
expect(funcCallCount).to.equal(i);
expect(val).to.equal(42);
});
}
expect(funcCallCount).to.equal(99);
});
let funcHalfSecCallCount = 0;
const funcHalfSec = debounce(async (): Promise => {
++funcHalfSecCallCount;
console.log(`funcHalfSec - ${funcHalfSecCallCount}`);
return 42;
}, 500);
it("0.5 sec timeout", async function (): Promise {
return new Promise((resolve, reject) => {
const startTime = Date.now();
funcHalfSec();
const interval = setInterval(() => {
funcHalfSec();
const elapsed = Date.now() - startTime;
console.log(`elapsed - ${elapsed}`);
if (elapsed > 1500) {
expect(funcHalfSecCallCount).to.equal(4);
clearInterval(interval);