44 ItDefinition ,
55 TestSuite ,
66} from "./test_suite.ts" ;
7- export type { DescribeDefinition , ItDefinition , TestSuite } ;
7+ export type { DescribeDefinition , ItDefinition } ;
88
99/** The arguments for an ItFunction. */
1010type ItArgs < T > =
@@ -32,32 +32,32 @@ type ItArgs<T> =
3232 fn : ( context : T ) => void | Promise < void > ,
3333 ]
3434 | [
35- suite : TestSuite < T > ,
35+ suite : symbol ,
3636 name : string ,
3737 options : Omit < ItDefinition < T > , "name" | "suite" > ,
3838 ]
3939 | [
40- suite : TestSuite < T > ,
40+ suite : symbol ,
4141 name : string ,
4242 fn : ( context : T ) => void | Promise < void > ,
4343 ]
4444 | [
45- suite : TestSuite < T > ,
45+ suite : symbol ,
4646 fn : ( context : T ) => void | Promise < void > ,
4747 ]
4848 | [
49- suite : TestSuite < T > ,
49+ suite : symbol ,
5050 name : string ,
5151 options : Omit < ItDefinition < T > , "fn" | "name" | "suite" > ,
5252 fn : ( context : T ) => void | Promise < void > ,
5353 ]
5454 | [
55- suite : TestSuite < T > ,
55+ suite : symbol ,
5656 options : Omit < ItDefinition < T > , "fn" | "suite" > ,
5757 fn : ( context : T ) => void | Promise < void > ,
5858 ]
5959 | [
60- suite : TestSuite < T > ,
60+ suite : symbol ,
6161 options : Omit < ItDefinition < T > , "fn" | "name" | "suite" > ,
6262 fn : ( context : T ) => void | Promise < void > ,
6363 ] ;
@@ -70,14 +70,14 @@ function itDefinition<T>(...args: ItArgs<T>): ItDefinition<T> {
7070 optionsOrFn ,
7171 fn ,
7272 ] = args ;
73- let suite : TestSuite < T > | undefined = undefined ;
73+ let suite : symbol | undefined = undefined ;
7474 let name : string ;
7575 let options :
7676 | ItDefinition < T >
7777 | Omit < ItDefinition < T > , "fn" >
7878 | Omit < ItDefinition < T > , "name" >
7979 | Omit < ItDefinition < T > , "fn" | "name" > ;
80- if ( suiteOptionsOrNameOrFn instanceof TestSuite ) {
80+ if ( typeof suiteOptionsOrNameOrFn === "symbol" ) {
8181 suite = suiteOptionsOrNameOrFn ;
8282 } else {
8383 fn = optionsOrFn as typeof fn ;
@@ -134,13 +134,12 @@ export function it<T>(...args: ItArgs<T>): void {
134134 ) ;
135135 }
136136 const options = itDefinition ( ...args ) ;
137- let { suite } = options ;
138-
139- suite ??= TestSuite . current as TestSuite < T > ;
137+ const { suite } = options ;
138+ const testSuite = suite ? TestSuite . suites . get ( suite ) : TestSuite . current ;
140139
141140 if ( ! TestSuite . started ) TestSuite . started = true ;
142- if ( suite ) {
143- TestSuite . addStep ( suite , options ) ;
141+ if ( testSuite ) {
142+ TestSuite . addStep ( testSuite , options ) ;
144143 } else {
145144 const {
146145 name,
@@ -255,36 +254,36 @@ type DescribeArgs<T> =
255254 fn : ( ) => void ,
256255 ]
257256 | [
258- suite : TestSuite < T > ,
257+ suite : symbol ,
259258 name : string ,
260259 ]
261260 | [
262- suite : TestSuite < T > ,
261+ suite : symbol ,
263262 name : string ,
264263 options : Omit < DescribeDefinition < T > , "name" | "suite" > ,
265264 ]
266265 | [
267- suite : TestSuite < T > ,
266+ suite : symbol ,
268267 name : string ,
269268 fn : ( ) => void ,
270269 ]
271270 | [
272- suite : TestSuite < T > ,
271+ suite : symbol ,
273272 fn : ( ) => void ,
274273 ]
275274 | [
276- suite : TestSuite < T > ,
275+ suite : symbol ,
277276 name : string ,
278277 options : Omit < DescribeDefinition < T > , "fn" | "name" | "suite" > ,
279278 fn : ( ) => void ,
280279 ]
281280 | [
282- suite : TestSuite < T > ,
281+ suite : symbol ,
283282 options : Omit < DescribeDefinition < T > , "fn" | "suite" > ,
284283 fn : ( ) => void ,
285284 ]
286285 | [
287- suite : TestSuite < T > ,
286+ suite : symbol ,
288287 options : Omit < DescribeDefinition < T > , "fn" | "name" | "suite" > ,
289288 fn : ( ) => void ,
290289 ] ;
@@ -299,14 +298,14 @@ function describeDefinition<T>(
299298 optionsOrFn ,
300299 fn ,
301300 ] = args ;
302- let suite : TestSuite < T > | undefined = undefined ;
301+ let suite : symbol | undefined = undefined ;
303302 let name : string ;
304303 let options :
305304 | DescribeDefinition < T >
306305 | Omit < DescribeDefinition < T > , "fn" >
307306 | Omit < DescribeDefinition < T > , "name" >
308307 | Omit < DescribeDefinition < T > , "fn" | "name" > ;
309- if ( suiteOptionsOrNameOrFn instanceof TestSuite ) {
308+ if ( typeof suiteOptionsOrNameOrFn === "symbol" ) {
310309 suite = suiteOptionsOrNameOrFn ;
311310 } else {
312311 fn = optionsOrFn as typeof fn ;
@@ -337,7 +336,7 @@ function describeDefinition<T>(
337336 }
338337
339338 if ( ! suite ) {
340- suite = options . suite ?? TestSuite . current as TestSuite < T > ;
339+ suite = options . suite ?? TestSuite . current ?. symbol ;
341340 }
342341
343342 return {
@@ -350,32 +349,32 @@ function describeDefinition<T>(
350349
351350/** Registers a test suite. */
352351export interface describe {
353- < T > ( ...args : DescribeArgs < T > ) : TestSuite < T > ;
352+ < T > ( ...args : DescribeArgs < T > ) : symbol ;
354353
355354 /** Registers a test suite with only set to true. */
356- only < T > ( ...args : DescribeArgs < T > ) : TestSuite < T > ;
355+ only < T > ( ...args : DescribeArgs < T > ) : symbol ;
357356
358357 /** Registers a test suite with ignore set to true. */
359- ignore < T > ( ...args : DescribeArgs < T > ) : TestSuite < T > ;
358+ ignore < T > ( ...args : DescribeArgs < T > ) : symbol ;
360359}
361360
362361/** Registers a test suite. */
363362export function describe < T > (
364363 ...args : DescribeArgs < T >
365- ) : TestSuite < T > {
364+ ) : symbol {
366365 if ( TestSuite . running ) {
367366 throw new Error (
368367 "cannot register new test suites after already registered test cases start running" ,
369368 ) ;
370369 }
371370 const options = describeDefinition ( ...args ) ;
372371 if ( ! TestSuite . started ) TestSuite . started = true ;
373- return new TestSuite ( options ) ;
372+ return ( new TestSuite ( options ) ) . symbol ;
374373}
375374
376375describe . only = function describeOnly < T > (
377376 ...args : DescribeArgs < T >
378- ) : TestSuite < T > {
377+ ) : symbol {
379378 const options = describeDefinition ( ...args ) ;
380379 return describe ( {
381380 ...options ,
@@ -385,7 +384,7 @@ describe.only = function describeOnly<T>(
385384
386385describe . ignore = function describeIgnore < T > (
387386 ...args : DescribeArgs < T >
388- ) : TestSuite < T > {
387+ ) : symbol {
389388 const options = describeDefinition ( ...args ) ;
390389 return describe ( {
391390 ...options ,
0 commit comments