async-test-util
Advanced tools
Comparing version 1.7.3 to 2.0.0
@@ -16,26 +16,37 @@ import wait from './wait'; | ||
if (timeout !== 0) wait(timeout).then(function () { | ||
return timedOut = true; | ||
}); | ||
if (timeout !== 0) { | ||
wait(timeout).then(function () { | ||
return timedOut = true; | ||
}); | ||
} | ||
return new Promise(function (resolve, reject) { | ||
var runLoop = function runLoop() { | ||
/** | ||
* @recursive | ||
* @return {Promise<void>} | ||
*/ | ||
function runLoopOnce() { | ||
if (ok) { | ||
resolve(); | ||
return; | ||
} | ||
if (timedOut) { | ||
} else if (timedOut) { | ||
reject(new Error('AsyncTestUtil.waitUntil(): reached timeout of ' + timeout + 'ms')); | ||
return; | ||
} else { | ||
return wait(interval).then(function () { | ||
return promisify(fun()); | ||
}) | ||
/** | ||
* Propagate errors of the fun function | ||
* upwards. | ||
*/ | ||
['catch'](function (err) { | ||
return reject(err); | ||
}).then(function (value) { | ||
ok = value; | ||
return runLoopOnce(); | ||
}); | ||
} | ||
wait(interval).then(function () { | ||
var value = promisify(fun()); | ||
value.then(function (val) { | ||
ok = val; | ||
runLoop(); | ||
}); | ||
}); | ||
}; | ||
runLoop(); | ||
} | ||
runLoopOnce(); | ||
}); | ||
} |
@@ -30,26 +30,37 @@ 'use strict'; | ||
if (timeout !== 0) (0, _wait2['default'])(timeout).then(function () { | ||
return timedOut = true; | ||
}); | ||
if (timeout !== 0) { | ||
(0, _wait2['default'])(timeout).then(function () { | ||
return timedOut = true; | ||
}); | ||
} | ||
return new Promise(function (resolve, reject) { | ||
var runLoop = function runLoop() { | ||
/** | ||
* @recursive | ||
* @return {Promise<void>} | ||
*/ | ||
function runLoopOnce() { | ||
if (ok) { | ||
resolve(); | ||
return; | ||
} | ||
if (timedOut) { | ||
} else if (timedOut) { | ||
reject(new Error('AsyncTestUtil.waitUntil(): reached timeout of ' + timeout + 'ms')); | ||
return; | ||
} else { | ||
return (0, _wait2['default'])(interval).then(function () { | ||
return (0, _promisify2['default'])(fun()); | ||
}) | ||
/** | ||
* Propagate errors of the fun function | ||
* upwards. | ||
*/ | ||
['catch'](function (err) { | ||
return reject(err); | ||
}).then(function (value) { | ||
ok = value; | ||
return runLoopOnce(); | ||
}); | ||
} | ||
(0, _wait2['default'])(interval).then(function () { | ||
var value = (0, _promisify2['default'])(fun()); | ||
value.then(function (val) { | ||
ok = val; | ||
runLoop(); | ||
}); | ||
}); | ||
}; | ||
runLoop(); | ||
} | ||
runLoopOnce(); | ||
}); | ||
} |
{ | ||
"name": "async-test-util", | ||
"version": "1.7.3", | ||
"version": "2.0.0", | ||
"description": "Util-functions that are be useful in async tests", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -117,3 +117,3 @@ # async-test-util | ||
Async-Form of [assert.throws](https://nodejs.org/api/assert.html#assert_assert_throws_block_error_message). Asserts that the given function throws with the defined error, throws if not. | ||
Async-Form of [assert.throws](https://nodejs.org/api/assert.html#assert_assert_throws_fn_error_message). Asserts that the given function throws with the defined error, throws if not. | ||
@@ -120,0 +120,0 @@ ```javascript |
@@ -13,25 +13,34 @@ import wait from './wait'; | ||
if (timeout !== 0) | ||
if (timeout !== 0) { | ||
wait(timeout).then(() => timedOut = true); | ||
} | ||
return new Promise((resolve, reject) => { | ||
const runLoop = () => { | ||
/** | ||
* @recursive | ||
* @return {Promise<void>} | ||
*/ | ||
function runLoopOnce() { | ||
if (ok) { | ||
resolve(); | ||
return; | ||
} | ||
if (timedOut) { | ||
} else if (timedOut) { | ||
reject(new Error('AsyncTestUtil.waitUntil(): reached timeout of ' + timeout + 'ms')); | ||
return; | ||
} else { | ||
return wait(interval) | ||
.then(() => promisify(fun())) | ||
/** | ||
* Propagate errors of the fun function | ||
* upwards. | ||
*/ | ||
.catch(err => reject(err)) | ||
.then(value => { | ||
ok = value; | ||
return runLoopOnce(); | ||
}); | ||
} | ||
wait(interval).then(() => { | ||
const value = promisify(fun()); | ||
value.then(val => { | ||
ok = val; | ||
runLoop(); | ||
}); | ||
}); | ||
}; | ||
runLoop(); | ||
} | ||
runLoopOnce(); | ||
}); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62416
61
1199