forked from robotframework/robotframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestdata.js
More file actions
300 lines (269 loc) · 9.53 KB
/
Copy pathtestdata.js
File metadata and controls
300 lines (269 loc) · 9.53 KB
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
window.testdata = function () {
var elementsById = {};
var idCounter = 0;
var _statistics = null;
var LEVELS = ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FAIL'];
var STATUSES = ['FAIL', 'PASS', 'NOT_RUN'];
var KEYWORDS = ['KEYWORD', 'SETUP', 'TEARDOWN', 'FOR', 'VAR'];
function addElement(elem) {
if (!elem.id)
elem.id = uniqueId();
elementsById[elem.id] = elem;
return elem;
}
function uniqueId() {
idCounter++;
return 'element-id-' + idCounter;
}
function times(stats) {
var startMillis = stats[1];
var elapsed = stats[2];
if (startMillis === null)
return [null, null, elapsed];
return [util.timestamp(startMillis),
util.timestamp(startMillis + elapsed),
elapsed];
}
function message(element, strings) {
return addElement(model.Message(LEVELS[element[1]],
util.timestamp(element[0]),
strings.get(element[2]),
strings.get(element[3])));
}
function parseStatus(stats) {
return STATUSES[stats[0]];
}
function childCreator(parent, childType) {
return function (elem, strings, index) {
return addElement(childType(parent, elem, strings, index));
};
}
function createKeyword(parent, element, strings, index) {
var kw = model.Keyword({
parent: parent,
type: KEYWORDS[element[0]],
id: 'k' + (index + 1),
name: strings.get(element[1]),
libname: strings.get(element[2]),
timeout: strings.get(element[3]),
args: strings.get(element[5]),
assign: strings.get(element[6]),
tags: strings.get(element[7]),
doc: function () {
var doc = strings.get(element[4]);
this.doc = function () { return doc; };
return doc;
},
status: parseStatus(element[8], strings),
times: model.Times(times(element[8])),
isChildrenLoaded: typeof(element[9]) !== 'number'
});
lazyPopulateKeywordsFromFile(kw, element[9], strings);
kw.populateMessages(Populator(element[10], strings, message));
return kw;
}
function lazyPopulateKeywordsFromFile(parent, modelOrIndex, strings) {
var model, index, populator;
var creator = childCreator(parent, createKeyword);
if (parent.isChildrenLoaded) {
model = modelOrIndex;
populator = Populator(model, strings, creator);
} else {
index = modelOrIndex;
parent.childFileName = window.settings['splitLogBase'] + '-' + index + '.js';
populator = SplitLogPopulator(index, creator);
}
parent.populateKeywords(populator);
}
function tags(taglist, strings) {
return util.map(taglist, strings.get);
}
function createTest(parent, element, strings, index) {
var statusElement = element[5];
var test = model.Test({
parent: parent,
id: 't' + (index + 1),
name: strings.get(element[0]),
doc: function () {
var doc = strings.get(element[3]);
this.doc = function () { return doc; };
return doc;
},
timeout: strings.get(element[1]),
isCritical: element[2],
status: parseStatus(statusElement),
message: function () {
var msg = createMessage(statusElement, strings);
this.message = function () { return msg; };
return msg;
},
times: model.Times(times(statusElement)),
tags: tags(element[4], strings),
isChildrenLoaded: typeof(element[6]) !== 'number'
});
lazyPopulateKeywordsFromFile(test, element[6], strings);
return test;
}
function createMessage(statusElement, strings) {
return statusElement.length == 4 ? strings.get(statusElement[3]) : '';
}
function createSuite(parent, element, strings, index) {
var statusElement = element[5];
var suite = model.Suite({
parent: parent,
id: 's' + ((index || 0) + 1),
name: strings.get(element[0]),
source: strings.get(element[1]),
relativeSource: strings.get(element[2]),
doc: function () {
var doc = strings.get(element[3]);
this.doc = function () { return doc; };
return doc;
},
status: parseStatus(statusElement),
message: function () {
var msg = createMessage(statusElement, strings);
this.message = function () { return msg; };
return msg;
},
times: model.Times(times(statusElement)),
statistics: suiteStats(util.last(element)),
metadata: parseMetadata(element[4], strings)
});
suite.populateKeywords(Populator(element[8], strings, childCreator(suite, createKeyword)));
suite.populateTests(Populator(element[7], strings, childCreator(suite, createTest)));
suite.populateSuites(Populator(element[6], strings, childCreator(suite, createSuite)));
return suite;
}
function parseMetadata(data, strings) {
var metadata = [];
for (var i=0; i<data.length; i+=2) {
metadata.push([strings.get(data[i]), strings.get(data[i+1])]);
}
return metadata;
}
function suiteStats(stats) {
return {
total: stats[0],
totalPassed: stats[1],
totalFailed: stats[0] - stats[1],
critical: stats[2],
criticalPassed: stats[3],
criticalFailed: stats[2] - stats[3]
};
}
function Populator(items, strings, creator) {
return {
numberOfItems: function () {
return items.length;
},
creator: function (index) {
return creator(items[index], strings, index);
}
};
}
function SplitLogPopulator(structureIndex, creator) {
return {
numberOfItems: function () {
return window['keywords'+structureIndex].length;
},
creator: function (index) {
return creator(window['keywords'+structureIndex][index],
StringStore(window['strings'+structureIndex]),
index);
}
};
}
function suite() {
var elem = window.output.suite;
if (elementsById[elem.id])
return elem;
var root = addElement(createSuite(null, elem, StringStore(window.output.strings)));
window.output.suite = root;
return root;
}
function findLoaded(id) {
return elementsById[id];
}
function ensureLoaded(id, callback) {
var ids = id.split('-');
var root = suite();
ids.shift();
loadItems(ids, root, [root.id], callback);
}
function loadItems(ids, current, result, callback) {
if (!ids.length) {
callback(result);
return;
}
current.callWhenChildrenReady(function () {
var id = ids.shift();
var type = id[0];
var index = parseInt(id.substring(1)) - 1;
var item = selectFrom(current, type, index);
if (item)
result.push(item.id);
else // Invalid id. Should this be reported somewhere?
ids = [];
loadItems(ids, item, result, callback);
});
}
function selectFrom(element, type, index) {
if (type === 'k') {
return element.keywords()[index];
} else if (type === 't') {
return element.tests()[index];
} else {
return element.suites()[index];
}
}
function errorIterator() {
return {
next: function () {
return message(window.output.errors.shift(),
StringStore(window.output.strings));
},
hasNext: function () {
return window.output.errors.length > 0;
}
};
}
function statistics() {
if (!_statistics) {
var statData = window.output.stats;
_statistics = stats.Statistics(statData[0], statData[1], statData[2]);
}
return _statistics;
}
function StringStore(strings) {
function getText(id) {
var text = strings[id];
if (!text)
return '';
if (text[0] == '*')
return text.substring(1);
var extracted = extract(text);
strings[id] = '*' + extracted;
return extracted;
}
function extract(text) {
var decoded = JXG.Util.Base64.decodeAsArray(text);
var extracted = (new JXG.Util.Unzip(decoded)).unzip()[0][0];
return JXG.Util.UTF8.decode(extracted);
}
function get(id) {
if (id === null) return null;
return getText(id);
}
return {get: get};
}
return {
suite: suite,
errorIterator: errorIterator,
findLoaded: findLoaded,
ensureLoaded: ensureLoaded,
statistics: statistics,
StringStore: StringStore, // exposed for tests
LEVELS: LEVELS
};
}();