( fn: (...args: any[]) => any, )
| 742 | } |
| 743 | |
| 744 | export function createTaskCollector( |
| 745 | fn: (...args: any[]) => any, |
| 746 | ): TestAPI { |
| 747 | const taskFn = fn as any |
| 748 | |
| 749 | taskFn.each = function <T>( |
| 750 | this: TestAPI, |
| 751 | cases: ReadonlyArray<T>, |
| 752 | ...args: any[] |
| 753 | ) { |
| 754 | const context = getChainableContext(this) |
| 755 | const test = context.withContext() |
| 756 | context.setContext('each', true) |
| 757 | |
| 758 | if (Array.isArray(cases) && args.length) { |
| 759 | cases = formatTemplateString(cases, args) |
| 760 | } |
| 761 | |
| 762 | return ( |
| 763 | name: string | Function, |
| 764 | optionsOrFn: ((...args: T[]) => void) | TestOptions, |
| 765 | fnOrOptions?: ((...args: T[]) => void) | number, |
| 766 | ) => { |
| 767 | const _name = formatName(name) |
| 768 | const arrayOnlyCases = cases.every(Array.isArray) |
| 769 | |
| 770 | const { options, handler } = parseArguments(optionsOrFn, fnOrOptions) |
| 771 | |
| 772 | const fnFirst = typeof optionsOrFn === 'function' |
| 773 | |
| 774 | cases.forEach((i, idx) => { |
| 775 | const items = Array.isArray(i) ? i : [i] |
| 776 | |
| 777 | if (fnFirst) { |
| 778 | if (arrayOnlyCases) { |
| 779 | test( |
| 780 | formatTitle(_name, items, idx), |
| 781 | handler ? () => handler(...items) : undefined, |
| 782 | options.timeout, |
| 783 | ) |
| 784 | } |
| 785 | else { |
| 786 | test(formatTitle(_name, items, idx), handler ? () => handler(i) : undefined, options.timeout) |
| 787 | } |
| 788 | } |
| 789 | else { |
| 790 | if (arrayOnlyCases) { |
| 791 | test(formatTitle(_name, items, idx), options, handler ? () => handler(...items) : undefined) |
| 792 | } |
| 793 | else { |
| 794 | test(formatTitle(_name, items, idx), options, handler ? () => handler(i) : undefined) |
| 795 | } |
| 796 | } |
| 797 | }) |
| 798 | |
| 799 | context.setContext('each', undefined) |
| 800 | } |
| 801 | } |
no test coverage detected