monocart-reporter 2.9.6 → 2.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,369 +1,369 @@
1
- const Util = {
2
-
3
- // definition
4
- tagPattern: /(\s*)@([^@\s]+)(\s*)/g,
5
-
6
- attachments: {
7
- audit: {
8
- name: 'audit',
9
- contentType: 'text/html',
10
- reportFile: 'audit-report.json'
11
- },
12
- coverage: {
13
- name: 'coverage',
14
- contentType: 'text/html',
15
- reportFile: 'coverage-report.json'
16
- },
17
- network: {
18
- name: 'network',
19
- contentType: 'text/html',
20
- reportFile: 'network-report.json'
21
- },
22
- metadata: {
23
- name: 'metadata',
24
- contentType: 'application/json'
25
- }
26
- },
27
-
28
- pageTimings: [{
29
- key: 'onContentLoad',
30
- name: 'Content Loaded',
31
- color: '#1a1aa6'
32
- }, {
33
- key: 'onLoad',
34
- name: 'Page Loaded',
35
- color: '#c80000'
36
- }],
37
-
38
- timings: [{
39
- key: 'blocked',
40
- name: 'Blocking',
41
- color: '#858585'
42
- }, {
43
- key: 'dns',
44
- name: 'DNS Lookup',
45
- color: '#009688'
46
- }, {
47
- key: 'connect',
48
- name: 'Connecting',
49
- color: '#b52dcd'
50
- }, {
51
- key: 'send',
52
- name: 'Sending',
53
- color: '#74979a'
54
- }, {
55
- key: 'wait',
56
- name: 'Waiting',
57
- color: '#00a846'
58
- }, {
59
- key: 'receive',
60
- name: 'Receiving',
61
- color: '#0299de'
62
- }],
63
-
64
- hasOwn: function(obj, key) {
65
- return Object.prototype.hasOwnProperty.call(obj, key);
66
- },
67
-
68
- isNull: function(input) {
69
- if (input === null || typeof input === 'undefined') {
70
- return true;
71
- }
72
- return false;
73
- },
74
-
75
- uid: function(len = 20, prefix = '') {
76
- const dict = '0123456789abcdefghijklmnopqrstuvwxyz';
77
- const dictLen = dict.length;
78
- let str = prefix;
79
- while (len--) {
80
- str += dict[Math.random() * dictLen | 0];
81
- }
82
- return str;
83
- },
84
-
85
- zero: function(s, l = 2) {
86
- s = `${s}`;
87
- return s.padStart(l, '0');
88
- },
89
-
90
- toNum: function(num, toInt) {
91
- if (typeof (num) !== 'number') {
92
- num = parseFloat(num);
93
- }
94
- if (isNaN(num)) {
95
- num = 0;
96
- }
97
- if (toInt) {
98
- num = Math.round(num);
99
- }
100
- return num;
101
- },
102
-
103
- isList: function(data) {
104
- if (data && data instanceof Array && data.length > 0) {
105
- return true;
106
- }
107
- return false;
108
- },
109
-
110
- forEach: function(rootList, callback) {
111
- const isBreak = (res) => {
112
- return res === 'break' || res === false;
113
- };
114
- const forList = (list, parent) => {
115
- if (!Util.isList(list)) {
116
- return;
117
- }
118
- for (const item of list) {
119
- const result = callback(item, parent);
120
- if (isBreak(result)) {
121
- return result;
122
- }
123
- const subResult = forList(item.subs, item);
124
- if (isBreak(subResult)) {
125
- return subResult;
126
- }
127
- }
128
- };
129
- forList(rootList);
130
- },
131
-
132
- // \ to /
133
- formatPath: function(str) {
134
- if (str) {
135
- str = str.replace(/\\/g, '/');
136
- }
137
- return str;
138
- },
139
-
140
- getCurrentTrendInfo: (data) => {
141
-
142
- const {
143
- date, duration, summary
144
- } = data;
145
-
146
- const info = {
147
- date,
148
- duration
149
- };
150
-
151
- Object.keys(summary).forEach((k) => {
152
- const item = summary[k];
153
- info[k] = item.value;
154
- });
155
-
156
- return info;
157
- },
158
-
159
- isTagItem: (item) => {
160
-
161
- // new syntax in playwright v1.42
162
- if (item.tags) {
163
- return true;
164
- }
165
-
166
- if (item.type === 'case' || (item.type === 'suite' && item.suiteType === 'describe')) {
167
- return true;
168
- }
169
- return false;
170
- },
171
-
172
- delay: function(ms) {
173
- return new Promise((resolve) => {
174
- if (ms) {
175
- setTimeout(resolve, ms);
176
- } else {
177
- setImmediate(resolve);
178
- }
179
- });
180
- },
181
-
182
- // =============================================================================
183
-
184
- generatePercentChart: function(percent) {
185
- return `<div style="--mcr-percent:${percent}%;" class="mcr-percent-chart"></div>`;
186
- },
187
-
188
- getStatus: (value, watermarks) => {
189
- if (!watermarks) {
190
- return 'unknown';
191
- }
192
- if (value < watermarks[0]) {
193
- return 'low';
194
- }
195
- if (value < watermarks[1]) {
196
- return 'medium';
197
- }
198
- return 'high';
199
- },
200
-
201
- isJsonType(contentType) {
202
- if (contentType) {
203
- if (contentType === 'application/json' || contentType === 'json') {
204
- return true;
205
- }
206
- }
207
- return false;
208
- },
209
-
210
- isMarkdownType(contentType) {
211
- if (contentType) {
212
- if (contentType === 'text/markdown' || contentType === 'markdown') {
213
- return true;
214
- }
215
- }
216
- return false;
217
- },
218
-
219
- isTextType(contentType) {
220
- if (contentType) {
221
- if (contentType.startsWith('text')) {
222
- return true;
223
- }
224
- if (Util.isMarkdownType(contentType)) {
225
- return true;
226
- }
227
- if (Util.isJsonType(contentType)) {
228
- return true;
229
- }
230
- }
231
- return false;
232
- },
233
-
234
- // =============================================================================
235
- // svg
236
-
237
- dFixed: (num, fixed = 1) => {
238
- if (Number.isInteger(num)) {
239
- return num;
240
- }
241
- return Util.toNum(Util.toNum(num).toFixed(fixed));
242
- },
243
-
244
- pxFixed: (num) => {
245
- const floor = Math.floor(num);
246
- if (num < floor + 0.5) {
247
- return floor + 0.5;
248
- }
249
- return floor + 1.5;
250
- },
251
-
252
- point: (px, py) => {
253
- return `${Util.dFixed(px)},${Util.dFixed(py)}`;
254
- },
255
-
256
- // =============================================================================
257
- // formatter
258
-
259
- // number
260
- NF: function(v) {
261
- if (typeof v === 'number' && v) {
262
- return v.toLocaleString();
263
- }
264
- return v;
265
- },
266
-
267
- // percent
268
- PF: function(v, t = 1, digits = 1, unit = '%', space = '') {
269
- v = Util.toNum(v);
270
- t = Util.toNum(t);
271
- let per = 0;
272
- if (t) {
273
- per = v / t;
274
- }
275
- const perStr = (per * 100).toFixed(digits);
276
- if (unit) {
277
- return perStr + space + unit;
278
- }
279
- return parseFloat(perStr);
280
- },
281
-
282
- PSF: function(v, t = 1, digits = 1) {
283
- return Util.PF(v, t, digits, '%', ' ');
284
- },
285
-
286
- PNF: function(v, t = 1, digits = 1) {
287
- return Util.PF(v, t, digits, '');
288
- },
289
-
290
- // byte
291
- BF: function(v, places = 1, space = '') {
292
- v = Util.toNum(v, true);
293
- if (v === 0) {
294
- return `0${space}B`;
295
- }
296
- let prefix = '';
297
- if (v < 0) {
298
- v = Math.abs(v);
299
- prefix = '-';
300
- }
301
-
302
- const base = 1024;
303
- const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
304
- for (let i = 0, l = units.length; i < l; i++) {
305
- const min = Math.pow(base, i);
306
- const max = Math.pow(base, i + 1);
307
- if (v > min && v < max) {
308
- const unit = units[i];
309
- v = prefix + (v / min).toFixed(places) + space + unit;
310
- break;
311
- }
312
- }
313
- return v;
314
- },
315
-
316
- BSF: function(v, places = 1) {
317
- return Util.BF(v, places, ' ');
318
- },
319
-
320
- // time
321
- TF: function(v, space = '') {
322
- const ms = Util.toNum(v, true);
323
-
324
- if (ms < 1000) {
325
- return `${ms}${space}ms`;
326
- }
327
-
328
- if (ms < 60 * 1000) {
329
- const ss = Math.floor(ms / 1000);
330
- const sms = Math.round((ms - ss * 1000) / 100);
331
- if (sms) {
332
- return `${ss}.${sms}${space}s`;
333
- }
334
- return `${ss}${space}s`;
335
- }
336
-
337
- const s = Math.round(ms / 1000);
338
-
339
- const m = 60;
340
- const h = m * 60;
341
- const d = h * 24;
342
-
343
- if (s < h) {
344
- const minutes = Math.floor(s / m);
345
- const seconds = s - minutes * m;
346
- return `${minutes}${space}m ${seconds}${space}s`;
347
- }
348
-
349
- if (s < d) {
350
- const hours = Math.floor(s / h);
351
- const minutes = Math.floor((s - hours * h) / m);
352
- const seconds = s - hours * h - minutes * m;
353
- return `${hours}${space}h ${minutes}${space}m ${seconds}${space}s`;
354
- }
355
-
356
- const days = Math.floor(s / d);
357
- const hours = Math.floor((s - days * d) / h);
358
- const minutes = Math.floor((s - days * d - hours * h) / m);
359
- const seconds = s - days * d - hours * h - minutes * m;
360
- return `${days}${space}d ${hours}${space}h ${minutes}${space}m ${seconds}${space}s`;
361
- },
362
-
363
- TSF: function(v) {
364
- return Util.TF(v, ' ');
365
- }
366
- };
367
-
368
-
369
- module.exports = Util;
1
+ const Util = {
2
+
3
+ // definition
4
+ tagPattern: /(\s*)@([^@\s]+)(\s*)/g,
5
+
6
+ attachments: {
7
+ audit: {
8
+ name: 'audit',
9
+ contentType: 'text/html',
10
+ reportFile: 'audit-report.json'
11
+ },
12
+ coverage: {
13
+ name: 'coverage',
14
+ contentType: 'text/html',
15
+ reportFile: 'coverage-report.json'
16
+ },
17
+ network: {
18
+ name: 'network',
19
+ contentType: 'text/html',
20
+ reportFile: 'network-report.json'
21
+ },
22
+ metadata: {
23
+ name: 'metadata',
24
+ contentType: 'application/json'
25
+ }
26
+ },
27
+
28
+ pageTimings: [{
29
+ key: 'onContentLoad',
30
+ name: 'Content Loaded',
31
+ color: '#1a1aa6'
32
+ }, {
33
+ key: 'onLoad',
34
+ name: 'Page Loaded',
35
+ color: '#c80000'
36
+ }],
37
+
38
+ timings: [{
39
+ key: 'blocked',
40
+ name: 'Blocking',
41
+ color: '#858585'
42
+ }, {
43
+ key: 'dns',
44
+ name: 'DNS Lookup',
45
+ color: '#009688'
46
+ }, {
47
+ key: 'connect',
48
+ name: 'Connecting',
49
+ color: '#b52dcd'
50
+ }, {
51
+ key: 'send',
52
+ name: 'Sending',
53
+ color: '#74979a'
54
+ }, {
55
+ key: 'wait',
56
+ name: 'Waiting',
57
+ color: '#00a846'
58
+ }, {
59
+ key: 'receive',
60
+ name: 'Receiving',
61
+ color: '#0299de'
62
+ }],
63
+
64
+ hasOwn: function(obj, key) {
65
+ return Object.prototype.hasOwnProperty.call(obj, key);
66
+ },
67
+
68
+ isNull: function(input) {
69
+ if (input === null || typeof input === 'undefined') {
70
+ return true;
71
+ }
72
+ return false;
73
+ },
74
+
75
+ uid: function(len = 20, prefix = '') {
76
+ const dict = '0123456789abcdefghijklmnopqrstuvwxyz';
77
+ const dictLen = dict.length;
78
+ let str = prefix;
79
+ while (len--) {
80
+ str += dict[Math.random() * dictLen | 0];
81
+ }
82
+ return str;
83
+ },
84
+
85
+ zero: function(s, l = 2) {
86
+ s = `${s}`;
87
+ return s.padStart(l, '0');
88
+ },
89
+
90
+ toNum: function(num, toInt) {
91
+ if (typeof (num) !== 'number') {
92
+ num = parseFloat(num);
93
+ }
94
+ if (isNaN(num)) {
95
+ num = 0;
96
+ }
97
+ if (toInt) {
98
+ num = Math.round(num);
99
+ }
100
+ return num;
101
+ },
102
+
103
+ isList: function(data) {
104
+ if (data && data instanceof Array && data.length > 0) {
105
+ return true;
106
+ }
107
+ return false;
108
+ },
109
+
110
+ forEach: function(rootList, callback) {
111
+ const isBreak = (res) => {
112
+ return res === 'break' || res === false;
113
+ };
114
+ const forList = (list, parent) => {
115
+ if (!Util.isList(list)) {
116
+ return;
117
+ }
118
+ for (const item of list) {
119
+ const result = callback(item, parent);
120
+ if (isBreak(result)) {
121
+ return result;
122
+ }
123
+ const subResult = forList(item.subs, item);
124
+ if (isBreak(subResult)) {
125
+ return subResult;
126
+ }
127
+ }
128
+ };
129
+ forList(rootList);
130
+ },
131
+
132
+ // \ to /
133
+ formatPath: function(str) {
134
+ if (str) {
135
+ str = str.replace(/\\/g, '/');
136
+ }
137
+ return str;
138
+ },
139
+
140
+ getCurrentTrendInfo: (data) => {
141
+
142
+ const {
143
+ date, duration, summary
144
+ } = data;
145
+
146
+ const info = {
147
+ date,
148
+ duration
149
+ };
150
+
151
+ Object.keys(summary).forEach((k) => {
152
+ const item = summary[k];
153
+ info[k] = item.value;
154
+ });
155
+
156
+ return info;
157
+ },
158
+
159
+ isTagItem: (item) => {
160
+
161
+ // new syntax in playwright v1.42
162
+ if (item.tags) {
163
+ return true;
164
+ }
165
+
166
+ if (item.type === 'case' || (item.type === 'suite' && item.suiteType === 'describe')) {
167
+ return true;
168
+ }
169
+ return false;
170
+ },
171
+
172
+ delay: function(ms) {
173
+ return new Promise((resolve) => {
174
+ if (ms) {
175
+ setTimeout(resolve, ms);
176
+ } else {
177
+ setImmediate(resolve);
178
+ }
179
+ });
180
+ },
181
+
182
+ // =============================================================================
183
+
184
+ generatePercentChart: function(percent) {
185
+ return `<div style="--mcr-percent:${percent}%;" class="mcr-percent-chart"></div>`;
186
+ },
187
+
188
+ getStatus: (value, watermarks) => {
189
+ if (!watermarks) {
190
+ return 'unknown';
191
+ }
192
+ if (value < watermarks[0]) {
193
+ return 'low';
194
+ }
195
+ if (value < watermarks[1]) {
196
+ return 'medium';
197
+ }
198
+ return 'high';
199
+ },
200
+
201
+ isJsonType(contentType) {
202
+ if (contentType) {
203
+ if (contentType === 'application/json' || contentType === 'json') {
204
+ return true;
205
+ }
206
+ }
207
+ return false;
208
+ },
209
+
210
+ isMarkdownType(contentType) {
211
+ if (contentType) {
212
+ if (contentType === 'text/markdown' || contentType === 'markdown') {
213
+ return true;
214
+ }
215
+ }
216
+ return false;
217
+ },
218
+
219
+ isTextType(contentType) {
220
+ if (contentType) {
221
+ if (contentType.startsWith('text')) {
222
+ return true;
223
+ }
224
+ if (Util.isMarkdownType(contentType)) {
225
+ return true;
226
+ }
227
+ if (Util.isJsonType(contentType)) {
228
+ return true;
229
+ }
230
+ }
231
+ return false;
232
+ },
233
+
234
+ // =============================================================================
235
+ // svg
236
+
237
+ dFixed: (num, fixed = 1) => {
238
+ if (Number.isInteger(num)) {
239
+ return num;
240
+ }
241
+ return Util.toNum(Util.toNum(num).toFixed(fixed));
242
+ },
243
+
244
+ pxFixed: (num) => {
245
+ const floor = Math.floor(num);
246
+ if (num < floor + 0.5) {
247
+ return floor + 0.5;
248
+ }
249
+ return floor + 1.5;
250
+ },
251
+
252
+ point: (px, py) => {
253
+ return `${Util.dFixed(px)},${Util.dFixed(py)}`;
254
+ },
255
+
256
+ // =============================================================================
257
+ // formatter
258
+
259
+ // number
260
+ NF: function(v) {
261
+ if (typeof v === 'number' && v) {
262
+ return v.toLocaleString();
263
+ }
264
+ return v;
265
+ },
266
+
267
+ // percent
268
+ PF: function(v, t = 1, digits = 1, unit = '%', space = '') {
269
+ v = Util.toNum(v);
270
+ t = Util.toNum(t);
271
+ let per = 0;
272
+ if (t) {
273
+ per = v / t;
274
+ }
275
+ const perStr = (per * 100).toFixed(digits);
276
+ if (unit) {
277
+ return perStr + space + unit;
278
+ }
279
+ return parseFloat(perStr);
280
+ },
281
+
282
+ PSF: function(v, t = 1, digits = 1) {
283
+ return Util.PF(v, t, digits, '%', ' ');
284
+ },
285
+
286
+ PNF: function(v, t = 1, digits = 1) {
287
+ return Util.PF(v, t, digits, '');
288
+ },
289
+
290
+ // byte
291
+ BF: function(v, places = 1, space = '') {
292
+ v = Util.toNum(v, true);
293
+ if (v === 0) {
294
+ return `0${space}B`;
295
+ }
296
+ let prefix = '';
297
+ if (v < 0) {
298
+ v = Math.abs(v);
299
+ prefix = '-';
300
+ }
301
+
302
+ const base = 1024;
303
+ const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
304
+ for (let i = 0, l = units.length; i < l; i++) {
305
+ const min = Math.pow(base, i);
306
+ const max = Math.pow(base, i + 1);
307
+ if (v > min && v < max) {
308
+ const unit = units[i];
309
+ v = prefix + (v / min).toFixed(places) + space + unit;
310
+ break;
311
+ }
312
+ }
313
+ return v;
314
+ },
315
+
316
+ BSF: function(v, places = 1) {
317
+ return Util.BF(v, places, ' ');
318
+ },
319
+
320
+ // time
321
+ TF: function(v, space = '') {
322
+ const ms = Util.toNum(v, true);
323
+
324
+ if (ms < 1000) {
325
+ return `${ms}${space}ms`;
326
+ }
327
+
328
+ if (ms < 60 * 1000) {
329
+ const ss = Math.floor(ms / 1000);
330
+ const sms = Math.round((ms - ss * 1000) / 100);
331
+ if (sms) {
332
+ return `${ss}.${sms}${space}s`;
333
+ }
334
+ return `${ss}${space}s`;
335
+ }
336
+
337
+ const s = Math.round(ms / 1000);
338
+
339
+ const m = 60;
340
+ const h = m * 60;
341
+ const d = h * 24;
342
+
343
+ if (s < h) {
344
+ const minutes = Math.floor(s / m);
345
+ const seconds = s - minutes * m;
346
+ return `${minutes}${space}m ${seconds}${space}s`;
347
+ }
348
+
349
+ if (s < d) {
350
+ const hours = Math.floor(s / h);
351
+ const minutes = Math.floor((s - hours * h) / m);
352
+ const seconds = s - hours * h - minutes * m;
353
+ return `${hours}${space}h ${minutes}${space}m ${seconds}${space}s`;
354
+ }
355
+
356
+ const days = Math.floor(s / d);
357
+ const hours = Math.floor((s - days * d) / h);
358
+ const minutes = Math.floor((s - days * d - hours * h) / m);
359
+ const seconds = s - days * d - hours * h - minutes * m;
360
+ return `${days}${space}d ${hours}${space}h ${minutes}${space}m ${seconds}${space}s`;
361
+ },
362
+
363
+ TSF: function(v) {
364
+ return Util.TF(v, ' ');
365
+ }
366
+ };
367
+
368
+
369
+ module.exports = Util;