diff --git a/plugin.d.ts b/plugin.d.ts index 11b2274aa..a2f68e179 100644 --- a/plugin.d.ts +++ b/plugin.d.ts @@ -41,7 +41,7 @@ export namespace SharedWorker { readonly file: string; publish: (data: Data) => PublishedMessage; subscribe: () => AsyncIterableIterator>; - teardown: void> (fn: TeardownFn) => TeardownFn; + teardown: (fn: (() => Promise) | (() => void)) => () => Promise; }; export namespace Plugin { diff --git a/test-d/plugin.ts b/test-d/plugin.ts index 368ab0295..edf1a0a0f 100644 --- a/test-d/plugin.ts +++ b/test-d/plugin.ts @@ -5,5 +5,13 @@ import * as plugin from '../plugin'; // eslint-disable-line import/extensions expectType(plugin.registerSharedWorker({filename: '', supportedProtocols: ['ava-4']})); const factory: plugin.SharedWorker.Factory = ({negotiateProtocol}) => { // eslint-disable-line @typescript-eslint/no-unused-vars - expectType(negotiateProtocol(['ava-4'])); + const protocol = negotiateProtocol(['ava-4']); + expectType(protocol); + + (async () => { + for await (const w of protocol.testWorkers()) { + expectType<() => Promise>(w.teardown(() => {})); // eslint-disable-line @typescript-eslint/no-empty-function + expectType<() => Promise>(w.teardown(async () => {})); // eslint-disable-line @typescript-eslint/no-empty-function + } + })(); }; diff --git a/test-d/teardown.ts b/test-d/teardown.ts new file mode 100644 index 000000000..4627d1798 --- /dev/null +++ b/test-d/teardown.ts @@ -0,0 +1,6 @@ +import test from '..'; + +test('test', t => { + t.teardown(() => {}); // eslint-disable-line @typescript-eslint/no-empty-function + t.teardown(async () => {}); // eslint-disable-line @typescript-eslint/no-empty-function +}); diff --git a/types/test-fn.d.ts b/types/test-fn.d.ts index bcb9778ab..ff9d13fb7 100644 --- a/types/test-fn.d.ts +++ b/types/test-fn.d.ts @@ -46,7 +46,7 @@ export interface PlanFn { export type TimeoutFn = (ms: number, message?: string) => void; /** Declare a function to be run after the test has ended. */ -export type TeardownFn = (fn: () => void) => void; +export type TeardownFn = (fn: (() => Promise) | (() => void)) => void; export type ImplementationFn = ((t: ExecutionContext, ...args: Args) => PromiseLike) |