* Create container with all required helpers and support objects * * @api * @param {*} config * @param {*} opts
(config, opts)
| 71 | * @param {*} opts |
| 72 | */ |
| 73 | static async create(config, opts) { |
| 74 | debug('creating container') |
| 75 | asyncHelperPromise = Promise.resolve() |
| 76 | |
| 77 | // dynamically create mocha instance |
| 78 | const mochaConfig = config.mocha || {} |
| 79 | if (config.grep && !opts.grep) mochaConfig.grep = config.grep |
| 80 | this.createMocha = () => (container.mocha = MochaFactory.create(mochaConfig, opts || {})) |
| 81 | this.createMocha() |
| 82 | |
| 83 | // create support objects |
| 84 | container.support = {} |
| 85 | container.helpers = await createHelpers(config.helpers || {}) |
| 86 | container.translation = await loadTranslation(config.translation || null, config.vocabularies || []) |
| 87 | container.proxySupportConfig = config.include || {} |
| 88 | container.proxySupport = createSupportObjects(container.proxySupportConfig) |
| 89 | container.plugins = await createPlugins(config.plugins || {}, opts) |
| 90 | container.result = new Result() |
| 91 | |
| 92 | // Preload includes (so proxies can expose real objects synchronously) |
| 93 | const includes = config.include || {} |
| 94 | |
| 95 | // Check if custom I is provided |
| 96 | if (Object.prototype.hasOwnProperty.call(includes, 'I')) { |
| 97 | try { |
| 98 | const mod = includes.I |
| 99 | if (typeof mod === 'string') { |
| 100 | container.support.I = await loadSupportObject(mod, 'I') |
| 101 | } else if (typeof mod === 'function') { |
| 102 | container.support.I = await loadSupportObject(mod, 'I') |
| 103 | } else if (mod && typeof mod === 'object') { |
| 104 | container.support.I = mod |
| 105 | } |
| 106 | } catch (e) { |
| 107 | throw e |
| 108 | } |
| 109 | } else { |
| 110 | // Create default actor - this sets up the callback in asyncHelperPromise |
| 111 | createActor() |
| 112 | } |
| 113 | |
| 114 | // Load remaining includes except I |
| 115 | for (const [name, mod] of Object.entries(includes)) { |
| 116 | if (name === 'I') continue |
| 117 | try { |
| 118 | if (typeof mod === 'string') { |
| 119 | container.support[name] = await loadSupportObject(mod, name) |
| 120 | } else if (typeof mod === 'function') { |
| 121 | // function or class |
| 122 | container.support[name] = await loadSupportObject(mod, name) |
| 123 | } else if (mod && typeof mod === 'object') { |
| 124 | container.support[name] = mod |
| 125 | } |
| 126 | } catch (e) { |
| 127 | throw new Error(`Could not include object ${name}: ${e.message}`) |
| 128 | } |
| 129 | } |
| 130 |
no test coverage detected