1 | const requireDeep = require('../util/requireDeep');
|
2 |
|
3 | class Strategy {
|
4 |
|
5 | |
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | constructor (name, resources, compiler, runTimeOptions) {
|
12 | this.name = name;
|
13 | this.__resourceCreators = resources;
|
14 | this.__runTimeOptions = runTimeOptions;
|
15 | this.compiler = compiler;
|
16 | this.__await__ = [];
|
17 |
|
18 | this.__gunnerInstances = [];
|
19 | this.resources = {};
|
20 | this.specs = [];
|
21 | }
|
22 |
|
23 | |
24 |
|
25 |
|
26 |
|
27 |
|
28 | createResource (name, resource) {
|
29 | return this.__resourceCreators[name](resource);
|
30 | }
|
31 |
|
32 | |
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | fetchSpecs (options) {
|
40 | this.__await__.push(
|
41 | requireDeep(options)
|
42 | .then(required => required.map(
|
43 | each => this.__gunnerInstances = this.compiler(this)(each)
|
44 | )));
|
45 | return this;
|
46 | }
|
47 |
|
48 | |
49 |
|
50 |
|
51 |
|
52 | addSpec (spec) {
|
53 | this.__gunnerInstances.push(this.compiler(this)(spec));
|
54 | return this;
|
55 | }
|
56 |
|
57 | |
58 |
|
59 |
|
60 |
|
61 | run (options) {
|
62 | const runOptions = options || this.__runTimeOptions;
|
63 |
|
64 | return Promise.all(this.__await__).then(() => (
|
65 | this.__gunnerInstances.run(runOptions)));
|
66 | }
|
67 |
|
68 | }
|
69 |
|
70 | module.exports = Strategy;
|