MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / _after

Method _after

lib/helper/ApiDataFactory.js:234–265  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

232 }
233
234 _after() {
235 if (!this.config.cleanup || this.config.cleanup === false) {
236 return Promise.resolve()
237 }
238 const promises = []
239
240 // clean up all created items
241 for (const factoryName in this.created) {
242 const createdItems = this.created[factoryName]
243 if (!createdItems.length) continue
244 this.debug(`Deleting ${createdItems.length} ${factoryName}(s)`)
245 for (const id in createdItems) {
246 const deletePromise = this._requestDelete(factoryName, createdItems[id])
247 if (deletePromise) {
248 promises.push(deletePromise.catch(err => {
249 this.debugSection('Delete Error', `Failed to delete ${factoryName} with id ${createdItems[id]}: ${err.message}`)
250 // Don't reject Promise.all, just log the error
251 return Promise.resolve()
252 }))
253 }
254 }
255 }
256 return Promise.all(promises).then(() => {
257 // Clear the created items after successful cleanup
258 for (const factoryName in this.created) {
259 this.created[factoryName] = []
260 }
261 // Add a small delay to ensure file system changes propagate in Docker environments
262 // This helps avoid race conditions where GET requests after DELETE don't see the changes yet
263 return new Promise(resolve => setTimeout(resolve, 100))
264 })
265 }
266
267 /**
268 * Generates a new record using factory and saves API request to store it.

Callers

nothing calls this directly

Calls 3

_requestDeleteMethod · 0.95
debugMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected