| 1 | import { getParams } from '../parser.js' |
| 2 | |
| 3 | const getInjectedArguments = async (fn, test, suite) => { |
| 4 | const containerModule = await import('../container.js') |
| 5 | const container = containerModule.default || containerModule |
| 6 | |
| 7 | const testArgs = {} |
| 8 | const params = getParams(fn, { warnOnLegacyFormat: true }) || [] |
| 9 | const objects = container.support() |
| 10 | |
| 11 | for (const key of params) { |
| 12 | testArgs[key] = {} |
| 13 | |
| 14 | // Handle special built-in objects first |
| 15 | if (key === 'suite') { |
| 16 | if (test) { |
| 17 | testArgs[key] = test.parent || test |
| 18 | } else if (suite) { |
| 19 | testArgs[key] = suite |
| 20 | } |
| 21 | continue |
| 22 | } |
| 23 | if (key === 'test') { |
| 24 | testArgs[key] = test |
| 25 | continue |
| 26 | } |
| 27 | |
| 28 | if (test && test.inject && test.inject[key]) { |
| 29 | // @FIX: need fix got inject |
| 30 | testArgs[key] = test.inject[key] |
| 31 | continue |
| 32 | } |
| 33 | if (!objects[key]) { |
| 34 | throw new Error(`Object of type ${key} is not defined in container`) |
| 35 | } |
| 36 | testArgs[key] = container.support(key) |
| 37 | } |
| 38 | |
| 39 | if (test) { |
| 40 | testArgs.suite = test?.parent |
| 41 | testArgs.test = test |
| 42 | } |
| 43 | return testArgs |
| 44 | } |
| 45 | |
| 46 | export { getInjectedArguments } |