mirror of
https://github.com/pezkuwichain/pezkuwi-dev.git
synced 2026-11-07 16:01:10 +00:00
Fix TypeScript type definitions for test suite
- Add explicit Describe and It interfaces with todo support - Fix mock type compatibility in jest.ts - Update import assertions to import attributes (assert -> with) - Add dynamic.d.mts declaration file - Fix spec files to use explicit type declarations
This commit is contained in:
1 parent
cb6801a3cc
commit
b65f265e87
9 files changed
+2987
-2672
No files matched your search
Vendored
+19
-5
@@ -13,6 +13,20 @@ interface WrapOpts {
|
||||
|
||||
type WrapFn = (name: string, options: { only?: boolean; skip?: boolean; timeout?: number; todo?: boolean; }, fn: () => void | Promise<void>) => void | Promise<void>;
|
||||
|
||||
type TestFn = (name: string, exec: () => void | Promise<void>, timeout?: number) => void;
|
||||
|
||||
export interface Describe extends TestFn {
|
||||
only: TestFn;
|
||||
skip: TestFn;
|
||||
todo: TestFn;
|
||||
}
|
||||
|
||||
export interface It extends TestFn {
|
||||
only: TestFn;
|
||||
skip: TestFn;
|
||||
todo: TestFn;
|
||||
}
|
||||
|
||||
const MINUTE = 60 * 1000;
|
||||
|
||||
/**
|
||||
@@ -23,7 +37,7 @@ const MINUTE = 60 * 1000;
|
||||
*
|
||||
* @param {} fn
|
||||
*/
|
||||
function createWrapper <T extends WrapFn> (fn: T, defaultTimeout: number) {
|
||||
function createWrapper <T extends WrapFn> (fn: T, defaultTimeout: number): Describe | It {
|
||||
const wrap = (opts: WrapOpts) => (name: string, exec: () => void | Promise<void>, timeout?: number) => fn(name, { ...opts, timeout: (timeout || defaultTimeout) }, exec) as unknown as void;
|
||||
|
||||
// Ensure that we have consistent helpers on the function. These are not consistently
|
||||
@@ -33,16 +47,16 @@ function createWrapper <T extends WrapFn> (fn: T, defaultTimeout: number) {
|
||||
only: wrap({ only: true }),
|
||||
skip: wrap({ skip: true }),
|
||||
todo: wrap({ todo: true })
|
||||
});
|
||||
}) as Describe | It;
|
||||
}
|
||||
|
||||
/**
|
||||
* This ensures that the describe and it functions match our actual usages.
|
||||
* This includes .only, .skip and .todo helpers (.each is not applied)
|
||||
**/
|
||||
export function suite () {
|
||||
export function suite (): { describe: Describe; it: It } {
|
||||
return {
|
||||
describe: createWrapper(describe, 60 * MINUTE),
|
||||
it: createWrapper(it, 2 * MINUTE)
|
||||
describe: createWrapper(describe, 60 * MINUTE) as Describe,
|
||||
it: createWrapper(it, 2 * MINUTE) as It
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user