-
-
Notifications
You must be signed in to change notification settings - Fork 85
/
index.js
59 lines (50 loc) · 1.17 KB
/
index.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
import { getSuite, setSuites } from '..';
import singleton from '../../../lib/singleton';
/**
* Generates a default suite state object.
* @param {string} suiteId Unique identifier of the validation suite.
* @param {string} name Name of the validation suite.
*/
const INITIAL_SUITE_STATE = (suiteId, name) => ({
doneCallbacks: [],
exclusive: {},
fieldCallbacks: {},
groups: {},
lagging: [],
name,
pending: [],
suiteId,
testObjects: [],
tests: {},
});
/**
* Registers a new suite run.
*/
const registerSuite = () => {
const context = singleton.useContext();
const { name, suiteId } = context;
let suite = getSuite(suiteId);
let lagging = [];
if (!suite) {
suite = setSuites(suites => {
suites[suiteId] = [];
return suites;
})[suiteId];
} else {
const [prevState] = suite;
lagging = [...prevState.lagging, ...prevState.pending];
prevState.pending = null;
prevState.lagging = null;
}
const next = {
...INITIAL_SUITE_STATE(suiteId, name),
lagging,
};
suite.unshift(next);
suite.length = 2;
setSuites(state => {
state[suiteId] = suite;
return state;
});
};
export default registerSuite;