@@ -11,11 +11,11 @@ import * as quenchUserUtils from "./utils/user-utils";
1111declare global {
1212 namespace Mocha {
1313 interface Runnable {
14- _quench_parentBatch : string ;
14+ _quench_parentBatch ? : string ;
1515 }
1616 interface Suite {
17- _quench_parentBatch : string ;
18- _quench_batchRoot : boolean ;
17+ _quench_parentBatch ? : string ;
18+ _quench_batchRoot ? : boolean ;
1919 get id ( ) : string ;
2020 }
2121 interface Test {
@@ -135,29 +135,6 @@ export class Quench {
135135 } ) ;
136136 return batches . map ( ( { key } ) => key ) ;
137137 }
138- /**
139- * A helper function adding a reference to a test's Quench Batch to a given Mocha function's result
140- *
141- * @internal
142- * @param fn - The Mocha function to add the batch to
143- * @param key - The key of the batch to add
144- * @returns The Mocha function with the batch reference added
145- */
146- protected static _quenchify < Fn extends Mocha . TestFunction | Mocha . SuiteFunction > (
147- fn : Fn ,
148- key : string ,
149- ) : Fn {
150- const quenchFn = function quenchFn ( ...args : Parameters < Fn > ) {
151- // @ts -expect-error Args are passed through as-is
152- const result = fn ( ...args ) ;
153- result . _quench_parentBatch = key ;
154- return result ;
155- } ;
156- quenchFn . only = fn . only ;
157- quenchFn . skip = fn . skip ;
158- if ( "retries" in fn ) quenchFn . retries = fn . retries ;
159- return quenchFn as Fn ;
160- }
161138
162139 /**
163140 * Registers a new Quench test batch which will show up in the quench window to be enabled/disabled and run.
@@ -284,11 +261,13 @@ export class Quench {
284261 // Run should to patch object prototype
285262 const should = this . chai . should ( ) ;
286263
287- const baseContext : Omit < QuenchBatchContext , "describe" | "it" > = {
264+ const baseContext : QuenchBatchContext = {
288265 after,
289266 afterEach,
290267 before,
291268 beforeEach,
269+ describe,
270+ it,
292271 utils,
293272 assert,
294273 expect,
@@ -303,18 +282,15 @@ export class Quench {
303282
304283 // Register suites and tests for provided batches
305284 for ( const key of batchKeys ) {
306- const context : QuenchBatchContext = {
307- ...baseContext ,
308- describe : ( this . constructor as typeof Quench ) . _quenchify ( describe , key ) , // typecasting necessary, see #3841
309- it : ( this . constructor as typeof Quench ) . _quenchify ( it , key ) , // see above; check again ~2030
310- } ;
311-
285+ const context = { ...baseContext } ;
312286 // Create a wrapper suite to contain this test batch
313- const testBatchRoot = context . describe ( `${ key } _root` , async ( ) => {
287+ const quench = this ;
288+ const testBatchRoot = context . describe ( `${ key } _root` , async function ( ) {
314289 // Call the batch's registration function
315- await this . _testBatches . get ( key ) ?. fn ( context ) ;
290+ await quench . _testBatches . get ( key ) ?. fn . apply ( this , [ context ] ) ;
316291 } ) ;
317292 testBatchRoot . _quench_batchRoot = true ;
293+ testBatchRoot . _quench_parentBatch = key ;
318294 }
319295
320296 // Run the tests and hold on to the runner
@@ -370,7 +346,10 @@ export interface QuenchRegisterBatchOptions {
370346 * @public
371347 * @param context - Various Mocha and Chai functions
372348 */
373- export type QuenchRegisterBatchFunction = ( context : QuenchBatchContext ) => void | Promise < void > ;
349+ export type QuenchRegisterBatchFunction = (
350+ this : Mocha . Suite ,
351+ context : QuenchBatchContext ,
352+ ) => void | Promise < void > ;
374353
375354/**
376355 * A context object passed to batch registration functions, containing functions usually
0 commit comments