@@ -41,6 +41,9 @@ const isIntegerRegExp = /^\d+$/;
41
41
42
42
const isIntegerRangeRegExp = / ^ (?< startStr > \d + ) - (?< endStr > \d + ) $ / ;
43
43
44
+ const noop = ( ) => undefined ;
45
+ Object . freeze ( noop ) ;
46
+
44
47
export default pluginTester ;
45
48
46
49
/**
@@ -122,8 +125,8 @@ export function pluginTester(options: PluginTesterOptions = {}) {
122
125
formatResult : ( ( r ) => r ) as ResultFormatter ,
123
126
snapshot : false ,
124
127
fixtureOutputName : 'output' ,
125
- setup : ( ) => undefined ,
126
- teardown : ( ) => undefined
128
+ setup : noop ,
129
+ teardown : noop
127
130
} ,
128
131
options ,
129
132
mergeCustomizer
@@ -198,9 +201,9 @@ export function pluginTester(options: PluginTesterOptions = {}) {
198
201
// * https://xunn.at/babel-helper-plugin-utils-src
199
202
return rawBaseConfig . plugin ! (
200
203
{
201
- assertVersion : ( ) => undefined ,
202
- targets : ( ) => undefined ,
203
- assumption : ( ) => undefined
204
+ assertVersion : noop ,
205
+ targets : noop ,
206
+ assumption : noop
204
207
} ,
205
208
{ } ,
206
209
process . cwd ( )
@@ -431,7 +434,7 @@ export function pluginTester(options: PluginTesterOptions = {}) {
431
434
}
432
435
433
436
const rootOptions = mergeWith (
434
- { setup : ( ) => undefined , teardown : ( ) => undefined } ,
437
+ { setup : noop , teardown : noop } as object ,
435
438
fixtureOptions ,
436
439
readFixtureOptions ( fixturesDirectory ) ,
437
440
mergeCustomizer
@@ -588,8 +591,8 @@ export function pluginTester(options: PluginTesterOptions = {}) {
588
591
only,
589
592
skip,
590
593
expectedError : throws ?? error ,
591
- testSetup : setup ,
592
- testTeardown : teardown ,
594
+ testSetup : setup || noop ,
595
+ testTeardown : teardown || noop ,
593
596
formatResult : formatResult || baseFormatResult ,
594
597
fixtureOutputBasename,
595
598
code,
@@ -663,9 +666,9 @@ export function pluginTester(options: PluginTesterOptions = {}) {
663
666
execFixture
664
667
} = mergeWith (
665
668
{
666
- setup : ( ) => undefined ,
667
- teardown : ( ) => undefined
668
- } ,
669
+ setup : noop ,
670
+ teardown : noop
671
+ } as object ,
669
672
testObject ,
670
673
mergeCustomizer
671
674
) ;
@@ -717,8 +720,8 @@ export function pluginTester(options: PluginTesterOptions = {}) {
717
720
only,
718
721
skip,
719
722
expectedError : throws ?? error ,
720
- testSetup : setup ,
721
- testTeardown : teardown ,
723
+ testSetup : setup || noop ,
724
+ testTeardown : teardown || noop ,
722
725
formatResult : formatResult || baseFormatResult ,
723
726
// ? trimAndFixLineEndings is called later on the babel output instead
724
727
code,
@@ -799,13 +802,13 @@ export function pluginTester(options: PluginTesterOptions = {}) {
799
802
const setupFunctions = [ baseSetup , testSetup ] ;
800
803
const teardownFunctions = [ testTeardown , baseTeardown ] ;
801
804
802
- for ( const setupFn of setupFunctions ) {
805
+ for ( const [ index , setupFn ] of setupFunctions . entries ( ) ) {
803
806
try {
804
807
// eslint-disable-next-line no-await-in-loop
805
808
const maybeTeardownFn = await setupFn ( ) ;
806
809
807
810
if ( typeof maybeTeardownFn === 'function' ) {
808
- teardownFunctions . unshift ( maybeTeardownFn ) ;
811
+ teardownFunctions . splice ( index - 1 , 0 , maybeTeardownFn ) ;
809
812
}
810
813
} catch ( error ) {
811
814
throw new Error (
0 commit comments