11import {
2- type HarnessTestContext ,
32 afterEach ,
43 beforeEach ,
54 describe as harnessDescribe ,
65 getTestCollector ,
76 it as harnessIt ,
87} from '../collector/index.js' ;
8+ import type { HarnessTestContext } from '@react-native-harness/bridge' ;
99import { getTestRunner } from '../runner/index.js' ;
1010import { describe , expect , it , vi } from 'vitest' ;
1111
1212vi . mock ( '../symbolicate.js' , async ( ) => {
13- const actual = await vi . importActual < typeof import ( '../symbolicate.js' ) > (
14- '../symbolicate.js' ,
15- ) ;
16-
1713 return {
18- ...actual ,
1914 getCodeFrame : vi . fn ( async ( ) => null ) ,
2015 } ;
2116} ) ;
@@ -28,6 +23,14 @@ const getTask = (context?: HarnessTestContext) => {
2823 return context . task ;
2924} ;
3025
26+ const getTaskContext = ( context ?: HarnessTestContext ) => {
27+ if ( ! context ) {
28+ throw new Error ( 'Expected test context to be defined' ) ;
29+ }
30+
31+ return context ;
32+ } ;
33+
3134describe ( 'runner task context' , ( ) => {
3235 it ( 'passes minimal task metadata to tests and per-test hooks' , async ( ) => {
3336 const observedTasks : Array < {
@@ -46,15 +49,15 @@ describe('runner task context', () => {
4649 try {
4750 const collection = await collector . collect ( ( ) => {
4851 harnessDescribe ( 'Task Context Suite' , ( ) => {
49- beforeEach ( ( context ) => {
52+ beforeEach ( ( context : HarnessTestContext | undefined ) => {
5053 observedTasks . push ( { source : 'beforeEach' , task : getTask ( context ) } ) ;
5154 } ) ;
5255
53- afterEach ( ( context ) => {
56+ afterEach ( ( context : HarnessTestContext | undefined ) => {
5457 observedTasks . push ( { source : 'afterEach' , task : getTask ( context ) } ) ;
5558 } ) ;
5659
57- harnessIt ( 'exposes task metadata' , ( context ) => {
60+ harnessIt ( 'exposes task metadata' , ( context : HarnessTestContext | undefined ) => {
5861 observedTasks . push ( { source : 'test' , task : getTask ( context ) } ) ;
5962 } ) ;
6063 } ) ;
@@ -157,7 +160,9 @@ describe('runner task context', () => {
157160 calls . push ( 'afterEach' ) ;
158161 } ) ;
159162
160- harnessIt ( 'skips from context' , ( { skip } ) => {
163+ harnessIt ( 'skips from context' , ( context : HarnessTestContext | undefined ) => {
164+ const { skip } = getTaskContext ( context ) ;
165+
161166 calls . push ( 'before-skip' ) ;
162167 skip ( 'skip this test' ) ;
163168 calls . push ( 'after-skip' ) ;
@@ -199,7 +204,9 @@ describe('runner task context', () => {
199204 try {
200205 const collection = await collector . collect ( ( ) => {
201206 harnessDescribe ( 'Conditional Skip Suite' , ( ) => {
202- harnessIt ( 'continues when condition is false' , ( { skip } ) => {
207+ harnessIt ( 'continues when condition is false' , ( context : HarnessTestContext | undefined ) => {
208+ const { skip } = getTaskContext ( context ) ;
209+
203210 calls . push ( 'before' ) ;
204211 skip ( false , 'do not skip' ) ;
205212 calls . push ( 'after' ) ;
@@ -233,7 +240,9 @@ describe('runner task context', () => {
233240 calls . push ( 'afterEach' ) ;
234241 } ) ;
235242
236- harnessIt ( 'runs finished callbacks' , ( { onTestFinished } ) => {
243+ harnessIt ( 'runs finished callbacks' , ( context : HarnessTestContext | undefined ) => {
244+ const { onTestFinished } = getTaskContext ( context ) ;
245+
237246 onTestFinished ( ( ) => {
238247 calls . push ( 'onTestFinished:first' ) ;
239248 } ) ;
@@ -277,14 +286,19 @@ describe('runner task context', () => {
277286 calls . push ( 'afterEach' ) ;
278287 } ) ;
279288
280- harnessIt ( 'runs finished callback after skip' , ( { onTestFinished, skip } ) => {
289+ harnessIt (
290+ 'runs finished callback after skip' ,
291+ ( context : HarnessTestContext | undefined ) => {
292+ const { onTestFinished, skip } = getTaskContext ( context ) ;
293+
281294 onTestFinished ( ( ) => {
282295 calls . push ( 'onTestFinished' ) ;
283296 } ) ;
284297
285298 calls . push ( 'before-skip' ) ;
286299 skip ( ) ;
287- } ) ;
300+ } ,
301+ ) ;
288302 } ) ;
289303 } , 'runtime/on-test-finished-skip.test.ts' ) ;
290304
@@ -314,14 +328,19 @@ describe('runner task context', () => {
314328 calls . push ( 'afterEach' ) ;
315329 } ) ;
316330
317- harnessIt ( 'runs finished callback after failure' , ( { onTestFinished } ) => {
331+ harnessIt (
332+ 'runs finished callback after failure' ,
333+ ( context : HarnessTestContext | undefined ) => {
334+ const { onTestFinished } = getTaskContext ( context ) ;
335+
318336 onTestFinished ( ( ) => {
319337 calls . push ( 'onTestFinished' ) ;
320338 } ) ;
321339
322340 calls . push ( 'test' ) ;
323341 throw new Error ( 'expected failure' ) ;
324- } ) ;
342+ } ,
343+ ) ;
325344 } ) ;
326345 } , 'runtime/on-test-finished-failure.test.ts' ) ;
327346
@@ -351,7 +370,9 @@ describe('runner task context', () => {
351370 calls . push ( 'afterEach' ) ;
352371 } ) ;
353372
354- harnessIt ( 'runs failed callbacks' , ( { onTestFailed } ) => {
373+ harnessIt ( 'runs failed callbacks' , ( context : HarnessTestContext | undefined ) => {
374+ const { onTestFailed } = getTaskContext ( context ) ;
375+
355376 onTestFailed ( ( ) => {
356377 calls . push ( 'onTestFailed:first' ) ;
357378 } ) ;
@@ -396,14 +417,19 @@ describe('runner task context', () => {
396417 calls . push ( 'afterEach' ) ;
397418 } ) ;
398419
399- harnessIt ( 'does not run failed callbacks on skip' , ( { onTestFailed, skip } ) => {
420+ harnessIt (
421+ 'does not run failed callbacks on skip' ,
422+ ( context : HarnessTestContext | undefined ) => {
423+ const { onTestFailed, skip } = getTaskContext ( context ) ;
424+
400425 onTestFailed ( ( ) => {
401426 calls . push ( 'onTestFailed' ) ;
402427 } ) ;
403428
404429 calls . push ( 'before-skip' ) ;
405430 skip ( ) ;
406- } ) ;
431+ } ,
432+ ) ;
407433 } ) ;
408434 } , 'runtime/on-test-failed-skip.test.ts' ) ;
409435
@@ -434,13 +460,18 @@ describe('runner task context', () => {
434460 throw new Error ( 'afterEach failure' ) ;
435461 } ) ;
436462
437- harnessIt ( 'runs failed callback after afterEach failure' , ( { onTestFailed } ) => {
463+ harnessIt (
464+ 'runs failed callback after afterEach failure' ,
465+ ( context : HarnessTestContext | undefined ) => {
466+ const { onTestFailed } = getTaskContext ( context ) ;
467+
438468 onTestFailed ( ( ) => {
439469 calls . push ( 'onTestFailed' ) ;
440470 } ) ;
441471
442472 calls . push ( 'test' ) ;
443- } ) ;
473+ } ,
474+ ) ;
444475 } ) ;
445476 } , 'runtime/on-test-failed-after-each.test.ts' ) ;
446477
0 commit comments