-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
304 lines (275 loc) · 13.6 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/normalize.css@8.0.1/normalize.css">
<link rel="stylesheet" href="https://unpkg.com/sakura.css/css/sakura-dark.css" type="text/css">
<script async defer src="https://buttons.github.io/buttons.js"></script>
<title>Online JUnit Parser</title>
<meta name="description" content="An online JUnit parser that display the JUnit file in a readable format and convert the JUnit file to json">
<meta name="keywords" content="JUnit, JSON, Parser, online">
<meta name="author" content="André Tarnowsky">
<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;}
.buttons { margin-top: 1em;}
.copy-link { float:right; margin-top: -2em;}
</style>
</head>
<body>
<h1>Online JUnit Parser</h1>
<textarea class="xml" placeholder="XML" rows="15"></textarea>
<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"></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"></textarea>
</div>
</details>
<div id="result"></div>
<div id="settings">
<input name="settingErrorIsFailure" id="settingErrorIsFailure" type="checkbox" checked>
<label style="display: inline" for="settingErrorIsFailure">Treat errors as if they were failures.</label>
</div>
<div class="buttons">
<a class="github-button" href="https://github.com/lotterfriends/online-junit-parser" data-color-scheme="no-preference: light; light: light; dark: light;" data-icon="octicon-star" data-size="large" aria-label="Star lotterfriends/online-junit-parser on GitHub">Star</a>
<a class="github-button" href="https://github.com/lotterfriends" data-color-scheme="no-preference: light; light: light; dark: light;" data-size="large" aria-label="Follow @lotterfriends on GitHub">Follow @lotterfriends</a>
</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,
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')];
const testsuites = [...testsuite.querySelectorAll(':scope > testsuite')];
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) : [],
testsuite: testsuites.length ? parseTestsuite(testsuites) : []
};
});
}
function parseTestsuites(testsuitesNodes) {
return testsuitesNodes.map(testsuites => {
const testcases = [...testsuites.querySelectorAll(':scope > testcase')];
const testsuite = [...testsuites.querySelectorAll(':scope > testsuite')];
return {
id: testsuites.getAttribute('id'),
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) : [],
testcases: testcases.length ? parseTestcases(testcases) : []
};
});
}
function convertToJson(xmlDoc) {
const result = {
testsuites: [],
testsuite: [],
testcases: []
};
const testsuitesNodes = [...xmlDoc.getElementsByTagName('testsuites')]
if (testsuitesNodes && testsuitesNodes.length) {
result.testsuites = parseTestsuites(testsuitesNodes);
} else {
const testsuiteNodes = [...xmlDoc.querySelectorAll(':scope > testsuite')];
if (testsuiteNodes && testsuiteNodes.length) {
result.testsuite = parseTestsuite(testsuiteNodes);
}
const testcaseNodes = [...xmlDoc.querySelectorAll(':scope > testcase')];
if (testcaseNodes && testcaseNodes.length) {
result.testcases = parseTestcases(testcaseNodes);
}
}
return result;
}
function tplFail() {
return `<span style="color: red">⛔</span>`;
}
function tplSuccess() {
return `<span style="color: green">✅</span>`;
}
function tplResult(isFailing) {
return isFailing ? tplFail() : tplSuccess();
}
function tpl(result) {
return `
${result.testsuites ? result.testsuites.map(testsuites => `
${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>
${tplTestsuite(testsuites.testsuite)}
`).join('') : ''}
${result.testsuite ? tplTestsuite(result.testsuite) : ''}
${result.testcases ? tplTestcases(result.testcases) : ''}
`
}
function isFailing(testObject) {
const errorIsFailure = document.getElementById('settingErrorIsFailure').checked;
if (testObject.failure && testObject.failures > 0) {
return true;
}
if (errorIsFailure) {
if (testObject.errors && testObject.errors > 0) {
return true;
}
if (testObject.error && testObject.error.length) {
return true;
}
}
return false;
}
function tplTestsuite(testsuites) {
return testsuites && testsuites.length ? `
${testsuites.map(testsuite => `
<details>
<summary>
${tplResult(isFailing(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>
${testsuite.testcases && testsuite.testcases.length ? `<div>${tplTestcases(testsuite.testcases)}</div>` : ''}
${testsuite.testsuite && testsuite.testsuite.length ? `<div style="margin-left: 1em">${tplTestsuite(testsuite.testsuite)}</div>` : ''}
</details>
`).join('')}
` : '';
}
function tplTestcases(testcases) {
return testcases && testcases.length ? `
${testcases.map(testcase => `
<details style="margin-left: 1em">
<summary>
${tplResult(isFailing(testcase))}
<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">
${testcase.failure ? `
<div>
${testcase.failure.type ? `<div>${testcase.failure.type}</div>` : ''}
${testcase.failure.message ? `<div>${testcase.failure.message}</div>` : ''}
${testcase.failure && testcase.failure.content && testcase.failure.content.length ? `
<div><b>Content:</b></div>
<div><pre>${testcase.failure.content}</pre></div>
` : ''}
</div>
` : ''}
${testcase.error && testcase.error.length ? `
<div><pre>${testcase.error}</pre></div>
` : ''}
<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>
`).join('')}` : '';
}
function refresh(event) {
const text = document.querySelector('textarea.xml').value;
parseText(text);
}
function parseText(text) {
localStorage.setItem('xml', text);
localStorage.setItem('settingErrorIsFailure', `${document.getElementById('settingErrorIsFailure').checked}`);
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 = document.querySelector('#result').innerHTML.trim();
}
function init() {
document.querySelector('textarea.xml').addEventListener('change', refresh);
document.querySelector('#settingErrorIsFailure').addEventListener('change', refresh);
const settingErrorIsFailureStorage = localStorage.getItem('settingErrorIsFailure');
const settingErrorIsFailur = false;
if (settingErrorIsFailureStorage && settingErrorIsFailureStorage === 'true') {
document.getElementById('settingErrorIsFailure').checked = true;
}
const lsXml = localStorage.getItem('xml');
if (lsXml) {
document.querySelector('textarea.xml').value = lsXml;
parseText(lsXml);
}
}
init();
})();
</script>
</body>
</html>