(fn: () => Promise<any>, errorMessage?: string)
| 4 | import path from 'node:path'; |
| 5 | |
| 6 | export function expectToFail(fn: () => Promise<any>, errorMessage?: string): Promise<Error> { |
| 7 | return fn().then( |
| 8 | () => { |
| 9 | const functionSource = fn.name || (<any>fn).source || fn.toString(); |
| 10 | const errorDetails = errorMessage ? `\n\tDetails:\n\t${errorMessage}` : ''; |
| 11 | throw new Error( |
| 12 | `Function ${functionSource} was expected to fail, but succeeded.${errorDetails}`, |
| 13 | ); |
| 14 | }, |
| 15 | (err) => { |
| 16 | return err instanceof Error ? err : new Error(err); |
| 17 | }, |
| 18 | ); |
| 19 | } |
| 20 | |
| 21 | export async function mktempd(prefix: string, tempRoot?: string): Promise<string> { |
| 22 | return realpath(await mkdtemp(path.join(tempRoot ?? tmpdir(), prefix))); |
no test coverage detected