-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.js
68 lines (57 loc) · 1.8 KB
/
runner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import throat from 'throat';
import Runable from './runable';
const mRunnable = Symbol('runable');
/**
* Base runner.
*/
class Runner {
constructor(...params) {
if (!params[0]) {
throw new Error('Runner Must be Inintialized with Runnable or a function')
}
if (typeof params[0] === 'function'){
this[mRunnable] = new Runable(...params)
} else if (params[0] instanceof Runable) {
this[mRunnable] = params[0]
}
}
/**
* If there is an asserion error, this should the the added message to the error
* @abstract
* @param {any[]} params - the params passed to the executed function
* @param {object} extend - extend object passed to the runnable
* @param {Runnable} runnable - the instance of the runnable that was executed
* @return {string}
*/
asertionErrorMessage(extend, runnable) {
return `
Path: Runner(${extend.index})
`;
}
/**
* Execute the runner and return a promise representing the test run
* @param {number} cycles - the amount of cycles that should be executed
* @param {number} concurrency - amoun of cuncurrent runnables that can run in parallel
* @return {Promise}
*/
do(cycles, concurrency=1) {
let i = 0;
let queue = new Array(cycles).fill(index => this[mRunnable].call(undefined, { index }))
return Promise.all(
queue.map(throat(concurrency, fn => fn(i++)))
)
.catch(error => {
if(error instanceof Error) {
error.message = error.message + `
Internal lib-monkey Error, if you dont mind open an issue =]
`;
throw error;
} else {
let { err, extend, runnable } = error;
err.message = err.message + this.asertionErrorMessage(extend, runnable);
throw err;
}
});
}
}
export default Runner;