Skip to content

Commit 9f4382a

Browse files
committed
fix(ApiDataFactory): Improve cleanup reliability in _after() method
- Add error handling to catch and log deletion failures without breaking Promise.all - Explicitly clear created items array after successful cleanup - Check for undefined deletePromise before adding to promises array This should help prevent test failures where data from previous tests accumulates, especially in CI environments where timing may differ. The cleanup now: 1. Catches individual deletion errors to prevent Promise.all rejection 2. Logs deletion errors for debugging 3. Clears the created items tracker after all deletions complete 4. Handles cases where _requestDelete returns undefined
1 parent 8ee6c69 commit 9f4382a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/helper/ApiDataFactory.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,22 @@ class ApiDataFactory extends Helper {
241241
if (!createdItems.length) continue
242242
this.debug(`Deleting ${createdItems.length} ${factoryName}(s)`)
243243
for (const id in createdItems) {
244-
promises.push(this._requestDelete(factoryName, createdItems[id]))
244+
const deletePromise = this._requestDelete(factoryName, createdItems[id])
245+
if (deletePromise) {
246+
promises.push(deletePromise.catch(err => {
247+
this.debugSection('Delete Error', `Failed to delete ${factoryName} with id ${createdItems[id]}: ${err.message}`)
248+
// Don't reject Promise.all, just log the error
249+
return Promise.resolve()
250+
}))
251+
}
245252
}
246253
}
247-
return Promise.all(promises)
254+
return Promise.all(promises).then(() => {
255+
// Clear the created items after successful cleanup
256+
for (const factoryName in this.created) {
257+
this.created[factoryName] = []
258+
}
259+
})
248260
}
249261

250262
/**

0 commit comments

Comments
 (0)