mirror of
https://github.com/github/codeql-action.git
synced 2026-01-02 12:40:21 +08:00
* --- updated-dependencies: - dependency-name: "@typescript-eslint/eslint-plugin" dependency-type: direct:development update-type: version-update:semver-minor dependency-group: npm - dependency-name: "@typescript-eslint/parser" dependency-type: direct:development update-type: version-update:semver-minor dependency-group: npm - dependency-name: sinon dependency-type: direct:development update-type: version-update:semver-major dependency-group: npm ... Signed-off-by: dependabot[bot] <support@github.com> * Update checked-in dependencies --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
74 lines
1.9 KiB
JavaScript
74 lines
1.9 KiB
JavaScript
"use strict";
|
|
|
|
var FakeTimers = require("@sinonjs/fake-timers");
|
|
var fakeServer = require("./index");
|
|
|
|
// eslint-disable-next-line no-empty-function
|
|
function Server() {}
|
|
Server.prototype = fakeServer;
|
|
|
|
var fakeServerWithClock = new Server();
|
|
|
|
fakeServerWithClock.addRequest = function addRequest(xhr) {
|
|
if (xhr.async) {
|
|
if (typeof setTimeout.clock === "object") {
|
|
this.clock = setTimeout.clock;
|
|
} else {
|
|
this.clock = FakeTimers.install();
|
|
this.resetClock = true;
|
|
}
|
|
|
|
if (!this.longestTimeout) {
|
|
var clockSetTimeout = this.clock.setTimeout;
|
|
var clockSetInterval = this.clock.setInterval;
|
|
var server = this;
|
|
|
|
this.clock.setTimeout = function (fn, timeout) {
|
|
server.longestTimeout = Math.max(
|
|
timeout,
|
|
server.longestTimeout || 0,
|
|
);
|
|
|
|
return clockSetTimeout.apply(this, arguments);
|
|
};
|
|
|
|
this.clock.setInterval = function (fn, timeout) {
|
|
server.longestTimeout = Math.max(
|
|
timeout,
|
|
server.longestTimeout || 0,
|
|
);
|
|
|
|
return clockSetInterval.apply(this, arguments);
|
|
};
|
|
}
|
|
}
|
|
|
|
return fakeServer.addRequest.call(this, xhr);
|
|
};
|
|
|
|
fakeServerWithClock.respond = function respond() {
|
|
var returnVal = fakeServer.respond.apply(this, arguments);
|
|
|
|
if (this.clock) {
|
|
this.clock.tick(this.longestTimeout || 0);
|
|
this.longestTimeout = 0;
|
|
|
|
if (this.resetClock) {
|
|
this.clock.uninstall();
|
|
this.resetClock = false;
|
|
}
|
|
}
|
|
|
|
return returnVal;
|
|
};
|
|
|
|
fakeServerWithClock.restore = function restore() {
|
|
if (this.clock) {
|
|
this.clock.uninstall();
|
|
}
|
|
|
|
return fakeServer.restore.apply(this, arguments);
|
|
};
|
|
|
|
module.exports = fakeServerWithClock;
|