( name: string, config: ConfigFor<P>, fn: (props: P) => Promise<void> )
| 14 | } |
| 15 | |
| 16 | export function describe<P>( |
| 17 | name: string, |
| 18 | config: ConfigFor<P>, |
| 19 | fn: (props: P) => Promise<void> |
| 20 | ): void { |
| 21 | if (currentScenarios === null) { |
| 22 | const scenarios = (currentScenarios = []) |
| 23 | |
| 24 | Promise.resolve().then(async () => { |
| 25 | const ifaceNames = process.env.INTERFACE || 'interactive,console' |
| 26 | const ifaces = [] |
| 27 | for (const ifaceName of ifaceNames.split(',').map((s) => s.trim())) { |
| 28 | let iface: unknown |
| 29 | try { |
| 30 | iface = await import(`./interfaces/${ifaceName}.js`) |
| 31 | } catch (e) { |
| 32 | iface = await import(ifaceName) |
| 33 | } |
| 34 | iface = (iface && (iface as any).default) || iface |
| 35 | if (typeof iface === 'function') { |
| 36 | iface = await iface() |
| 37 | } |
| 38 | if (!iface) { |
| 39 | throw new Error(`Interface ${ifaceName} is not a valid interface`) |
| 40 | } |
| 41 | ifaces.push(iface as Interface) |
| 42 | } |
| 43 | runScenarios(scenarios, compose(...ifaces)) |
| 44 | }) |
| 45 | } |
| 46 | const normalizedConfig: Record<string, (string | number | boolean)[]> = |
| 47 | Object.fromEntries( |
| 48 | Object.entries(config).map(([key, value]) => [ |
| 49 | key, |
| 50 | typeof value === 'boolean' |
| 51 | ? [value, !value] |
| 52 | : (value as (string | number | boolean)[]), |
| 53 | ]) |
| 54 | ) |
| 55 | currentScenarios!.push({ |
| 56 | name, |
| 57 | config: normalizedConfig, |
| 58 | only: false, |
| 59 | fn: fn as ( |
| 60 | props: Record<string, string | number | boolean> |
| 61 | ) => Promise<void>, |
| 62 | }) |
| 63 | } |
| 64 | |
| 65 | describe.only = function describeOnly<P>( |
| 66 | name: string, |
no test coverage detected