11import { CurrentRuntime , Runtime } from "@cross/runtime" ;
22
3+ /**
4+ * Test subject
5+ */
6+ export type TestSubject = ( context : unknown | undefined , done : ( value ?: unknown ) => void ) => void | Promise < void > ;
7+
38/**
49 * Runtime independent test function
510 */
611export interface WrappedTest {
7- ( name : string , options : WrappedTestOptions , testFn : ( ) => Promise < void > ) : Promise < void > ;
12+ ( name : string , testFn : TestSubject , options ?: WrappedTestOptions ) : Promise < void > ;
813}
914
1015/**
@@ -13,26 +18,31 @@ export interface WrappedTest {
1318export interface WrappedTestOptions {
1419 timeout ?: number ; // Timeout duration in milliseconds (optional)
1520 skip ?: boolean ; // Whether to skip the test (optional)
21+ waitForCallback ?: boolean ; // Whether to wait for the done-callback to be called
1622}
1723
18- let wrappedTestToUse : WrappedTest | undefined ;
24+ let wrappedTestToUse : WrappedTest ;
1925if ( CurrentRuntime == Runtime . Deno ) {
20- const { wrappedTest } = await import ( "./shims/deno.js " ) ;
26+ const { wrappedTest } = await import ( "./shims/deno.ts " ) ;
2127 // @ts -ignore js
2228 wrappedTestToUse = wrappedTest ;
2329} else if ( CurrentRuntime == Runtime . Node ) {
24- const { wrappedTest } = await import ( "./shims/node.js" ) ;
30+ const { wrappedTest } = await import ( "./shims/node.ts" ) ;
31+ // @ts -ignore js
32+ wrappedTestToUse = wrappedTest ;
33+ } else if ( CurrentRuntime == Runtime . Bun ) {
34+ const { wrappedTest } = await import ( "./shims/bun.ts" ) ;
2535 // @ts -ignore js
2636 wrappedTestToUse = wrappedTest ;
2737} else {
2838 throw new Error ( "Unsupported runtime" ) ;
2939}
3040/**
3141 * Defines and executes a single test.
32- * @param { string } name - The name of the test.
33- * @param { any } options - Options for the test (structure depends on your shim)
34- * @param { () => Promise<void> } testFn - The function containing the test logic.
42+ * @param name - The name of the test.
43+ * @param options? - Options for the test (structure depends on your shim)
44+ * @param testFn - The function containing the test logic.
3545 */
36- export async function test ( name : string , options : WrappedTestOptions , testFn : ( ) => Promise < void > ) {
37- if ( wrappedTestToUse ) await wrappedTestToUse ( name , options , testFn ) ;
46+ export async function test ( name : string , testFn : TestSubject , options : WrappedTestOptions = { } ) {
47+ await wrappedTestToUse ( name , testFn , options ) ;
3848}
0 commit comments