-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.sa.html
558 lines (512 loc) · 23.7 KB
/
index.sa.html
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>JUnit Parser</title>
<meta name="description" content="A JUnit parser, visualizer and format converter">
<meta name="keywords" content="JUnit, JSON, Parser">
<meta name="author" content="André Tarnowsky">
<style>button,hr,input{overflow:visible}progress,sub,sup{vertical-align:baseline}[type=checkbox],[type=radio],legend{box-sizing:border-box;padding:0}html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}details,main{display:block}h1{font-size:2em;margin:.67em 0}hr{box-sizing:content-box;height:0}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted}b,strong{font-weight:bolder}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{border-style:none;padding:0}[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring,button:-moz-focusring{outline:ButtonText dotted 1px}fieldset{padding:.35em .75em .625em}legend{color:inherit;display:table;max-width:100%;white-space:normal}textarea{overflow:auto}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}[hidden],template{display:none}</style>
<style>h1,h2,h3,h4,h5,h6,html{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif}a,a:hover,body{color:#fff}img,p,pre,ul,video{margin-top:0;margin-bottom:2.5rem}blockquote,img,p,pre,ul,video{margin-bottom:2.5rem}table,textarea{width:100%}html{font-size:62.5%}body{font-size:1.8rem;line-height:1.618;max-width:38em;background-color:#222;padding:13px}@media (max-width:684px){body{font-size:1.53rem}}@media (max-width:382px){body{font-size:1.35rem}}h1,h2,h3,h4,h5,h6{line-height:1.1;font-weight:700;margin-top:1rem;margin-bottom:1rem;overflow-wrap:break-word;word-wrap:break-word;-ms-word-break:break-all;word-break:break-word}h1{font-size:2.35em}h2{font-size:2em}h3{font-size:1.75em}h4{font-size:1.5em}h5{font-size:1.25em}h6,pre>code{font-size:1em}small,sub,sup{font-size:75%}code,kbd,pre,samp{font-size:.9em;background-color:#4a4a4a}hr{border-color:#fff}a{text-decoration:none}a:visited{color:#e6e6e6}a:hover{border-bottom:2px solid #c9c9c9}ul{padding-left:1.4em}li{margin-bottom:.4em}blockquote{margin-left:0;margin-right:0;padding:.8em .8em .8em 1em;border-left:5px solid #fff;background-color:#4a4a4a}blockquote p{margin-bottom:0}img,video{height:auto;max-width:100%}pre{display:block;padding:1em;overflow-x:auto}code,kbd,samp{padding:0 .5em;white-space:pre-wrap}pre>code{padding:0;background-color:transparent;white-space:pre}table{text-align:justify;border-collapse:collapse}td,th{padding:.5em;border-bottom:1px solid #4a4a4a}.button,button,input[type=button],input[type=reset],input[type=submit]{display:inline-block;padding:5px 10px;text-align:center;text-decoration:none;white-space:nowrap;background-color:#fff;color:#222;border-radius:1px;border:1px solid #fff;cursor:pointer;box-sizing:border-box}.button[disabled],button[disabled],input[type=button][disabled],input[type=reset][disabled],input[type=submit][disabled]{cursor:default;opacity:.5}.button:focus:enabled,.button:hover:enabled,button:focus:enabled,button:hover:enabled,input[type=button]:focus:enabled,input[type=button]:hover:enabled,input[type=reset]:focus:enabled,input[type=reset]:hover:enabled,input[type=submit]:focus:enabled,input[type=submit]:hover:enabled{background-color:#c9c9c9;border-color:#c9c9c9;color:#222;outline:0}input,select,textarea{color:#fff;padding:6px 10px;margin-bottom:10px;background-color:#4a4a4a;border:1px solid #4a4a4a;border-radius:4px;box-shadow:none;box-sizing:border-box}input:focus,select:focus,textarea:focus{border:1px solid #fff;outline:0}input[type=checkbox]:focus{outline:#ffffff dotted 1px}fieldset,label,legend{display:block;margin-bottom:.5rem;font-weight:600}</style>
<style>body { max-width: 55em; }
textarea { font-size: 12px; }
pre { font-size: .75em; }
em { font-size: .75em; }
.testsuite-name, .testcase-name { max-width: 400px;overflow: hidden;display: inline-block;white-space: nowrap;text-overflow: ellipsis;vertical-align: middle; }
.testcase-name { max-width: 600px;}
.copy-link { float:right; margin-top: -2em;}
.plot-rect {
opacity: 0.8;
}
.plot-rect:hover {
opacity: 1;
fill: #FFFFFF;
cursor: pointer;
}</style>
</head>
<body>
<h1>JUnit Parser</h1>
<div id="plotVector" width="100%"></div>
<div>
<textarea class="xml"
placeholder="XML - paste, or use button below to load from file..."
rows="15"></textarea>
<input type="file" id="file" name="file" accept="application/xml"
title="Load JUnit XML from file" />
</div>
<details>
<summary>JSON</summary>
<div>
<a class="copy-link" onclick="copyTextToClipboard(document.querySelector('textarea.json'))" href="#">Copy to Clipboard</a>
<textarea class="json" placeholder="JSON" rows="15" readonly></textarea>
</div>
</details>
<details>
<summary>HTML</summary>
<div>
<a class="copy-link" onclick="copyTextToClipboard(document.querySelector('textarea.html'))" href="#">Copy to Clipboard</a>
<textarea class="html" placeholder="HTML" rows="15" readonly></textarea>
</div>
</details>
<div id="result"></div>
<div id="settings">
<h5>Settings</h5>
<div>
<input name="settingErrorIsFailure" id="settingErrorIsFailure" type="checkbox" checked>
<label style="display: inline" for="settingErrorIsFailure">Treat errors as if they were failures.</label>
</div>
<div>
<input name="settingPlotResult" id="settingPlotResult" type="checkbox">
<label style="display: inline" for="settingPlotResult">Plot result</label>
</div>
</div>
<script>(function(){
function copyTextToClipboard(textArea) {
textArea.focus();
textArea.select();
try {
const success = document.execCommand('copy');
} catch (err) {
console.log('unable to copy');
}
}
// to allow usage in onclick
window.copyTextToClipboard = copyTextToClipboard;
function parseTestcases(testcaseNodes) {
return testcaseNodes.map(testcase => {
const failure = testcase.querySelector('failure') ? testcase.querySelector('failure') : null;
const skipped = testcase.querySelector('skipped') ? testcase.querySelector('skipped') : null;
const error = testcase.querySelector('error') ? testcase.querySelector('error') : null;
return {
classname: testcase.getAttribute('classname'),
name: testcase.getAttribute('name'),
time: testcase.getAttribute('time') ? parseFloat(testcase.getAttribute('time'), 10) : null,
skipped: skipped ? {
message: skipped.getAttribute('message'),
} : null,
error: error && error.textContent ? error.textContent.trim() : '',
failure: failure ? {
message: failure.getAttribute('message'),
type: failure.getAttribute('type'),
content: failure.textContent ? failure.textContent.trim() : ''
} : failure,
systemOut: testcase.querySelector('system-out') ? testcase.querySelector('system-out').textContent.trim() : '',
systemErr: testcase.querySelector('system-err') ? testcase.querySelector('system-err').textContent.trim() : '',
};
});
}
function parseTestsuite(testsuiteNodes) {
return testsuiteNodes.map(testsuite => {
const testcases = [...testsuite.querySelectorAll(':scope > testcase')];
return {
id: testsuite.getAttribute('id'),
name: testsuite.getAttribute('name'),
package: testsuite.getAttribute('package'),
hostname: testsuite.getAttribute('hostname'),
disabled: testsuite.getAttribute('disabled') ? parseInt(testsuite.getAttribute('disabled'), 10) : null,
failures: testsuite.getAttribute('failures') ? parseInt(testsuite.getAttribute('failures'), 10) : null,
errors: testsuite.getAttribute('errors') ? parseInt(testsuite.getAttribute('errors'), 10) : null,
skipped: testsuite.getAttribute('skipped') ? parseInt(testsuite.getAttribute('skipped'), 10) : null,
tests: testsuite.getAttribute('tests') ? parseInt(testsuite.getAttribute('tests'), 10) : null,
time: testsuite.getAttribute('time') ? parseFloat(testsuite.getAttribute('time'), 10) : null,
timestamp: testsuite.getAttribute('timestamp') ? new Date(testsuite.getAttribute('timestamp')) : null,
testcases: testcases.length ? parseTestcases(testcases) : [],
};
});
}
function parseTestsuites(testsuitesNodes) {
return testsuitesNodes.map(testsuites => {
const testsuite = [...testsuites.querySelectorAll(':scope > testsuite')];
return {
name: testsuites.getAttribute('name'),
tests: testsuites.getAttribute('tests') ? parseInt(testsuites.getAttribute('tests'), 10) : null,
failures: testsuites.getAttribute('failures') ? parseInt(testsuites.getAttribute('failures'), 10) : null,
errors: testsuites.getAttribute('errors') ? parseInt(testsuites.getAttribute('errors'), 10) : null,
disabled: testsuites.getAttribute('disabled') ? parseInt(testsuites.getAttribute('disabled'), 10) : null,
time: testsuites.getAttribute('time') ? parseFloat(testsuites.getAttribute('time')) : null,
testsuite: testsuite.length ? parseTestsuite(testsuite) : [],
};
});
}
function convertToJson(xmlDoc) {
const result = {
testsuites: [],
};
const testsuitesNodes = [...xmlDoc.getElementsByTagName('testsuites')]
if (testsuitesNodes && testsuitesNodes.length) {
result.testsuites = parseTestsuites(testsuitesNodes);
} else {
const testsuiteNodes = [...xmlDoc.querySelectorAll('testsuite')];
if (testsuiteNodes && testsuiteNodes.length) {
result.testsuites = Array({
testsuite: parseTestsuite(testsuiteNodes)
});
}
}
return result;
}
function tplHeader(testsuites) {
return `${testsuites.name !== null ? `<h1>${testsuites.name}</h1>` : ''}
<h2>
${testsuites.tests !== null ? `Tests: <b>${testsuites.tests}</b>,` : ''}
${testsuites.failures !== null ? `Failures: <b>${testsuites.failures}</b>,` : ''}
${testsuites.errors !== null ? `Errors: <b>${testsuites.errors}</b>,` : ''}
${testsuites.time ? `<em>Time: ${testsuites.time}</em>`: ''}
</h2>`;
}
function tpl(result, clean) {
return result.testsuites.map(testsuites =>
`${testsuites.name ? tplHeader(testsuites) : ''}
${tplTestsuite(testsuites.testsuite, clean)}`
).join('');
}
function tplSuiteResult(testsuite) {
const errorIsFailure = getSetting('ErrorIsFailure');;
if ((testsuite.failures > 0)
|| (errorIsFailure && testsuite.errors && testsuite.errors > 0)) {
return `<span style="color: red">⛔</span>`;
}
return `<span style="color: green">✅</span>`;
}
function tplTestsuite(testsuites, clean) {
if (!testsuites || !testsuites.length) {
return '';
}
return testsuites.map((testsuite, ts_i) =>
`<details id="suite.${ts_i}">
<summary ${clean ? '' : `onclick="updateUrl('suite.${ts_i}')"`}>
${tplSuiteResult(testsuite)}
${testsuite.name !== null ? ` <span class="testsuite-name" title="${testsuite.name}">${testsuite.name}</span>` : ''}
${testsuite.tests !== null ? `Tests: <b>${testsuite.tests}</b>,` : ''}
${testsuite.failures !== null ? `Failures: <b>${testsuite.failures}</b>,` : ''}
${testsuite.errors !== null ? `Errors: <b>${testsuite.errors}</b>,` : ''}
${testsuite.skipped !== null ? `Skipped: <b>${testsuite.skipped}</b>,` : ''}
${testsuite.time ? `<em>Time: ${testsuite.time}</em>`: ''}
</summary>
${tplTestcases(ts_i, testsuite.testcases, clean)}
</details>`
).join('');
}
function tplCaseResult(testcase, tstc_id, clean) {
var o;
if (testcase.failure) {
o = {
summary: `<span title="failed" style="color: red">⛔</span>`,
details: `<div>
${testcase.failure.type ? `<div>${testcase.failure.type}</div>` : ''}
${testcase.failure.message ? `<div>${testcase.failure.message}</div>` : ''}
${testcase.failure.content && testcase.failure.content.length ?
`<div><b>Content:</b></div>
<div><pre>${testcase.failure.content}</pre></div>` : ''}
</div>`
};
} else if (testcase.error) {
const isF = getSetting('ErrorIsFailure');
o = {
summary: `<span title="errored" style="color: ${isF ? `red">⛔` : `green">✅`}</span>`,
details: testcase.error.length ?
`<div><pre>${testcase.error}</pre></div>` : ''
};
} else if (testcase.skipped) {
o = {
summary: `<span title="skipped">⏩</span>`,
details: testcase.skipped.message ?
`<div>${testcase.skipped.message}</div>` : ''
};
} else {
o = {
summary: `<span title="passed" style="color: green">✅</span>`,
details: ''
};
}
return `<details style="margin-left: 1em" id=${tstc_id}>
<summary ${clean ? '': `onclick="updateUrl('${tstc_id}')"`}>
${o.summary}
<span class="testcase-name" title=" ${testcase.name ? testcase.name : ''} ${testcase.classname ? testcase.classname : ''}">
${testcase.name ? testcase.name : ''}
${testcase.classname ? testcase.classname : ''}
</span>
<em>${testcase.time}</em>
</summary>
<div style="margin-left: 1em" >
${o.details}
<div>
${testcase.systemOut && testcase.systemOut.length ? `
<div><b>System-Out:</b></div>
<div><pre>${testcase.systemOut}</pre></div>
` : ''}
${testcase.systemErr && testcase.systemErr.length ? `
<div><b>System-Err:</b></div>
<div><pre>${testcase.systemErr}</pre></div>
` : ''}
</div>
</div>
</details>`;
}
function tplTestcases(ts_i, testcases, clean) {
if (!testcases || !testcases.length) {
return ''
}
return '<div>' + testcases.map((testcase, tc_i) =>
`${tplCaseResult(testcase, `case.${ts_i}.${tc_i}`, clean)}`).join('')
+ '</div>';
}
function refresh(event) {
const text = document.querySelector('textarea.xml').value;
localStorage.setItem('xml', text);
saveSettingInStorage('ErrorIsFailure');
saveSettingInStorage('PlotResult');
parseText(text);
}
function processFile(evt) {
if (evt.target.files.length < 1) {
console.log('invalid files length: ' + evt.target.files.length);
return;
}
const fr = new FileReader();
fr.onload = (ev) => {
document.querySelector('textarea.xml').value = ev.target.result;
refresh();
};
fr.readAsText(evt.target.files[0]);
}
function plotSvg(tss) {
const line_colors = [
'#00BFFF', // DeepSkyBlue
'#98FB98', // PaleGreen
'#FFFF00', // Yellow
'#FFA07A', // LightSalmon
'#F4A460', // SandyBrown
'#FFB6C1', // LightPink
'#ADD8E6', // LightBlue
'#DDA0DD', // Plum
];
function node(el, attrs) {
const e = document.createElementNS("http://www.w3.org/2000/svg", el);
for (var i in attrs) {
e.setAttributeNS(null, i, attrs[i]);
}
return e;
}
function plotInit(plotDiv, suite_name) {
const svg = document.createElementNS("http://www.w3.org/2000/svg",
'svg');
svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
var n = node('rect', { width: '100%', height: '100%', fill: 'black' });
svg.appendChild(n); // background
[ 'passed', 'skipped', 'failed' ].forEach((bucket, i) => {
const rect_y = i * 100 + 96; // dividers for pass, skip & fail buckets
const tx_y = rect_y + 94;
var g = node('g', {});
n = node('title', {});
n.appendChild(document.createTextNode(`${bucket} tests`));
g.appendChild(n);
n = node('rect', { x: '0', y: rect_y, width: '100%', height: '102',
'stroke-dasharray': '4', stroke: 'grey', 'stroke-width': '2' });
g.appendChild(n);
n = node('text', { x: '99%', y: tx_y, 'font-size': '12', fill: 'grey',
'text-anchor': 'end'});
n.appendChild(document.createTextNode(bucket));
g.appendChild(n);
svg.appendChild(g);
});
n = node('text', { x: '50%', y: '28', 'text-anchor': 'middle',
'font-size': '28', fill: 'white' });
svg.appendChild(n);
n.appendChild(
document.createTextNode(`Results for Test Suite ${suite_name}`)
);
svg.appendChild(n);
plotDiv.appendChild(svg);
// initial dimensions based on chart title. Width may be extended later.
svg.setAttribute('width', svg.getBBox().width + 10);
svg.setAttribute('height', '500');
return svg;
}
function plotSuite(ts_i, suite, svg_suite_state) {
const svg = svg_suite_state.svg;
const xinc = 15;
// path line joins up all points
var line = null;
var xcoord = svg_suite_state.xcoord_next;
var ycoord
for (let i = 0; i < suite.testcases.length; i++) {
const tc = suite.testcases[i];
var rfill;
var title = null;
if (tc.failure) {
title = tc.failure.message;
rfill = "rgba(212, 22, 16)"; // red
ycoord = 300;
} else if (tc.error) {
rfill = "rgba(228, 232, 19)"; // yellow
ycoord = 300;
} else if (tc.skipped) {
title = tc.skipped.message;
rfill = "rgba(29, 85, 176)"; // blue
ycoord = 200;
} else {
title = tc.time ? `passed with time ${tc.time}` : null;
rfill = "rgba(53, 176, 34)"; // green
ycoord = 100;
}
if (tc.name in svg_suite_state.case_xcoords) {
// reuse pre-existing testcase name on x-axis
xcoord_next = xcoord;
xcoord = svg_suite_state.case_xcoords[tc.name];
} else {
xcoord_next = xcoord + xinc;
svg_suite_state.case_xcoords[tc.name] = xcoord;
text_ycoord = 500;
n = node('text', {x: 0, y: 0, 'font-size': '12', fill: 'white',
transform: `translate(${xcoord + 10},${text_ycoord}) rotate(-90)`});
n.appendChild(document.createTextNode(tc.name));
svg.appendChild(n);
}
// stagger y-coords across suites plotted on the same axis, so points
// aren't overlaid.
ycoord += (15 * svg_suite_state.plot_i);
var g = node('g', {});
n = node('title', {});
n.appendChild(
document.createTextNode(`${tc.name}${title ? ': ' + title : ''}`));
g.appendChild(n);
n = node('a', { href: `#case.${ts_i}.${i}` });
n.appendChild(
node('rect', { x: xcoord, y: ycoord, width: 10, height: 10,
fill: rfill, 'fill-opacity': '0.8', class: 'plot-rect' })
);
g.appendChild(n);
svg.appendChild(g);
if (!line) {
// +5 for middle of rect
line = `M ${xcoord + 5} ${ycoord + 5}`;
} else {
line += ` L ${xcoord + 5} ${ycoord + 5}`;
}
xcoord = xcoord_next;
}
// subsequent name-matched suites could reuse. Append new tests from where
// we left off.
svg_suite_state.xcoord_next = xcoord;
if (line) {
const color = line_colors[svg_suite_state.plot_i % line_colors.length];
n = node('path', // path connecting all points
{ fill: 'none', stroke: color, 'stroke-width': '3', d: line });
svg_suite_state.line_sibling.after(n);
svg_suite_state.line_sibling = n;
}
if (xcoord > svg.getAttribute('width')) {
svg.setAttribute('width', xcoord); // resize to fit bounds
}
}
const plotDiv = document.getElementById("plotVector");
plotDiv.replaceChildren();
if (tss.length < 1) {
return;
}
// plot matching testsuites on the same graph, reusing common x-axis points
var svg_suite_state = {};
tss[0].testsuite.forEach((suite, ts_i) => {
if (suite.name in svg_suite_state) {
svg_suite_state[suite.name].plot_i++;
} else {
const svg = plotInit(plotDiv, suite.name);
svg_suite_state[suite.name] = {
'svg': svg,
xcoord_next: 5,
case_xcoords: {},
plot_i: 0, // per-plot increment for this suite
line_sibling: svg.lastChild // append line plots after bg and banner
};
}
plotSuite(ts_i, suite, svg_suite_state[suite.name]);
});
}
function parseText(text) {
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(text.trim(),"text/xml");
const resultAsJson = convertToJson(xmlDoc);
document.querySelector('textarea.json').value = JSON.stringify(resultAsJson, null,2);
document.querySelector('#result').innerHTML = tpl(resultAsJson);
document.querySelector('textarea.html').value = tpl(resultAsJson, true).trim();
const plotResuls = getSetting('PlotResult');
if (plotResuls) {
plotSvg(resultAsJson.testsuites);
} else {
plotSvg([]);
}
}
// #case.$testsuite_id.$testcase_id URL opens and scrolls to details
function scrollTestInView() {
if (document.location.hash) {
const hel = document.getElementById(document.location.hash.substring(1));
if (hel) {
for (el = hel; el; el = el.parentElement) {
if (el.open === false) {
el.setAttribute('open', true);
}
}
hel.scrollIntoView();
}
}
}
function getSetting(name, defaultValue) {
let setting = typeof defaultValue !== 'undefined' ? defaultValue : false;
const settingName = `setting${name}`;
// from dom
const elm = document.getElementById(settingName);
if (elm) {
setting = elm.checked;
}
// overwrite with storage
const strg = localStorage.getItem(settingName);
if (strg) {
setting = strg === 'true';
}
// update dom with storage
if (elm && strg) {
if (elm.checked !== setting) {
elm.checked = setting;
}
}
return setting;
}
function saveSettingInStorage(name, settingValue) {
const settingName = `setting${name}`;
const elm = document.getElementById(settingName);
if (elm) {
settingValue = elm.checked;
}
const strg = localStorage.setItem(settingName, settingValue ? settingValue : false);
}
function addCustomEventListener(selector, event, listener) {
const elm = document.querySelector(selector);
if (elm) {
elm.addEventListener(event, listener);
}
}
function init() {
addCustomEventListener('textarea.xml', 'change', refresh);
addCustomEventListener('#settingErrorIsFailure', 'change', refresh);
addCustomEventListener('#settingPlotResult', 'change', refresh);
addCustomEventListener('#file', 'change', processFile);
getSetting('ErrorIsFailure', true);
getSetting('PlotResult', false);
const lsXml = localStorage.getItem('xml');
if (lsXml) {
document.querySelector('textarea.xml').value = lsXml;
parseText(lsXml);
}
scrollTestInView();
updateUrl = (id) => {
window.location.hash = `#${id}`;
return false;
}
}
init();
})();</script>
</body>
</html>