@@ -2,34 +2,32 @@ import { cleanup } from './pure';
22import { flushMicroTasks } from './flushMicroTasks' ;
33import { getIsReactActEnvironment , setReactActEnvironment } from './act' ;
44
5- // If we're running in a test runner that supports afterEach
6- // then we'll automatically run cleanup afterEach test
7- // this ensures that tests run in isolation from each other
8- // if you don't like this then either import the `pure` module
9- // or set the RNTL_SKIP_AUTO_CLEANUP env variable to 'true'.
10- if ( typeof afterEach === 'function' && ! process . env . RNTL_SKIP_AUTO_CLEANUP ) {
11- // eslint-disable-next-line no-undef
12- afterEach ( async ( ) => {
13- await flushMicroTasks ( ) ;
14- cleanup ( ) ;
15- } ) ;
16- }
5+ if ( typeof process === 'undefined' || ! process . env ?. RNTL_SKIP_AUTO_CLEANUP ) {
6+ // If we're running in a test runner that supports afterEach
7+ // then we'll automatically run cleanup afterEach test
8+ // this ensures that tests run in isolation from each other
9+ // if you don't like this then either import the `pure` module
10+ // or set the RNTL_SKIP_AUTO_CLEANUP env variable to 'true'.
11+ if ( typeof afterEach === 'function' ) {
12+ // eslint-disable-next-line no-undef
13+ afterEach ( async ( ) => {
14+ await flushMicroTasks ( ) ;
15+ cleanup ( ) ;
16+ } ) ;
17+ }
1718
18- if (
19- typeof beforeAll === 'function' &&
20- typeof afterAll === 'function' &&
21- ! process . env . RNTL_SKIP_AUTO_CLEANUP
22- ) {
23- // This matches the behavior of React < 18.
24- let previousIsReactActEnvironment = getIsReactActEnvironment ( ) ;
25- beforeAll ( ( ) => {
26- previousIsReactActEnvironment = getIsReactActEnvironment ( ) ;
27- setReactActEnvironment ( true ) ;
28- } ) ;
19+ if ( typeof beforeAll === 'function' && typeof afterAll === 'function' ) {
20+ // This matches the behavior of React < 18.
21+ let previousIsReactActEnvironment = getIsReactActEnvironment ( ) ;
22+ beforeAll ( ( ) => {
23+ previousIsReactActEnvironment = getIsReactActEnvironment ( ) ;
24+ setReactActEnvironment ( true ) ;
25+ } ) ;
2926
30- afterAll ( ( ) => {
31- setReactActEnvironment ( previousIsReactActEnvironment ) ;
32- } ) ;
27+ afterAll ( ( ) => {
28+ setReactActEnvironment ( previousIsReactActEnvironment ) ;
29+ } ) ;
30+ }
3331}
3432
3533export * from './pure' ;
0 commit comments