UNPKG

@o3r/testing

Version:

The module provides testing (e2e, unit test) utilities to help you build your own E2E pipeline integrating visual testing.

31 lines 965 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.withTimeout = exports.TimeoutError = exports.isPromise = void 0; /** * Determine if the given item is a promise * @param item Item to check */ const isPromise = (item) => !!item && typeof item.then === 'function'; exports.isPromise = isPromise; /** * Error raised when promise timeout */ class TimeoutError extends Error { constructor(message) { super(message || 'Timeout of the promise'); } } exports.TimeoutError = TimeoutError; /** * Apply timeout to a given promise * @param promise Promise to timeout * @param timeout timeout of the given promise (in ms) */ const withTimeout = async (promise, timeout) => { if (!timeout) { return promise; } return Promise.race([promise, new Promise((_, reject) => setTimeout(() => reject(new TimeoutError()), timeout))]); }; exports.withTimeout = withTimeout; //# sourceMappingURL=helpers.js.map