-
Notifications
You must be signed in to change notification settings - Fork 5
/
reducers.js
executable file
·312 lines (263 loc) · 27.2 KB
/
reducers.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
var _redux = require('redux');
var _actions = require("./actions");
function identity(defaultValue) {
return function (x) {
return x || defaultValue;
};
}
function updateSuiteToggleState(suites, id, state) {
var suite = _extends({}, suites[id]);
var result = _extends({}, suites);
suite.toggleState = state;
result[id] = suite;
return result;
}
function expand(_x2) {
var _arguments = arguments;
var _again = true;
_function: while (_again) {
var suites = _x2;
_again = false;
var id = _arguments.length <= 1 || _arguments[1] === undefined ? null : _arguments[1];
if (!id) {
return suites;
}
var suite = suites[id];
_arguments = [_x2 = updateSuiteToggleState(suites, id, "expanded"), suite.parent];
_again = true;
id = suite = undefined;
continue _function;
}
}
function toggleSuite(suites, id) {
var state = suites[id].toggleState;
return updateSuiteToggleState(suites, id, state === "collapsed" ? "expanded" : "collapsed");
}
function suites(suites, action) {
if (suites === undefined) suites = {};
if (action.type === _actions.Actions.TOGGLE_SUITE) {
return toggleSuite(suites, action.suite);
}
return suites;
}
function updateTestStatus(tests, id, status, error) {
var test = _extends({}, tests[id]);
test.status = status;
if (error) {
test.error = error;
}
var result = _extends({}, tests);
result[id] = test;
return result;
}
function tests(tests, action) {
if (tests === undefined) tests = {};
if (action.type === _actions.Actions.BEGIN_TEST) {
var id = action.test.id;
return updateTestStatus(tests, id, "pending");
}
if (action.type === _actions.Actions.END_TEST) {
var _action$test = action.test;
var id = _action$test.id;
var state = _action$test.state;
var error = _action$test.error;
return updateTestStatus(tests, id, state, error);
}
return tests;
}
function count(what) {
return function (total, object) {
if (object.status === what) {
return total + 1;
}
return total;
};
}
function hasFailed(stuff) {
return stuff.failed > 0;
}
function hasPassed(stuff) {
return stuff.passed > 0;
}
function determineTestPassOrFail(testStuff) {
if (hasPassed(testStuff) && !hasFailed(testStuff)) {
return "passed";
}
if (!hasPassed(testStuff) && hasFailed(testStuff)) {
return "failed";
}
return null;
}
function determineSuitePassOrFail(stuff) {
if (hasFailed(stuff) && !hasPassed(stuff)) {
return "failed";
}
if (!hasFailed(stuff) && hasPassed(stuff)) {
return "passed";
}
return "partial";
}
function determineStatus(suite, tests, suites) {
var suiteStatus = {
partial: suites.reduce(count("partial"), 0),
failed: suites.reduce(count("failed"), 0),
passed: suites.reduce(count("passed"), 0)
};
var testStatus = {
failed: tests.reduce(count("failed"), 0),
passed: tests.reduce(count("passed"), 0)
};
if (suite.partial) {
return "partial";
}
return determineTestPassOrFail(testStatus) || determineSuitePassOrFail(suiteStatus) || "partial";
}
function updateSuiteStatus(suites, tests, id) {
var suite = _extends({}, suites[id]);
var suiteTests = suite.tests.map(function (s) {
return tests[s];
});
var childSuites = suite.suites.map(function (s) {
return suites[s];
});
suite.status = determineStatus(suite, suiteTests, childSuites);
var result = _extends({}, suites);
result[id] = suite;
return result;
}
var entitiesAndResult = (0, _redux.combineReducers)({
entities: (0, _redux.combineReducers)({ suites: suites, tests: tests }),
result: identity([]),
stats: identity(null),
error: identity(null)
});
var initialState = {
stats: null,
entities: {
suites: {},
tests: {}
},
result: [],
error: null
};
function expandParents(state, action) {
if (action.type !== _actions.Actions.END_TEST) {
return state;
}
var id = action.test.id;
var _state$entities = state.entities;
var tests = _state$entities.tests;
var suites = _state$entities.suites;
var test = tests[id];
if (test.status === "failed" || action.expandAnyway) {
return _extends({}, state, {
entities: {
suites: expand(suites, test.parent),
tests: tests
}
});
}
return state;
}
function setSuiteStatus(state, action) {
if (action.type !== _actions.Actions.END_SUITE) {
return state;
}
var suite = action.suite;
var id = suite.id;
var _state$entities2 = state.entities;
var suites = _state$entities2.suites;
var tests = _state$entities2.tests;
return _extends({}, state, {
entities: {
suites: updateSuiteStatus(suites, tests, id),
tests: tests
}
});
}
function restart(state, action) {
if (action.type === _actions.Actions.RESTART) {
return initialState;
}
return state;
}
function begin(state, action) {
if (action.type === _actions.Actions.BEGIN) {
var _action$data = action.data;
var result = _action$data.result;
var entities = _action$data.entities;
return {
entities: {
suites: _extends({}, entities.suites),
tests: _extends({}, entities.tests)
},
result: [].concat(_toConsumableArray(result))
};
}
return state;
}
function attachStats(state, action) {
if (action.type === _actions.Actions.END) {
var stats = action.data.stats;
return _extends({}, state, { stats: stats });
}
return state;
}
function updateSuiteWithError(state, type, id, title, error) {
var suite = _extends({}, state.entities.suites[id]);
if (type === "BEFORE_EACH" || type === "BEFORE_ALL") {
suite.tests = [type + id].concat(_toConsumableArray(suite.tests));
} else {
suite.tests = [].concat(_toConsumableArray(suite.tests), [type + id]);
}
var suites = _extends({}, state.entities.suites);
suites[id] = suite;
var tests = _extends({}, state.entities.tests);
tests[type + id] = {
error: error,
id: type + id,
parent: id,
title: title,
status: "failed"
};
return _extends({}, state, {
entities: {
suites: suites,
tests: tests
}
});
}
function handleError(state, action) {
if (action.type === _actions.Actions.ERROR) {
return _extends({}, state, {
error: action.error
});
}
if (action.type === _actions.Actions.EACH_HOOK_FAILED) {
return updateSuiteWithError(state, action.hookType, action.suiteId, action.title, action.error);
}
if (action.type === _actions.Actions.HOOK_FAILED) {
return updateSuiteWithError(state, action.hookType, action.suiteId, action.title, action.error);
}
return state;
}
function pipeReducers() {
for (var _len = arguments.length, fns = Array(_len), _key = 0; _key < _len; _key++) {
fns[_key] = arguments[_key];
}
return function (state, action) {
if (state === undefined) state = initialState;
return fns.reduce(function (state, fn) {
return fn(state, action);
}, state);
};
}
exports["default"] = pipeReducers(handleError, restart, begin, attachStats, entitiesAndResult, setSuiteStatus, expandParents);
module.exports = exports["default"];
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInJlZHVjZXJzLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7cUJBQWdDLE9BQU87O3VCQUNqQixXQUFXOztBQUVqQyxTQUFTLFFBQVEsQ0FBQyxZQUFZLEVBQUM7QUFDM0IsV0FBTyxVQUFTLENBQUMsRUFBQztBQUNkLGVBQU8sQ0FBQyxJQUFJLFlBQVksQ0FBQztLQUM1QixDQUFDO0NBQ0w7O0FBRUQsU0FBUyxzQkFBc0IsQ0FBQyxNQUFNLEVBQUUsRUFBRSxFQUFFLEtBQUssRUFBQztBQUM5QyxRQUFNLEtBQUssZ0JBQU8sTUFBTSxDQUFDLEVBQUUsQ0FBQyxDQUFDLENBQUM7QUFDOUIsUUFBTSxNQUFN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