| 45 | })(); |
| 46 | |
| 47 | const _dispatchDescribe = ( |
| 48 | blockFn: Circus.BlockFn, |
| 49 | blockName: Circus.BlockNameLike, |
| 50 | describeFn: DescribeFn, |
| 51 | mode?: Circus.BlockMode, |
| 52 | ) => { |
| 53 | const asyncError = new ErrorWithStack(undefined, describeFn); |
| 54 | if (blockFn === undefined) { |
| 55 | asyncError.message = |
| 56 | 'Missing second argument. It must be a callback function.'; |
| 57 | throw asyncError; |
| 58 | } |
| 59 | if (typeof blockFn !== 'function') { |
| 60 | asyncError.message = `Invalid second argument, ${blockFn}. It must be a callback function.`; |
| 61 | throw asyncError; |
| 62 | } |
| 63 | try { |
| 64 | blockName = convertDescriptorToString(blockName); |
| 65 | } catch (error) { |
| 66 | asyncError.message = (error as Error).message; |
| 67 | throw asyncError; |
| 68 | } |
| 69 | |
| 70 | dispatchSync({ |
| 71 | asyncError, |
| 72 | blockName, |
| 73 | mode, |
| 74 | name: 'start_describe_definition', |
| 75 | }); |
| 76 | const describeReturn = blockFn(); |
| 77 | |
| 78 | if (isPromise(describeReturn)) { |
| 79 | throw new ErrorWithStack( |
| 80 | 'Returning a Promise from "describe" is not supported. Tests must be defined synchronously.', |
| 81 | describeFn, |
| 82 | ); |
| 83 | } else if (describeReturn !== undefined) { |
| 84 | throw new ErrorWithStack( |
| 85 | 'A "describe" callback must not return a value.', |
| 86 | describeFn, |
| 87 | ); |
| 88 | } |
| 89 | |
| 90 | dispatchSync({blockName, mode, name: 'finish_describe_definition'}); |
| 91 | }; |
| 92 | |
| 93 | const _addHook = ( |
| 94 | fn: Circus.HookFn, |