@@ -33,20 +33,38 @@ function applyTransform(module, options, input, testOptions = {}) {
33
33
options || { }
34
34
) ;
35
35
36
+ // Support async transforms
37
+ if ( output instanceof Promise ) {
38
+ return output . then ( output => ( output || '' ) . trim ( ) ) ;
39
+ }
40
+
36
41
return ( output || '' ) . trim ( ) ;
37
42
}
38
43
exports . applyTransform = applyTransform ;
39
44
40
45
function runSnapshotTest ( module , options , input ) {
41
46
const output = applyTransform ( module , options , input ) ;
47
+ if ( output instanceof Promise ) {
48
+ return output . then ( output => {
49
+ expect ( output ) . toMatchSnapshot ( ) ;
50
+ return output ;
51
+ } ) ;
52
+ }
42
53
expect ( output ) . toMatchSnapshot ( ) ;
43
54
return output ;
44
55
}
45
56
exports . runSnapshotTest = runSnapshotTest ;
46
57
47
58
function runInlineTest ( module , options , input , expectedOutput , testOptions ) {
48
59
const output = applyTransform ( module , options , input , testOptions ) ;
49
- expect ( output ) . toEqual ( expectedOutput . trim ( ) ) ;
60
+ const expectation = ( output => expect ( output ) . toEqual ( expectedOutput . trim ( ) ) )
61
+ if ( output instanceof Promise ) {
62
+ return output . then ( output => {
63
+ expectation ( output ) ;
64
+ return output ;
65
+ } ) ;
66
+ }
67
+ expectation ( output ) ;
50
68
return output ;
51
69
}
52
70
exports . runInlineTest = runInlineTest ;
@@ -95,10 +113,12 @@ function runTest(dirName, transformName, options, testFilePrefix, testOptions =
95
113
path . join ( fixtureDir , testFilePrefix + `.output.${ extension } ` ) ,
96
114
'utf8'
97
115
) ;
98
- runInlineTest ( module , options , {
116
+ const testResult = runInlineTest ( module , options , {
99
117
path : inputPath ,
100
118
source
101
119
} , expectedOutput , testOptions ) ;
120
+
121
+ return testResult instanceof Promise ? testResult : undefined ;
102
122
}
103
123
exports . runTest = runTest ;
104
124
@@ -112,26 +132,29 @@ function defineTest(dirName, transformName, options, testFilePrefix, testOptions
112
132
: 'transforms correctly' ;
113
133
describe ( transformName , ( ) => {
114
134
it ( testName , ( ) => {
115
- runTest ( dirName , transformName , options , testFilePrefix , testOptions ) ;
135
+ const testResult = runTest ( dirName , transformName , options , testFilePrefix , testOptions ) ;
136
+ return testResult instanceof Promise ? testResult : undefined ;
116
137
} ) ;
117
138
} ) ;
118
139
}
119
140
exports . defineTest = defineTest ;
120
141
121
142
function defineInlineTest ( module , options , input , expectedOutput , testName ) {
122
143
it ( testName || 'transforms correctly' , ( ) => {
123
- runInlineTest ( module , options , {
144
+ const testResult = runInlineTest ( module , options , {
124
145
source : input
125
146
} , expectedOutput ) ;
147
+ return testResult instanceof Promise ? testResult : undefined ;
126
148
} ) ;
127
149
}
128
150
exports . defineInlineTest = defineInlineTest ;
129
151
130
152
function defineSnapshotTest ( module , options , input , testName ) {
131
153
it ( testName || 'transforms correctly' , ( ) => {
132
- runSnapshotTest ( module , options , {
154
+ const testResult = runSnapshotTest ( module , options , {
133
155
source : input
134
156
} ) ;
157
+ return testResult instanceof Promise ? testResult : undefined ;
135
158
} ) ;
136
159
}
137
160
exports . defineSnapshotTest = defineSnapshotTest ;
@@ -144,6 +167,7 @@ function defineSnapshotTestFromFixture(dirName, module, options, testFilePrefix,
144
167
const fixtureDir = path . join ( dirName , '..' , '__testfixtures__' ) ;
145
168
const inputPath = path . join ( fixtureDir , testFilePrefix + `.input.${ extension } ` ) ;
146
169
const source = fs . readFileSync ( inputPath , 'utf8' ) ;
147
- defineSnapshotTest ( module , options , source , testName )
170
+ const testResult = defineSnapshotTest ( module , options , source , testName )
171
+ return testResult instanceof Promise ? testResult : undefined ;
148
172
}
149
173
exports . defineSnapshotTestFromFixture = defineSnapshotTestFromFixture ;
0 commit comments