@testomatio/reporter 2.24.0 → 2.26.0

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.
@@ -51,6 +51,7 @@ function CodeceptReporter(config) {
51
51
  let traces = [];
52
52
  const reportTestPromises = [];
53
53
  let isRunFinalized = false;
54
+ let isWorkersMode = false;
54
55
  const testTimeMap = {};
55
56
  const failedUrls = new Map();
56
57
  const clientConfig = buildCodeceptClientConfig(config);
@@ -91,6 +92,7 @@ function CodeceptReporter(config) {
91
92
  await client.updateRunStatus('finished');
92
93
  };
93
94
  event.dispatcher.on(event.workers.before, () => {
95
+ isWorkersMode = true;
94
96
  recorder.add('Creating new run', async () => {
95
97
  await client.createRun();
96
98
  process.env.TESTOMATIO_RUN = client.runId;
@@ -157,6 +159,7 @@ function CodeceptReporter(config) {
157
159
  suite_title: stripTagsFromTitle(suite.title),
158
160
  error,
159
161
  time: hook?.runnable?.duration,
162
+ outputDir: hook.outputDir || test.outputDir,
160
163
  });
161
164
  reportTestPromises.push(reportTestPromise);
162
165
  }
@@ -174,6 +177,7 @@ function CodeceptReporter(config) {
174
177
  suite_title: stripTagsFromTitle(suite.title),
175
178
  error,
176
179
  time: hook?.runnable?.duration,
180
+ outputDir: hook.outputDir || test.outputDir,
177
181
  });
178
182
  reportTestPromises.push(reportTestPromise);
179
183
  }
@@ -190,6 +194,7 @@ function CodeceptReporter(config) {
190
194
  message: error?.message || 'AfterSuite hook failed',
191
195
  steps: stepHierarchy,
192
196
  time: hook?.runnable?.duration,
197
+ outputDir: hook.outputDir,
193
198
  });
194
199
  reportTestPromises.push(reportTestPromise);
195
200
  }
@@ -243,6 +248,7 @@ function CodeceptReporter(config) {
243
248
  suite_title: test.parent && stripTagsFromTitle(stripExampleFromTitle(test.parent.title).title),
244
249
  time: test.duration,
245
250
  meta: test.meta,
251
+ outputDir: test.outputDir,
246
252
  });
247
253
  reportTestPromises.push(reportTestPromise);
248
254
  reportedTestUids.add(uid);
@@ -254,7 +260,7 @@ function CodeceptReporter(config) {
254
260
  failedTests.push(uid || title);
255
261
  const testObj = getTestAndMessage(title);
256
262
  const files = buildArtifactFiles(artifacts);
257
- const logs = getTestLogs(test);
263
+ const logs = getTestLogs(test, isWorkersMode);
258
264
  const manuallyAttachedArtifacts = index_js_1.services.artifacts.get(test.fullTitle());
259
265
  const keyValues = index_js_1.services.keyValues.get(test.fullTitle());
260
266
  const links = index_js_1.services.links.get(test.fullTitle());
@@ -280,11 +286,14 @@ function CodeceptReporter(config) {
280
286
  links,
281
287
  manuallyAttachedArtifacts,
282
288
  meta,
289
+ outputDir: test.outputDir,
283
290
  });
284
291
  reportTestPromises.push(reportTestPromise);
285
292
  processArtifactsForUpload(artifacts, uid, title, videos, traces);
286
293
  });
287
294
  event.dispatcher.on(event.step.started, step => {
295
+ if (isWorkersMode)
296
+ return;
288
297
  const stepText = `${repeat(output.stepShift)} ${formatStepLog(step)}`;
289
298
  data_storage_js_1.dataStorage.putData('log', stepText);
290
299
  });
@@ -437,18 +446,22 @@ function captureHookStep(step, currentHook, hookSteps) {
437
446
  hookSteps.set(currentHook, hookStepsArray);
438
447
  }
439
448
  // TODO: think about moving to some common utils
440
- function getTestLogs(test) {
449
+ function getTestLogs(test, isWorkersMode = false) {
441
450
  // Contexts for each log section
442
451
  const suiteTitle = test.parent.fullTitle();
443
452
  const testTitle = test.fullTitle();
444
453
  const beforeSuiteLogsArr = index_js_1.services.logger.getLogs(`BeforeSuite ${suiteTitle}`);
445
454
  const beforeLogsArr = index_js_1.services.logger.getLogs(`Before ${testTitle}`);
446
- const testLogsArr = index_js_1.services.logger.getLogs(testTitle);
455
+ const testLogsArr = isWorkersMode ? null : index_js_1.services.logger.getLogs(testTitle);
447
456
  const afterLogsArr = index_js_1.services.logger.getLogs(`After ${testTitle}`);
448
457
  const afterSuiteLogsArr = index_js_1.services.logger.getLogs(`AfterSuite ${suiteTitle}`);
449
458
  const beforeSuiteLogs = beforeSuiteLogsArr ? beforeSuiteLogsArr.join('\n').trim() : '';
450
459
  const beforeLogs = beforeLogsArr ? beforeLogsArr.join('\n').trim() : '';
451
- const testLogs = testLogsArr ? testLogsArr.join('\n').trim() : '';
460
+ const testLogs = isWorkersMode
461
+ ? (test.steps || []).map(step => formatStepLog(step)).join('\n').trim()
462
+ : testLogsArr
463
+ ? testLogsArr.join('\n').trim()
464
+ : '';
452
465
  const afterLogs = afterLogsArr ? afterLogsArr.join('\n').trim() : '';
453
466
  const afterSuiteLogs = afterSuiteLogsArr ? afterSuiteLogsArr.join('\n').trim() : '';
454
467
  let logs = '';
package/lib/client.js CHANGED
@@ -201,7 +201,7 @@ class Client {
201
201
  /**
202
202
  * @type {TestData}
203
203
  */
204
- const { rid, error = null, steps: originalSteps, title, suite_title } = testData;
204
+ const { rid, error = null, steps: originalSteps, title, suite_title, outputDir } = testData;
205
205
  let steps = originalSteps;
206
206
  // Capture step artifact paths BEFORE uploadStepArtifacts mutates them to URLs,
207
207
  // so we can exclude them from the test-level artifacts list later.
@@ -309,6 +309,7 @@ class Client {
309
309
  links,
310
310
  overwrite,
311
311
  tags,
312
+ ...(outputDir && { outputDir }),
312
313
  ...(rootSuiteId && { root_suite_id: rootSuiteId }),
313
314
  };
314
315
  // debug('Adding test run...', data);
@@ -26,6 +26,7 @@ declare class HtmlPipe {
26
26
  */
27
27
  addTest(test: import("../../types/types.js").HtmlTestData): void;
28
28
  finishRun(runParams: any): Promise<void>;
29
+ getExecutionTime(tests: any): string;
29
30
  /**
30
31
  * Generates an HTML report based on provided test data and a template.
31
32
  * @param {object} opts - Test options used to generate the HTML report:
package/lib/pipe/html.js CHANGED
@@ -99,7 +99,10 @@ class HtmlPipe {
99
99
  async finishRun(runParams) {
100
100
  if (!this.isEnabled)
101
101
  return;
102
- if (this.isHtml) {
102
+ if (!this.isHtml)
103
+ return;
104
+ const runs = groupTestsByRunFolder(this.tests);
105
+ if (runs.length === 1 && !runs[0].outputDir) {
103
106
  // GENERATE HTML reports based on the results data
104
107
  this.buildReport({
105
108
  runParams,
@@ -109,7 +112,29 @@ class HtmlPipe {
109
112
  templatePath: this.templateHtmlPath,
110
113
  warningMsg: this.filenameMsg,
111
114
  });
115
+ return;
112
116
  }
117
+ for (const { outputDir, tests } of runs) {
118
+ const reportDir = outputDir
119
+ ? path_1.default.join(outputDir, path_1.default.basename(this.htmlReportDir) || constants_js_1.HTML_REPORT.FOLDER)
120
+ : this.htmlReportDir;
121
+ utils_js_1.fileSystem.createDir(reportDir);
122
+ this.buildReport({
123
+ runParams,
124
+ tests,
125
+ outputPath: path_1.default.join(reportDir, this.htmlReportName),
126
+ templatePath: this.templateHtmlPath,
127
+ warningMsg: this.filenameMsg,
128
+ });
129
+ }
130
+ }
131
+ getExecutionTime(tests) {
132
+ if (this.startedAt) {
133
+ const durationMs = Date.now() - this.startedAt.getTime();
134
+ if (durationMs >= 0)
135
+ return formatDuration(durationMs);
136
+ }
137
+ return testExecutionSumTime(tests);
113
138
  }
114
139
  /**
115
140
  * Generates an HTML report based on provided test data and a template.
@@ -217,7 +242,7 @@ class HtmlPipe {
217
242
  status: runParams.status || 'No status info',
218
243
  parallel: runParams.isParallel || 'No parallel info',
219
244
  runUrl: this.store.runUrl || '',
220
- executionTime: testExecutionSumTime(aggregatedTests),
245
+ executionTime: this.getExecutionTime(aggregatedTests),
221
246
  executionDate: getDateTimeFormatted(this.startedAt || new Date()),
222
247
  description: [this.description, runParams.description || this.store.coverageDescription || this.store.description]
223
248
  .filter(Boolean)
@@ -587,6 +612,17 @@ function normalizeRetries(test) {
587
612
  const metaFlaky = test.meta?.flaky === true || test.meta?.isFlaky === true;
588
613
  test.flaky = Boolean(metaFlaky || passedAfterRetries);
589
614
  }
615
+ function groupTestsByRunFolder(tests) {
616
+ const groups = new Map();
617
+ for (const test of tests) {
618
+ const key = test.outputDir || null;
619
+ if (!groups.has(key))
620
+ groups.set(key, []);
621
+ const { outputDir, ...testData } = test;
622
+ groups.get(key).push(testData);
623
+ }
624
+ return [...groups.entries()].map(([outputDir, groupTests]) => ({ outputDir, tests: groupTests }));
625
+ }
590
626
  /**
591
627
  * Formats duration in milliseconds into a human-readable string representation.
592
628
  * @param {number} duration - The duration in milliseconds.
@@ -40,6 +40,7 @@ declare class TestomatioPipe implements Pipe {
40
40
  sharedRun: boolean;
41
41
  sharedRunShards: number;
42
42
  sharedRunTimeout: number;
43
+ terminationProtectionTimeout: number;
43
44
  groupTitle: any;
44
45
  env: string;
45
46
  label: string;
@@ -84,6 +84,9 @@ class TestomatioPipe {
84
84
  this.sharedRunTimeout = process.env.TESTOMATIO_SHARED_RUN_TIMEOUT
85
85
  ? parseInt(process.env.TESTOMATIO_SHARED_RUN_TIMEOUT, 10)
86
86
  : undefined;
87
+ this.terminationProtectionTimeout = process.env.TESTOMATIO_TERMINATION_PROTECTION_TIMEOUT
88
+ ? parseInt(process.env.TESTOMATIO_TERMINATION_PROTECTION_TIMEOUT, 10) || undefined
89
+ : undefined;
87
90
  if ((this.sharedRunTimeout || this.sharedRunShards) && !this.sharedRun) {
88
91
  debug('Auto-enabling sharedRun because sharedRunTimeout or sharedRunShards is set');
89
92
  this.sharedRun = true;
@@ -301,6 +304,7 @@ class TestomatioPipe {
301
304
  shared_run: this.sharedRun,
302
305
  shared_run_timeout: this.sharedRunTimeout,
303
306
  shared_run_shards: this.sharedRunShards,
307
+ termination_protection_timeout: this.terminationProtectionTimeout,
304
308
  kind: params.kind,
305
309
  status: params.status,
306
310
  configuration,
@@ -2527,13 +2527,22 @@
2527
2527
  google.charts.load('current', {'packages':['corechart']});
2528
2528
  google.charts.setOnLoadCallback(drawTestChart);
2529
2529
 
2530
+ function escapeHtml(text) {
2531
+ return String(text)
2532
+ .replaceAll('&', '&amp;')
2533
+ .replaceAll('<', '&lt;')
2534
+ .replaceAll('>', '&gt;')
2535
+ .replaceAll('"', '&quot;')
2536
+ .replaceAll("'", '&#39;');
2537
+ }
2538
+
2530
2539
  function createMetadataItems(metadata) {
2531
2540
  if (!metadata || Object.keys(metadata).length === 0) return '';
2532
2541
 
2533
2542
  return Object.entries(metadata).map(([key, value]) => `
2534
- <div class='metadata-item meta-item' data-meta-key='${key}'>
2535
- <div class='metadata-key'>${key}</div>
2536
- <div class='metadata-value'>${typeof value === 'object' ? JSON.stringify(value, null, 2) : value}</div>
2543
+ <div class='metadata-item meta-item' data-meta-key='${escapeHtml(key)}'>
2544
+ <div class='metadata-key'>${escapeHtml(key)}</div>
2545
+ <div class='metadata-value'>${typeof value === 'object' ? escapeHtml(JSON.stringify(value, null, 2)) : escapeHtml(value)}</div>
2537
2546
  </div>
2538
2547
  `).join('');
2539
2548
  }
@@ -2791,7 +2800,7 @@
2791
2800
  </div>
2792
2801
  </div>` : ''}
2793
2802
  ${Object.keys(test.meta || {}).length > 0 ? `<div class='test-tab-content' data-tab='metadata'>
2794
- <div class='metadata-grid' data-test-meta></div>
2803
+ <div class='metadata-grid' data-test-meta>${createMetadataItems(test.meta)}</div>
2795
2804
  </div>` : ''}
2796
2805
  ${hasTraces ? `<div class='test-tab-content' data-tab='traces'>
2797
2806
  <div class='trace-viewer-container'></div>
@@ -3378,35 +3387,11 @@
3378
3387
  setTimeout(populateMetadataFields, 50);
3379
3388
  }
3380
3389
 
3390
+ // Metadata is rendered inline by createTestItem (which has the test object in hand),
3391
+ // so after each re-render we only need to reapply the visibility settings.
3392
+ // Looking the test up in allTests by data-test-index is incorrect here:
3393
+ // the index is local to the group/filtered list, not the position in allTests (#993).
3381
3394
  function populateMetadataFields() {
3382
- const metaGrids = document.querySelectorAll('[data-test-meta]');
3383
- metaGrids.forEach(grid => {
3384
- const testItem = grid.closest('.test-item');
3385
- if (!testItem) return;
3386
-
3387
- const testIndex = parseInt(testItem.getAttribute('data-test-index'));
3388
- const test = allTests[testIndex];
3389
- if (!test || !test.meta) return;
3390
-
3391
- Object.entries(test.meta).forEach(([key, value]) => {
3392
- const metaItem = document.createElement('div');
3393
- metaItem.className = 'metadata-item meta-item';
3394
- metaItem.setAttribute('data-meta-key', key);
3395
-
3396
- const keyDiv = document.createElement('div');
3397
- keyDiv.className = 'metadata-key';
3398
- keyDiv.textContent = key;
3399
-
3400
- const valueDiv = document.createElement('div');
3401
- valueDiv.className = 'metadata-value';
3402
- valueDiv.textContent = typeof value === 'object' ? JSON.stringify(value, null, 2) : value;
3403
-
3404
- metaItem.appendChild(keyDiv);
3405
- metaItem.appendChild(valueDiv);
3406
- grid.appendChild(metaItem);
3407
- });
3408
- });
3409
-
3410
3395
  setTimeout(applyMetaVisibility, 10);
3411
3396
  }
3412
3397
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testomatio/reporter",
3
- "version": "2.24.0",
3
+ "version": "2.26.0",
4
4
  "description": "Testomatio Reporter Client",
5
5
  "engines": {
6
6
  "node": ">=22"
@@ -57,6 +57,7 @@ function CodeceptReporter(config) {
57
57
  let traces = [];
58
58
  const reportTestPromises = [];
59
59
  let isRunFinalized = false;
60
+ let isWorkersMode = false;
60
61
 
61
62
  const testTimeMap = {};
62
63
  const failedUrls = new Map();
@@ -107,6 +108,7 @@ function CodeceptReporter(config) {
107
108
  };
108
109
 
109
110
  event.dispatcher.on(event.workers.before, () => {
111
+ isWorkersMode = true;
110
112
  recorder.add('Creating new run', async () => {
111
113
  await client.createRun();
112
114
  process.env.TESTOMATIO_RUN = client.runId;
@@ -178,6 +180,7 @@ function CodeceptReporter(config) {
178
180
  suite_title: stripTagsFromTitle(suite.title),
179
181
  error,
180
182
  time: hook?.runnable?.duration,
183
+ outputDir: hook.outputDir || test.outputDir,
181
184
  });
182
185
  reportTestPromises.push(reportTestPromise);
183
186
  }
@@ -196,6 +199,7 @@ function CodeceptReporter(config) {
196
199
  suite_title: stripTagsFromTitle(suite.title),
197
200
  error,
198
201
  time: hook?.runnable?.duration,
202
+ outputDir: hook.outputDir || test.outputDir,
199
203
  });
200
204
  reportTestPromises.push(reportTestPromise);
201
205
  }
@@ -215,6 +219,7 @@ function CodeceptReporter(config) {
215
219
  message: error?.message || 'AfterSuite hook failed',
216
220
  steps: stepHierarchy,
217
221
  time: hook?.runnable?.duration,
222
+ outputDir: hook.outputDir,
218
223
  });
219
224
  reportTestPromises.push(reportTestPromise);
220
225
  }
@@ -274,6 +279,7 @@ function CodeceptReporter(config) {
274
279
  suite_title: test.parent && stripTagsFromTitle(stripExampleFromTitle(test.parent.title).title),
275
280
  time: test.duration,
276
281
  meta: test.meta,
282
+ outputDir: test.outputDir,
277
283
  });
278
284
  reportTestPromises.push(reportTestPromise);
279
285
  reportedTestUids.add(uid);
@@ -286,7 +292,7 @@ function CodeceptReporter(config) {
286
292
  failedTests.push(uid || title);
287
293
  const testObj = getTestAndMessage(title);
288
294
  const files = buildArtifactFiles(artifacts);
289
- const logs = getTestLogs(test);
295
+ const logs = getTestLogs(test, isWorkersMode);
290
296
  const manuallyAttachedArtifacts = services.artifacts.get(test.fullTitle());
291
297
  const keyValues = services.keyValues.get(test.fullTitle());
292
298
  const links = services.links.get(test.fullTitle());
@@ -318,6 +324,7 @@ function CodeceptReporter(config) {
318
324
  links,
319
325
  manuallyAttachedArtifacts,
320
326
  meta,
327
+ outputDir: test.outputDir,
321
328
  });
322
329
  reportTestPromises.push(reportTestPromise);
323
330
 
@@ -325,6 +332,7 @@ function CodeceptReporter(config) {
325
332
  });
326
333
 
327
334
  event.dispatcher.on(event.step.started, step => {
335
+ if (isWorkersMode) return;
328
336
  const stepText = `${repeat(output.stepShift)} ${formatStepLog(step)}`;
329
337
  dataStorage.putData('log', stepText);
330
338
  });
@@ -494,19 +502,23 @@ function captureHookStep(step, currentHook, hookSteps) {
494
502
  }
495
503
 
496
504
  // TODO: think about moving to some common utils
497
- function getTestLogs(test) {
505
+ function getTestLogs(test, isWorkersMode = false) {
498
506
  // Contexts for each log section
499
507
  const suiteTitle = test.parent.fullTitle();
500
508
  const testTitle = test.fullTitle();
501
509
  const beforeSuiteLogsArr = services.logger.getLogs(`BeforeSuite ${suiteTitle}`);
502
510
  const beforeLogsArr = services.logger.getLogs(`Before ${testTitle}`);
503
- const testLogsArr = services.logger.getLogs(testTitle);
511
+ const testLogsArr = isWorkersMode ? null : services.logger.getLogs(testTitle);
504
512
  const afterLogsArr = services.logger.getLogs(`After ${testTitle}`);
505
513
  const afterSuiteLogsArr = services.logger.getLogs(`AfterSuite ${suiteTitle}`);
506
514
 
507
515
  const beforeSuiteLogs = beforeSuiteLogsArr ? beforeSuiteLogsArr.join('\n').trim() : '';
508
516
  const beforeLogs = beforeLogsArr ? beforeLogsArr.join('\n').trim() : '';
509
- const testLogs = testLogsArr ? testLogsArr.join('\n').trim() : '';
517
+ const testLogs = isWorkersMode
518
+ ? (test.steps || []).map(step => formatStepLog(step)).join('\n').trim()
519
+ : testLogsArr
520
+ ? testLogsArr.join('\n').trim()
521
+ : '';
510
522
  const afterLogs = afterLogsArr ? afterLogsArr.join('\n').trim() : '';
511
523
  const afterSuiteLogs = afterSuiteLogsArr ? afterSuiteLogsArr.join('\n').trim() : '';
512
524
 
package/src/client.js CHANGED
@@ -216,7 +216,7 @@ class Client {
216
216
  /**
217
217
  * @type {TestData}
218
218
  */
219
- const { rid, error = null, steps: originalSteps, title, suite_title } = testData;
219
+ const { rid, error = null, steps: originalSteps, title, suite_title, outputDir } = testData;
220
220
  let steps = originalSteps;
221
221
 
222
222
  // Capture step artifact paths BEFORE uploadStepArtifacts mutates them to URLs,
@@ -353,6 +353,7 @@ class Client {
353
353
  links,
354
354
  overwrite,
355
355
  tags,
356
+ ...(outputDir && { outputDir }),
356
357
  ...(rootSuiteId && { root_suite_id: rootSuiteId }),
357
358
  };
358
359
 
package/src/pipe/html.js CHANGED
@@ -120,7 +120,10 @@ class HtmlPipe {
120
120
  async finishRun(runParams) {
121
121
  if (!this.isEnabled) return;
122
122
 
123
- if (this.isHtml) {
123
+ if (!this.isHtml) return;
124
+
125
+ const runs = groupTestsByRunFolder(this.tests);
126
+ if (runs.length === 1 && !runs[0].outputDir) {
124
127
  // GENERATE HTML reports based on the results data
125
128
  this.buildReport({
126
129
  runParams,
@@ -130,7 +133,30 @@ class HtmlPipe {
130
133
  templatePath: this.templateHtmlPath,
131
134
  warningMsg: this.filenameMsg,
132
135
  });
136
+ return;
137
+ }
138
+
139
+ for (const { outputDir, tests } of runs) {
140
+ const reportDir = outputDir
141
+ ? path.join(outputDir, path.basename(this.htmlReportDir) || HTML_REPORT.FOLDER)
142
+ : this.htmlReportDir;
143
+ fileSystem.createDir(reportDir);
144
+ this.buildReport({
145
+ runParams,
146
+ tests,
147
+ outputPath: path.join(reportDir, this.htmlReportName),
148
+ templatePath: this.templateHtmlPath,
149
+ warningMsg: this.filenameMsg,
150
+ });
151
+ }
152
+ }
153
+
154
+ getExecutionTime(tests) {
155
+ if (this.startedAt) {
156
+ const durationMs = Date.now() - this.startedAt.getTime();
157
+ if (durationMs >= 0) return formatDuration(durationMs);
133
158
  }
159
+ return testExecutionSumTime(tests);
134
160
  }
135
161
  /**
136
162
  * Generates an HTML report based on provided test data and a template.
@@ -269,7 +295,7 @@ class HtmlPipe {
269
295
  status: runParams.status || 'No status info',
270
296
  parallel: runParams.isParallel || 'No parallel info',
271
297
  runUrl: this.store.runUrl || '',
272
- executionTime: testExecutionSumTime(aggregatedTests),
298
+ executionTime: this.getExecutionTime(aggregatedTests),
273
299
  executionDate: getDateTimeFormatted(this.startedAt || new Date()),
274
300
  description:
275
301
  [this.description, runParams.description || this.store.coverageDescription || this.store.description]
@@ -709,6 +735,17 @@ function normalizeRetries(test) {
709
735
  test.flaky = Boolean(metaFlaky || passedAfterRetries);
710
736
  }
711
737
 
738
+ function groupTestsByRunFolder(tests) {
739
+ const groups = new Map();
740
+ for (const test of tests) {
741
+ const key = test.outputDir || null;
742
+ if (!groups.has(key)) groups.set(key, []);
743
+ const { outputDir, ...testData } = test;
744
+ groups.get(key).push(testData);
745
+ }
746
+ return [...groups.entries()].map(([outputDir, groupTests]) => ({ outputDir, tests: groupTests }));
747
+ }
748
+
712
749
  /**
713
750
  * Formats duration in milliseconds into a human-readable string representation.
714
751
  * @param {number} duration - The duration in milliseconds.
@@ -97,6 +97,9 @@ class TestomatioPipe {
97
97
  this.sharedRunTimeout = process.env.TESTOMATIO_SHARED_RUN_TIMEOUT
98
98
  ? parseInt(process.env.TESTOMATIO_SHARED_RUN_TIMEOUT, 10)
99
99
  : undefined;
100
+ this.terminationProtectionTimeout = process.env.TESTOMATIO_TERMINATION_PROTECTION_TIMEOUT
101
+ ? parseInt(process.env.TESTOMATIO_TERMINATION_PROTECTION_TIMEOUT, 10) || undefined
102
+ : undefined;
100
103
 
101
104
  if ((this.sharedRunTimeout || this.sharedRunShards) && !this.sharedRun) {
102
105
  debug('Auto-enabling sharedRun because sharedRunTimeout or sharedRunShards is set');
@@ -334,6 +337,7 @@ class TestomatioPipe {
334
337
  shared_run: this.sharedRun,
335
338
  shared_run_timeout: this.sharedRunTimeout,
336
339
  shared_run_shards: this.sharedRunShards,
340
+ termination_protection_timeout: this.terminationProtectionTimeout,
337
341
  kind: params.kind,
338
342
  status: params.status,
339
343
  configuration,
@@ -2527,13 +2527,22 @@
2527
2527
  google.charts.load('current', {'packages':['corechart']});
2528
2528
  google.charts.setOnLoadCallback(drawTestChart);
2529
2529
 
2530
+ function escapeHtml(text) {
2531
+ return String(text)
2532
+ .replaceAll('&', '&amp;')
2533
+ .replaceAll('<', '&lt;')
2534
+ .replaceAll('>', '&gt;')
2535
+ .replaceAll('"', '&quot;')
2536
+ .replaceAll("'", '&#39;');
2537
+ }
2538
+
2530
2539
  function createMetadataItems(metadata) {
2531
2540
  if (!metadata || Object.keys(metadata).length === 0) return '';
2532
2541
 
2533
2542
  return Object.entries(metadata).map(([key, value]) => `
2534
- <div class='metadata-item meta-item' data-meta-key='${key}'>
2535
- <div class='metadata-key'>${key}</div>
2536
- <div class='metadata-value'>${typeof value === 'object' ? JSON.stringify(value, null, 2) : value}</div>
2543
+ <div class='metadata-item meta-item' data-meta-key='${escapeHtml(key)}'>
2544
+ <div class='metadata-key'>${escapeHtml(key)}</div>
2545
+ <div class='metadata-value'>${typeof value === 'object' ? escapeHtml(JSON.stringify(value, null, 2)) : escapeHtml(value)}</div>
2537
2546
  </div>
2538
2547
  `).join('');
2539
2548
  }
@@ -2791,7 +2800,7 @@
2791
2800
  </div>
2792
2801
  </div>` : ''}
2793
2802
  ${Object.keys(test.meta || {}).length > 0 ? `<div class='test-tab-content' data-tab='metadata'>
2794
- <div class='metadata-grid' data-test-meta></div>
2803
+ <div class='metadata-grid' data-test-meta>${createMetadataItems(test.meta)}</div>
2795
2804
  </div>` : ''}
2796
2805
  ${hasTraces ? `<div class='test-tab-content' data-tab='traces'>
2797
2806
  <div class='trace-viewer-container'></div>
@@ -3378,35 +3387,11 @@
3378
3387
  setTimeout(populateMetadataFields, 50);
3379
3388
  }
3380
3389
 
3390
+ // Metadata is rendered inline by createTestItem (which has the test object in hand),
3391
+ // so after each re-render we only need to reapply the visibility settings.
3392
+ // Looking the test up in allTests by data-test-index is incorrect here:
3393
+ // the index is local to the group/filtered list, not the position in allTests (#993).
3381
3394
  function populateMetadataFields() {
3382
- const metaGrids = document.querySelectorAll('[data-test-meta]');
3383
- metaGrids.forEach(grid => {
3384
- const testItem = grid.closest('.test-item');
3385
- if (!testItem) return;
3386
-
3387
- const testIndex = parseInt(testItem.getAttribute('data-test-index'));
3388
- const test = allTests[testIndex];
3389
- if (!test || !test.meta) return;
3390
-
3391
- Object.entries(test.meta).forEach(([key, value]) => {
3392
- const metaItem = document.createElement('div');
3393
- metaItem.className = 'metadata-item meta-item';
3394
- metaItem.setAttribute('data-meta-key', key);
3395
-
3396
- const keyDiv = document.createElement('div');
3397
- keyDiv.className = 'metadata-key';
3398
- keyDiv.textContent = key;
3399
-
3400
- const valueDiv = document.createElement('div');
3401
- valueDiv.className = 'metadata-value';
3402
- valueDiv.textContent = typeof value === 'object' ? JSON.stringify(value, null, 2) : value;
3403
-
3404
- metaItem.appendChild(keyDiv);
3405
- metaItem.appendChild(valueDiv);
3406
- grid.appendChild(metaItem);
3407
- });
3408
- });
3409
-
3410
3395
  setTimeout(applyMetaVisibility, 10);
3411
3396
  }
3412
3397
 
package/types/types.d.ts CHANGED
@@ -211,6 +211,9 @@ export interface TestData {
211
211
 
212
212
  /** Whether to overwrite status of this test to avoid saving as retry (defaults to false) */
213
213
  overwrite?: boolean;
214
+
215
+ /** Output folder of the run this test belongs to (e.g. set by CodeceptJS run-workers per browser) */
216
+ outputDir?: string;
214
217
  }
215
218
 
216
219
  /**