Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fake-server-with-clock.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. "use strict";
  2. var FakeTimers = require("@sinonjs/fake-timers");
  3. var fakeServer = require("./index");
  4. // eslint-disable-next-line no-empty-function
  5. function Server() {}
  6. Server.prototype = fakeServer;
  7. var fakeServerWithClock = new Server();
  8. fakeServerWithClock.addRequest = function addRequest(xhr) {
  9. if (xhr.async) {
  10. if (typeof setTimeout.clock === "object") {
  11. this.clock = setTimeout.clock;
  12. } else {
  13. this.clock = FakeTimers.install();
  14. this.resetClock = true;
  15. }
  16. if (!this.longestTimeout) {
  17. var clockSetTimeout = this.clock.setTimeout;
  18. var clockSetInterval = this.clock.setInterval;
  19. var server = this;
  20. this.clock.setTimeout = function(fn, timeout) {
  21. server.longestTimeout = Math.max(
  22. timeout,
  23. server.longestTimeout || 0
  24. );
  25. return clockSetTimeout.apply(this, arguments);
  26. };
  27. this.clock.setInterval = function(fn, timeout) {
  28. server.longestTimeout = Math.max(
  29. timeout,
  30. server.longestTimeout || 0
  31. );
  32. return clockSetInterval.apply(this, arguments);
  33. };
  34. }
  35. }
  36. return fakeServer.addRequest.call(this, xhr);
  37. };
  38. fakeServerWithClock.respond = function respond() {
  39. var returnVal = fakeServer.respond.apply(this, arguments);
  40. if (this.clock) {
  41. this.clock.tick(this.longestTimeout || 0);
  42. this.longestTimeout = 0;
  43. if (this.resetClock) {
  44. this.clock.uninstall();
  45. this.resetClock = false;
  46. }
  47. }
  48. return returnVal;
  49. };
  50. fakeServerWithClock.restore = function restore() {
  51. if (this.clock) {
  52. this.clock.uninstall();
  53. }
  54. return fakeServer.restore.apply(this, arguments);
  55. };
  56. module.exports = fakeServerWithClock;