@@ -118,7 +118,7 @@ function pluginTester({
118
118
teardowns . push ( returnedTeardown )
119
119
}
120
120
try {
121
- tester ( )
121
+ await tester ( )
122
122
} finally {
123
123
try {
124
124
await Promise . all ( teardowns . map ( t => t ( ) ) )
@@ -132,7 +132,7 @@ function pluginTester({
132
132
}
133
133
134
134
// eslint-disable-next-line complexity
135
- function tester ( ) {
135
+ async function tester ( ) {
136
136
assert (
137
137
code ,
138
138
'A string or object with a `code` or `fixture` property must be provided' ,
@@ -146,16 +146,17 @@ function pluginTester({
146
146
'`output` cannot be provided with `snapshot: true`' ,
147
147
)
148
148
149
- let result
149
+ let result , transformed
150
150
let errored = false
151
151
152
152
try {
153
+ if ( babel . transformAsync ) {
154
+ transformed = await babel . transformAsync ( code , babelOptions )
155
+ } else {
156
+ transformed = babel . transform ( code , babelOptions )
157
+ }
153
158
result = formatResult (
154
- fixLineEndings (
155
- babel . transform ( code , babelOptions ) . code ,
156
- endOfLine ,
157
- code ,
158
- ) ,
159
+ fixLineEndings ( transformed . code , endOfLine , code ) ,
159
160
{ filename : testFilename } ,
160
161
)
161
162
} catch ( err ) {
@@ -293,7 +294,7 @@ const createFixtureTests = (fixturesDir, options) => {
293
294
return
294
295
}
295
296
296
- it ( blockTitle , ( ) => {
297
+ it ( blockTitle , async ( ) => {
297
298
const {
298
299
plugin,
299
300
pluginOptions,
@@ -335,17 +336,23 @@ const createFixtureTests = (fixturesDir, options) => {
335
336
)
336
337
337
338
const input = fs . readFileSync ( codePath ) . toString ( )
339
+ let transformed , ext
340
+ if ( babel . transformAsync ) {
341
+ transformed = await babel . transformAsync ( input , {
342
+ ...babelOptions ,
343
+ filename : codePath ,
344
+ } )
345
+ } else {
346
+ transformed = babel . transform ( input , {
347
+ ...babelOptions ,
348
+ filename : codePath ,
349
+ } )
350
+ }
338
351
const actual = formatResult (
339
- fixLineEndings (
340
- babel . transformSync ( input , { ...babelOptions , filename : codePath } )
341
- . code ,
342
- endOfLine ,
343
- input ,
344
- ) ,
352
+ fixLineEndings ( transformed . code , endOfLine , input ) ,
345
353
)
346
354
347
355
const { fixtureOutputExt} = fixturePluginOptions
348
- let ext
349
356
if ( fixtureOutputExt ) {
350
357
ext = fixtureOutputExt
351
358
} else {
0 commit comments