@@ -43,198 +43,211 @@ afterEach(() => {
43
43
}
44
44
} ) ;
45
45
46
- describe . each (
47
- [
48
- { babel : require ( '@babel/core' ) , version : '7' } ,
49
- Number . parseInt ( process . versions . node ) >= 20 && {
50
- babel : originalNodeRequire ( '@babel-8/core' ) ,
51
- version : '8' ,
52
- } ,
53
- ] . filter ( x => x !== false ) ,
54
- ) ( 'babel $version' , ( { babel} ) => {
55
- describe ( 'getCacheKey' , ( ) => {
56
- const sourceText = 'mock source' ;
57
- const sourcePath = 'mock-source-path.js' ;
58
-
59
- const transformOptions = {
60
- config : { rootDir : 'mock-root-dir' } ,
61
- configString : 'mock-config-string' ,
62
- instrument : true ,
63
- } as TransformOptions < BabelTransformOptions > ;
64
-
65
- const oldCacheKey = getCacheKey ! ( sourceText , sourcePath , transformOptions ) ;
66
-
67
- test ( 'returns cache key hash' , ( ) => {
68
- expect ( oldCacheKey ) . toHaveLength ( 32 ) ;
69
- } ) ;
70
-
71
- test ( 'if `THIS_FILE` value is changing' , async ( ) => {
72
- jest . doMock ( 'graceful-fs' , ( ) => ( {
73
- readFileSync : ( ) => 'new this file' ,
74
- } ) ) ;
75
-
76
- const { createTransformer} =
77
- require ( '../index' ) as typeof import ( '../index' ) ;
78
-
79
- const newCacheKey = ( await createTransformer ( ) ) . getCacheKey ! (
46
+ const babelVersions = [
47
+ { babel : require ( '@babel/core' ) , version : '7' } ,
48
+ {
49
+ babel :
50
+ Number . parseInt ( process . versions . node , 10 ) >= 20 &&
51
+ originalNodeRequire ( '@babel-8/core' ) ,
52
+ version : '8' ,
53
+ } ,
54
+ ] ;
55
+
56
+ describe . skip . each ( babelVersions . filter ( x => ! x . babel ) ) (
57
+ 'babel $version' ,
58
+ ( ) => { } ,
59
+ ) ;
60
+ describe . each ( babelVersions . filter ( x => x . babel ) ) (
61
+ 'babel $version' ,
62
+ ( { babel} ) => {
63
+ describe ( 'getCacheKey' , ( ) => {
64
+ const sourceText = 'mock source' ;
65
+ const sourcePath = 'mock-source-path.js' ;
66
+
67
+ const transformOptions = {
68
+ config : { rootDir : 'mock-root-dir' } ,
69
+ configString : 'mock-config-string' ,
70
+ instrument : true ,
71
+ } as TransformOptions < BabelTransformOptions > ;
72
+
73
+ const oldCacheKey = getCacheKey ! (
80
74
sourceText ,
81
75
sourcePath ,
82
76
transformOptions ,
83
77
) ;
84
78
85
- expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
86
- } ) ;
87
-
88
- test ( 'if `babelOptions.options` value is changing' , async ( ) => {
89
- jest . doMock ( '../babel' , ( ) => {
90
- return {
91
- ...babel ,
92
- loadPartialConfigSync : (
93
- options : Parameters < typeof babel . loadPartialConfigSync > [ 0 ] ,
94
- ) => ( {
95
- ...babel . loadPartialConfigSync ( options ) ,
96
- options : 'new-options' ,
97
- } ) ,
98
- } ;
79
+ test ( 'returns cache key hash' , ( ) => {
80
+ expect ( oldCacheKey ) . toHaveLength ( 32 ) ;
99
81
} ) ;
100
82
101
- const { createTransformer} =
102
- require ( '../index' ) as typeof import ( '../index' ) ;
83
+ test ( 'if `THIS_FILE` value is changing' , async ( ) => {
84
+ jest . doMock ( 'graceful-fs' , ( ) => ( {
85
+ readFileSync : ( ) => 'new this file' ,
86
+ } ) ) ;
103
87
104
- const newCacheKey = ( await createTransformer ( ) ) . getCacheKey ! (
105
- sourceText ,
106
- sourcePath ,
107
- transformOptions ,
108
- ) ;
88
+ const { createTransformer} =
89
+ require ( '../index' ) as typeof import ( '../index' ) ;
109
90
110
- expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
111
- } ) ;
112
-
113
- test ( 'if `sourceText` value is changing' , ( ) => {
114
- const newCacheKey = getCacheKey ! (
115
- 'new source text' ,
116
- sourcePath ,
117
- transformOptions ,
118
- ) ;
91
+ const newCacheKey = ( await createTransformer ( ) ) . getCacheKey ! (
92
+ sourceText ,
93
+ sourcePath ,
94
+ transformOptions ,
95
+ ) ;
119
96
120
- expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
121
- } ) ;
97
+ expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
98
+ } ) ;
122
99
123
- test ( 'if `sourcePath` value is changing' , ( ) => {
124
- const newCacheKey = getCacheKey ! (
125
- sourceText ,
126
- 'new-source-path.js' ,
127
- transformOptions ,
128
- ) ;
100
+ test ( 'if `babelOptions.options` value is changing' , async ( ) => {
101
+ jest . doMock ( '../babel' , ( ) => {
102
+ return {
103
+ ...babel ,
104
+ loadPartialConfigSync : (
105
+ options : Parameters < typeof babel . loadPartialConfigSync > [ 0 ] ,
106
+ ) => ( {
107
+ ...babel . loadPartialConfigSync ( options ) ,
108
+ options : 'new-options' ,
109
+ } ) ,
110
+ } ;
111
+ } ) ;
112
+
113
+ const { createTransformer} =
114
+ require ( '../index' ) as typeof import ( '../index' ) ;
115
+
116
+ const newCacheKey = ( await createTransformer ( ) ) . getCacheKey ! (
117
+ sourceText ,
118
+ sourcePath ,
119
+ transformOptions ,
120
+ ) ;
121
+
122
+ expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
123
+ } ) ;
129
124
130
- expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
131
- } ) ;
125
+ test ( 'if `sourceText` value is changing' , ( ) => {
126
+ const newCacheKey = getCacheKey ! (
127
+ 'new source text' ,
128
+ sourcePath ,
129
+ transformOptions ,
130
+ ) ;
132
131
133
- test ( 'if `configString` value is changing' , ( ) => {
134
- const newCacheKey = getCacheKey ! ( sourceText , sourcePath , {
135
- ...transformOptions ,
136
- configString : 'new-config-string' ,
132
+ expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
137
133
} ) ;
138
134
139
- expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
140
- } ) ;
135
+ test ( 'if `sourcePath` value is changing' , ( ) => {
136
+ const newCacheKey = getCacheKey ! (
137
+ sourceText ,
138
+ 'new-source-path.js' ,
139
+ transformOptions ,
140
+ ) ;
141
141
142
- test ( 'if `babelOptions.config` value is changing' , async ( ) => {
143
- jest . doMock ( '../babel' , ( ) => {
144
- return {
145
- ...babel ,
146
- loadPartialConfigSync : (
147
- options : Parameters < typeof babel . loadPartialConfigSync > [ 0 ] ,
148
- ) => ( {
149
- ...babel . loadPartialConfigSync ( options ) ,
150
- config : 'new-config' ,
151
- } ) ,
152
- } ;
142
+ expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
153
143
} ) ;
154
144
155
- const { createTransformer} =
156
- require ( '../index' ) as typeof import ( '../index' ) ;
145
+ test ( 'if `configString` value is changing' , ( ) => {
146
+ const newCacheKey = getCacheKey ! ( sourceText , sourcePath , {
147
+ ...transformOptions ,
148
+ configString : 'new-config-string' ,
149
+ } ) ;
157
150
158
- const newCacheKey = ( await createTransformer ( ) ) . getCacheKey ! (
159
- sourceText ,
160
- sourcePath ,
161
- transformOptions ,
162
- ) ;
163
-
164
- expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
165
- } ) ;
166
-
167
- test ( 'if `babelOptions.babelrc` value is changing' , async ( ) => {
168
- jest . doMock ( '../babel' , ( ) => {
169
- return {
170
- ...babel ,
171
- loadPartialConfig : (
172
- options : Parameters < typeof babel . loadPartialConfig > [ 0 ] ,
173
- ) => ( {
174
- ...babel . loadPartialConfig ( options ) ,
175
- babelrc : 'new-babelrc' ,
176
- } ) ,
177
- } ;
151
+ expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
178
152
} ) ;
179
153
180
- const { createTransformer} =
181
- require ( '../index' ) as typeof import ( '../index' ) ;
154
+ test ( 'if `babelOptions.config` value is changing' , async ( ) => {
155
+ jest . doMock ( '../babel' , ( ) => {
156
+ return {
157
+ ...babel ,
158
+ loadPartialConfigSync : (
159
+ options : Parameters < typeof babel . loadPartialConfigSync > [ 0 ] ,
160
+ ) => ( {
161
+ ...babel . loadPartialConfigSync ( options ) ,
162
+ config : 'new-config' ,
163
+ } ) ,
164
+ } ;
165
+ } ) ;
166
+
167
+ const { createTransformer} =
168
+ require ( '../index' ) as typeof import ( '../index' ) ;
169
+
170
+ const newCacheKey = ( await createTransformer ( ) ) . getCacheKey ! (
171
+ sourceText ,
172
+ sourcePath ,
173
+ transformOptions ,
174
+ ) ;
175
+
176
+ expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
177
+ } ) ;
182
178
183
- const newCacheKey = ( await createTransformer ( ) ) . getCacheKey ! (
184
- sourceText ,
185
- sourcePath ,
186
- transformOptions ,
187
- ) ;
179
+ test ( 'if `babelOptions.babelrc` value is changing' , async ( ) => {
180
+ jest . doMock ( '../babel' , ( ) => {
181
+ return {
182
+ ...babel ,
183
+ loadPartialConfig : (
184
+ options : Parameters < typeof babel . loadPartialConfig > [ 0 ] ,
185
+ ) => ( {
186
+ ...babel . loadPartialConfig ( options ) ,
187
+ babelrc : 'new-babelrc' ,
188
+ } ) ,
189
+ } ;
190
+ } ) ;
191
+
192
+ const { createTransformer} =
193
+ require ( '../index' ) as typeof import ( '../index' ) ;
194
+
195
+ const newCacheKey = ( await createTransformer ( ) ) . getCacheKey ! (
196
+ sourceText ,
197
+ sourcePath ,
198
+ transformOptions ,
199
+ ) ;
200
+
201
+ expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
202
+ } ) ;
188
203
189
- expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
190
- } ) ;
204
+ test ( 'if `instrument` value is changing' , ( ) => {
205
+ const newCacheKey = getCacheKey ! ( sourceText , sourcePath , {
206
+ ...transformOptions ,
207
+ instrument : false ,
208
+ } ) ;
191
209
192
- test ( 'if `instrument` value is changing' , ( ) => {
193
- const newCacheKey = getCacheKey ! ( sourceText , sourcePath , {
194
- ...transformOptions ,
195
- instrument : false ,
210
+ expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
196
211
} ) ;
197
212
198
- expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
199
- } ) ;
213
+ test ( 'if `process.env.NODE_ENV` value is changing' , ( ) => {
214
+ process . env . NODE_ENV = 'NEW_NODE_ENV' ;
200
215
201
- test ( 'if `process.env.NODE_ENV` value is changing' , ( ) => {
202
- process . env . NODE_ENV = 'NEW_NODE_ENV' ;
216
+ const newCacheKey = getCacheKey ! (
217
+ sourceText ,
218
+ sourcePath ,
219
+ transformOptions ,
220
+ ) ;
203
221
204
- const newCacheKey = getCacheKey ! (
205
- sourceText ,
206
- sourcePath ,
207
- transformOptions ,
208
- ) ;
209
-
210
- expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
211
- } ) ;
222
+ expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
223
+ } ) ;
212
224
213
- test ( 'if `process.env.BABEL_ENV` value is changing' , ( ) => {
214
- process . env . BABEL_ENV = 'NEW_BABEL_ENV' ;
225
+ test ( 'if `process.env.BABEL_ENV` value is changing' , ( ) => {
226
+ process . env . BABEL_ENV = 'NEW_BABEL_ENV' ;
215
227
216
- const newCacheKey = getCacheKey ! (
217
- sourceText ,
218
- sourcePath ,
219
- transformOptions ,
220
- ) ;
228
+ const newCacheKey = getCacheKey ! (
229
+ sourceText ,
230
+ sourcePath ,
231
+ transformOptions ,
232
+ ) ;
221
233
222
- expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
223
- } ) ;
234
+ expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
235
+ } ) ;
224
236
225
- test ( 'if node version is changing' , ( ) => {
226
- // @ts -expect-error: Testing purpose
227
- delete process . version ;
228
- // @ts -expect-error: Testing purpose
229
- process . version = 'new-node-version' ;
237
+ test ( 'if node version is changing' , ( ) => {
238
+ // @ts -expect-error: Testing purpose
239
+ delete process . version ;
240
+ // @ts -expect-error: Testing purpose
241
+ process . version = 'new-node-version' ;
230
242
231
- const newCacheKey = getCacheKey ! (
232
- sourceText ,
233
- sourcePath ,
234
- transformOptions ,
235
- ) ;
243
+ const newCacheKey = getCacheKey ! (
244
+ sourceText ,
245
+ sourcePath ,
246
+ transformOptions ,
247
+ ) ;
236
248
237
- expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
249
+ expect ( oldCacheKey ) . not . toEqual ( newCacheKey ) ;
250
+ } ) ;
238
251
} ) ;
239
- } ) ;
240
- } ) ;
252
+ } ,
253
+ ) ;
0 commit comments