(opts: {
titlePrefix: string | undefined;
separator: string | undefined;
mustDoSerial: boolean;
automaticallyDoSerial: boolean;
automaticallySkip: boolean;
beforeEachFunctions: Function[];
})
| 131 | } |
| 132 | |
| 133 | function createTestInterface<Context>(opts: { |
| 134 | titlePrefix: string | undefined; |
| 135 | separator: string | undefined; |
| 136 | mustDoSerial: boolean; |
| 137 | automaticallyDoSerial: boolean; |
| 138 | automaticallySkip: boolean; |
| 139 | beforeEachFunctions: Function[]; |
| 140 | }): TestInterface<Context> { |
| 141 | const { titlePrefix, separator = ' > ' } = opts; |
| 142 | const beforeEachFunctions = [...(opts.beforeEachFunctions ?? [])]; |
| 143 | let { mustDoSerial, automaticallyDoSerial, automaticallySkip } = opts; |
| 144 | let hookDeclared = false; |
| 145 | let suiteOrTestDeclared = false; |
| 146 | function computeTitle<Args extends any[]>( |
| 147 | title: string | undefined, |
| 148 | macros?: AvaMacro<Args, any>[], |
| 149 | ...args: Args |
| 150 | ) { |
| 151 | for (const macro of macros ?? []) { |
| 152 | if (macro.title) { |
| 153 | title = macro.title(title, ...args); |
| 154 | } |
| 155 | } |
| 156 | assert(title); |
| 157 | // return `${ titlePrefix }${ separator }${ title }`; |
| 158 | if (titlePrefix != null && title != null) { |
| 159 | return `${titlePrefix}${separator}${title}`; |
| 160 | } |
| 161 | if (titlePrefix == null && title != null) { |
| 162 | return title; |
| 163 | } |
| 164 | } |
| 165 | function parseArgs(args: any[]) { |
| 166 | const title = |
| 167 | typeof args[0] === 'string' ? (args.shift() as string) : undefined; |
| 168 | const macros = |
| 169 | typeof args[0] === 'function' |
| 170 | ? [args.shift() as AvaMacro] |
| 171 | : Array.isArray(args[0]) |
| 172 | ? (args.shift() as AvaMacro[]) |
| 173 | : []; |
| 174 | return { title, macros, args }; |
| 175 | } |
| 176 | function assertOrderingForDeclaringTest() { |
| 177 | suiteOrTestDeclared = true; |
| 178 | } |
| 179 | function assertOrderingForDeclaringHook() { |
| 180 | if (suiteOrTestDeclared) { |
| 181 | throw new Error( |
| 182 | 'Hooks must be declared before declaring sub-suites or tests' |
| 183 | ); |
| 184 | } |
| 185 | hookDeclared = true; |
| 186 | } |
| 187 | function assertOrderingForDeclaringSkipUnless() { |
| 188 | if (suiteOrTestDeclared) { |
| 189 | throw new Error( |
| 190 | 'skipUnless or runIf must be declared before declaring sub-suites or tests' |
no test coverage detected
searching dependent graphs…