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

Method _createItem

lib/helper/ApiDataFactory.js:318–348  ·  view source on GitHub ↗
(model, data, options)

Source from the content-addressed store, hash-verified

316 }
317
318 async _createItem(model, data, options) {
319 if (!this.factories[model]) {
320 throw new Error(`Factory ${model} is not defined in config`)
321 }
322 let modulePath = this.factories[model].factory
323 try {
324 try {
325 // Try to resolve the path as-is first
326 await import.meta.resolve(modulePath)
327 } catch (e) {
328 // If not found, try relative to codecept_dir
329 modulePath = path.join(store.codeceptDir, modulePath)
330 }
331 // check if the new syntax `export default new Factory()` is used and loads the builder, otherwise loads the module that used old syntax `module.exports = new Factory()`.
332 const resolvedPath = resolveImportModulePath(modulePath)
333 const module = await import(resolvedPath)
334 const builder = module.default || module
335 return builder.build(data, options)
336 } catch (err) {
337 throw new Error(`Couldn't load factory file from ${modulePath}, check that
338
339 "factories": {
340 "${model}": {
341 "factory": "./path/to/factory"
342
343points to valid factory file.
344Factory file should export an object with build method.
345
346Current file error: ${err.message}`)
347 }
348 }
349
350 _fetchId(body, factory) {
351 if (this.config.factories[factory].fetchId) {

Callers 1

haveMethod · 0.95

Calls 1

resolveImportModulePathFunction · 0.90

Tested by

no test coverage detected