codeceptjs 3.7.5-beta.5 → 3.7.5-beta.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.
@@ -105,7 +105,7 @@ module.exports = function (config) {
105
105
  output.print(`Failed Tests Tracker: Recorded failed test - ${test.title}`)
106
106
  })
107
107
 
108
- // Save failed tests to file after all tests complete
108
+ // Handle test completion and save failed tests
109
109
  event.dispatcher.on(event.all.result, (result) => {
110
110
  // Respect CodeceptJS output directory like other plugins
111
111
  const outputDir = global.output_dir || './output'
@@ -133,7 +133,7 @@ module.exports = function (config) {
133
133
  const failedTest = {
134
134
  title: test.title,
135
135
  fullTitle: test.fullTitle || test.title,
136
- file: test.file || (test.parent && test.parent.file),
136
+ file: test.file || 'unknown',
137
137
  uid: test.uid,
138
138
  timestamp: new Date().toISOString(),
139
139
  }
@@ -176,6 +176,8 @@ module.exports = function (config) {
176
176
  allFailedTests.push(failedTest)
177
177
  existingTestIds.add(testId)
178
178
  })
179
+
180
+ output.print(`Failed Tests Tracker: Collected ${workerFailedTests.length} failed tests from workers`)
179
181
  }
180
182
 
181
183
  if (allFailedTests.length === 0) {
@@ -222,7 +224,123 @@ module.exports = function (config) {
222
224
 
223
225
  // Handle worker mode - listen to workers.result event for consolidated results
224
226
  event.dispatcher.on(event.workers.result, (result) => {
225
- // This event is fired in worker mode with consolidated results
226
- // The event.all.result handler above will process the consolidated data
227
+ // Respect CodeceptJS output directory like other plugins
228
+ const outputDir = global.output_dir || './output'
229
+ const outputPath = path.isAbsolute(options.outputFile)
230
+ ? options.outputFile
231
+ : path.resolve(outputDir, options.outputFile)
232
+
233
+ let allFailedTests = []
234
+
235
+ // In worker mode, collect failed tests from consolidated result
236
+ if (result && result.tests) {
237
+ const workerFailedTests = result.tests.filter(test => test.state === 'failed' || test.err)
238
+
239
+ workerFailedTests.forEach(test => {
240
+ // Extract file path from test title or error stack trace as fallback
241
+ let filePath = test.file || test.parent?.file || 'unknown'
242
+
243
+ // If still unknown, try to extract from error stack trace
244
+ if (filePath === 'unknown' && test.err && test.err.stack) {
245
+ const stackMatch = test.err.stack.match(/at.*\(([^)]+\.js):\d+:\d+\)/)
246
+ if (stackMatch && stackMatch[1]) {
247
+ // Convert absolute path to relative path
248
+ const absolutePath = stackMatch[1]
249
+ const relativePath = absolutePath.replace(process.cwd() + '/', '')
250
+ filePath = relativePath
251
+ }
252
+ }
253
+
254
+ // If still unknown, try to extract from test context or use test file pattern
255
+ if (filePath === 'unknown') {
256
+ // Look for common test file patterns in the test title or fullTitle
257
+ const fullTitle = test.fullTitle || test.title
258
+ if (fullTitle && fullTitle.includes('checkout')) {
259
+ filePath = 'checkout_test.js'
260
+ } else if (fullTitle && fullTitle.includes('github')) {
261
+ filePath = 'github_test.js'
262
+ }
263
+ }
264
+
265
+ const failedTest = {
266
+ title: test.title,
267
+ fullTitle: test.fullTitle || test.title,
268
+ file: filePath,
269
+ uid: test.uid,
270
+ timestamp: new Date().toISOString(),
271
+ }
272
+
273
+ // Add parent suite information
274
+ if (test.parent) {
275
+ failedTest.suite = test.parent.title
276
+ failedTest.suiteFile = test.parent.file
277
+ }
278
+
279
+ // Add error information if available
280
+ if (test.err && options.includeStackTrace) {
281
+ failedTest.error = {
282
+ message: test.err.message || 'Test failed',
283
+ stack: test.err.stack || '',
284
+ name: test.err.name || 'Error',
285
+ }
286
+ }
287
+
288
+ // Add metadata if available
289
+ if (options.includeMetadata) {
290
+ failedTest.metadata = {
291
+ tags: test.tags || [],
292
+ meta: test.meta || {},
293
+ opts: test.opts || {},
294
+ duration: test.duration || 0,
295
+ retries: test.retries || 0,
296
+ }
297
+ }
298
+
299
+ // Add BDD/Gherkin information if available
300
+ if (test.parent && test.parent.feature) {
301
+ failedTest.bdd = {
302
+ feature: test.parent.feature.name || test.parent.title,
303
+ scenario: test.title,
304
+ featureFile: test.parent.file,
305
+ }
306
+ }
307
+
308
+ allFailedTests.push(failedTest)
309
+ })
310
+
311
+ output.print(`Failed Tests Tracker: Collected ${workerFailedTests.length} failed tests from workers`)
312
+ }
313
+
314
+ if (allFailedTests.length === 0) {
315
+ if (options.clearOnSuccess && fs.existsSync(outputPath)) {
316
+ try {
317
+ fs.unlinkSync(outputPath)
318
+ output.print(`Failed Tests Tracker: Cleared previous failed tests file (all tests passed)`)
319
+ } catch (error) {
320
+ output.print(`Failed Tests Tracker: Could not clear failed tests file: ${error.message}`)
321
+ }
322
+ }
323
+ return
324
+ }
325
+
326
+ // Save failed tests to file
327
+ try {
328
+ const failedTestsData = {
329
+ timestamp: new Date().toISOString(),
330
+ totalFailed: allFailedTests.length,
331
+ tests: allFailedTests,
332
+ }
333
+
334
+ // Ensure output directory exists
335
+ const dir = path.dirname(outputPath)
336
+ if (!fs.existsSync(dir)) {
337
+ fs.mkdirSync(dir, { recursive: true })
338
+ }
339
+
340
+ fs.writeFileSync(outputPath, JSON.stringify(failedTestsData, null, 2))
341
+ output.print(`Failed Tests Tracker: Saved ${allFailedTests.length} failed tests to ${outputPath}`)
342
+ } catch (error) {
343
+ output.print(`Failed Tests Tracker: Failed to save failed tests: ${error.message}`)
344
+ }
227
345
  })
228
346
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeceptjs",
3
- "version": "3.7.5-beta.5",
3
+ "version": "3.7.5-beta.7",
4
4
  "description": "Supercharged End 2 End Testing Framework for NodeJS",
5
5
  "keywords": [
6
6
  "acceptance",