(model, data, options)
| 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 | |
| 343 | points to valid factory file. |
| 344 | Factory file should export an object with build method. |
| 345 | |
| 346 | Current file error: ${err.message}`) |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | _fetchId(body, factory) { |
| 351 | if (this.config.factories[factory].fetchId) { |
no test coverage detected