UNPKG

@helpscout/cyan

Version:

Cypress-like Testing for React + JSDOM

74 lines (59 loc) 1.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var PromiseQueue = /*#__PURE__*/ function () { function PromiseQueue() { this.queue = []; this.runImmediately = false; this.length = 0; } var _proto = PromiseQueue.prototype; _proto.add = function add(promise) { this.queue = [].concat(this.queue, [promise]); this.length = this.queue.length; if (this.runImmediately) { promise.process(); } }; _proto.remove = function remove(promise) { this.queue = this.queue.filter(function (p) { return p !== promise; }); this.length = this.queue.length; }; _proto.clear = function clear() { this.queue = []; this.length = 0; this.runImmediately = false; }; _proto.debug = function debug() { console.log(this.queue); }; _proto.getNextPromise = function getNextPromise() { return this.queue[0]; }; _proto.runNextPromise = function runNextPromise() { var promise = this.getNextPromise(); if (promise) { // @ts-ignore promise.process(); } }; _proto.runAllPromises = function runAllPromises() { this.queue.forEach(function (promise) { // @ts-ignore promise.process(); }); }; _proto.runPromisesImmediately = function runPromisesImmediately() { this.runImmediately = true; }; return PromiseQueue; }(); var promiseQueue = new PromiseQueue(); var _default = promiseQueue; exports.default = _default;