async-test-util
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -7,2 +7,4 @@ import assertThrows from './assert-throws'; | ||
import wait from './wait'; | ||
import waitForever from './wait-forever'; | ||
import runForever from './run-forever'; | ||
@@ -15,6 +17,8 @@ var AsyncTestUtil = { | ||
waitUntil: waitUntil, | ||
wait: wait | ||
wait: wait, | ||
waitForever: waitForever, | ||
runForever: runForever | ||
}; | ||
export default AsyncTestUtil; | ||
export { assertThrows, clone, deepEqual, waitResolveable, waitUntil, wait }; | ||
export { assertThrows, clone, deepEqual, waitResolveable, waitUntil, wait, waitForever, runForever }; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.wait = exports.waitUntil = exports.waitResolveable = exports.deepEqual = exports.clone = exports.assertThrows = undefined; | ||
exports.runForever = exports.waitForever = exports.wait = exports.waitUntil = exports.waitResolveable = exports.deepEqual = exports.clone = exports.assertThrows = undefined; | ||
@@ -33,2 +33,10 @@ var _assertThrows = require('./assert-throws'); | ||
var _waitForever = require('./wait-forever'); | ||
var _waitForever2 = _interopRequireDefault(_waitForever); | ||
var _runForever = require('./run-forever'); | ||
var _runForever2 = _interopRequireDefault(_runForever); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
@@ -42,3 +50,5 @@ | ||
waitUntil: _waitUntil2['default'], | ||
wait: _wait2['default'] | ||
wait: _wait2['default'], | ||
waitForever: _waitForever2['default'], | ||
runForever: _runForever2['default'] | ||
}; | ||
@@ -51,2 +61,4 @@ exports['default'] = AsyncTestUtil; | ||
exports.waitUntil = _waitUntil2['default']; | ||
exports.wait = _wait2['default']; | ||
exports.wait = _wait2['default']; | ||
exports.waitForever = _waitForever2['default']; | ||
exports.runForever = _runForever2['default']; |
{ | ||
"name": "async-test-util", | ||
"version": "1.0.0", | ||
"description": "", | ||
"version": "1.1.0", | ||
"description": "Util-functions that are be useful in async tests", | ||
"main": "./dist/lib/index.js", | ||
@@ -11,2 +11,3 @@ "jsnext:main": "./dist/es/index.js", | ||
"test": "npm run build && mocha -b", | ||
"lint": "eslint src test", | ||
"clear": "rimraf -rf ./dist", | ||
@@ -29,25 +30,26 @@ "build:es6": "rimraf -rf dist/es && cross-env NODE_ENV=es6 babel src --out-dir dist/es", | ||
"assert": "1.4.1", | ||
"babel-cli": "^6.23.0", | ||
"babel-core": "^6.25.0", | ||
"babel-eslint": "^7.2.3", | ||
"babel-loader": "^7.1.1", | ||
"babel-plugin-transform-async-to-generator": "^6.22.0", | ||
"babel-plugin-transform-class-properties": "^6.23.0", | ||
"babel-plugin-transform-es2015-block-scoping": "^6.24.1", | ||
"babel-plugin-transform-es2015-constants": "^6.1.4", | ||
"babel-plugin-transform-es3-member-expression-literals": "^6.22.0", | ||
"babel-plugin-transform-es3-property-literals": "^6.22.0", | ||
"babel-plugin-transform-object-rest-spread": "^6.23.0", | ||
"babel-plugin-transform-regenerator": "^6.24.1", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-polyfill": "^6.23.0", | ||
"babel-preset-es2015": "^6.24.0", | ||
"babel-cli": "6.24.1", | ||
"babel-core": "6.25.0", | ||
"babel-eslint": "7.2.3", | ||
"babel-loader": "7.1.1", | ||
"babel-plugin-transform-async-to-generator": "6.24.1", | ||
"babel-plugin-transform-class-properties": "6.24.1", | ||
"babel-plugin-transform-es2015-block-scoping": "6.24.1", | ||
"babel-plugin-transform-es2015-constants": "6.1.4", | ||
"babel-plugin-transform-es3-member-expression-literals": "6.22.0", | ||
"babel-plugin-transform-es3-property-literals": "6.22.0", | ||
"babel-plugin-transform-object-rest-spread": "6.23.0", | ||
"babel-plugin-transform-regenerator": "6.24.1", | ||
"babel-plugin-transform-runtime": "6.23.0", | ||
"babel-polyfill": "6.23.0", | ||
"babel-preset-es2015": "6.24.1", | ||
"babel-preset-es2015-native-modules": "6.9.4", | ||
"babel-preset-es2015-rollup": "3.0.0", | ||
"babel-preset-es2016": "^6.24.1", | ||
"babel-preset-es2017": "^6.24.1", | ||
"babel-preset-latest": "^6.24.1", | ||
"cross-env": "^5.0.1", | ||
"mocha": "^3.4.2", | ||
"rimraf": "^2.6.1" | ||
"babel-preset-es2016": "6.24.1", | ||
"babel-preset-es2017": "6.24.1", | ||
"babel-preset-latest": "6.24.1", | ||
"cross-env": "5.0.1", | ||
"eslint": "4.2.0", | ||
"mocha": "3.4.2", | ||
"rimraf": "2.6.1" | ||
}, | ||
@@ -54,0 +56,0 @@ "dependencies": { |
@@ -66,3 +66,3 @@ # async-test-util | ||
```javascript | ||
it('should until server is online (maxtime: 1000ms)', async() => { | ||
it('should wait until server is online (maxtime: 1000ms)', async() => { | ||
const checkServer = async() => { | ||
@@ -80,2 +80,38 @@ try{ | ||
## waitForever() | ||
Waits forever, never resolves. | ||
```javascript | ||
it('should never resolve', async() => { | ||
let resolved = false; | ||
AsyncTestUtil | ||
.waitForever() | ||
.then(() => resolved = true); | ||
await AsyncTestUtil.wait(100); | ||
assert.equal(false, resolved); | ||
}); | ||
``` | ||
## runForever() | ||
Runs the given predicate-function forever. Between each run, the interval-time is awaited. | ||
```javascript | ||
it('should run forever', async() => { | ||
let t = 0; | ||
const pred = () => t++; | ||
AsyncTestUtil.runForever( | ||
pred, // predicate-function | ||
10 // interval | ||
); | ||
await AsyncTestUtil.wait(100); | ||
assert.ok(t > 4); | ||
const lastT = t; | ||
await AsyncTestUtil.wait(100); | ||
assert.ok(t > lastT); | ||
}); | ||
``` | ||
## assertThrows() | ||
@@ -82,0 +118,0 @@ |
@@ -30,2 +30,18 @@ /** | ||
/** | ||
* runs the given predicate-function forever | ||
* @param {Function} predicate | ||
* @param {number} [interval=100] interval-time in ms (optional) | ||
* @return {Promise<void>} never resolves | ||
*/ | ||
export function runForever(predicate: Function, interval?: number): Promise<void>; | ||
/** | ||
* waits forever | ||
* @return {Promise<void>} | ||
*/ | ||
export function waitForever(): Promise<void>; | ||
/** | ||
* async version of assert.throws | ||
@@ -32,0 +48,0 @@ * @param {Function} fun which should throw |
@@ -7,2 +7,4 @@ import assertThrows from './assert-throws'; | ||
import wait from './wait'; | ||
import waitForever from './wait-forever'; | ||
import runForever from './run-forever'; | ||
@@ -15,3 +17,5 @@ const AsyncTestUtil = { | ||
waitUntil, | ||
wait | ||
wait, | ||
waitForever, | ||
runForever | ||
}; | ||
@@ -26,3 +30,5 @@ export default AsyncTestUtil; | ||
waitUntil, | ||
wait | ||
wait, | ||
waitForever, | ||
runForever | ||
}; |
@@ -13,3 +13,2 @@ const assert = require('assert'); | ||
waiter.promise.then(x => { | ||
console.log('res!!!: ' + x); | ||
resolved = x; | ||
@@ -16,0 +15,0 @@ }); |
Sorry, the diff of this file is not supported yet
55886
42
1005
182
25