type ContextCallback = (context: T) => Promise; export function beforeAllWithContext( callback: () => Promise, ): Promise { return new Promise((resole, reject) => { beforeAll(() => callback().then(resole, reject)); }); } export function afterAllWithContext( context: Promise, callback: ContextCallback, ) { afterAll(() => context.then(callback)); } export function beforeEachWithContext( callback: () => Promise, ): Promise { return new Promise((resole, reject) => { beforeEach(() => callback().then(resole, reject)); }); } export function afterEachWithContext( context: Promise, callback: ContextCallback, ) { afterEach(() => context.then(callback)); } export function describeWithContext( name: string, context: Promise, fn: ContextCallback, ) { describe(name, async () => fn(await context)); } export function itWithContext( name: string, context: Promise, fn: ContextCallback, ) { it(name, async () => fn(await context)); } export function testWithContext( name: string, context: Promise, fn: ContextCallback, ) { test(name, async () => fn(await context)); }