@@ -20,31 +20,20 @@ test('assets should should be reversed', () => {
20
20
expect ( new AddAssetHtmlPlugin ( [ 'a' , 'b' ] ) . assets ) . toEqual ( [ 'b' , 'a' ] ) ;
21
21
} ) ;
22
22
23
- test ( 'should invoke callback on success' , async ( ) => {
24
- const callback = jest . fn ( ) ;
25
-
26
- await addAllAssetsToCompilation ( [ ] , { } , pluginMock , callback ) ;
27
-
28
- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
29
- expect ( callback ) . toHaveBeenCalledWith ( null , pluginMock ) ;
30
- } ) ;
31
-
32
23
test ( 'should not reject success' , async ( ) => {
33
24
expect ( await addAllAssetsToCompilation ( [ ] , { } , pluginMock ) ) . toEqual (
34
25
pluginMock ,
35
26
) ;
36
27
} ) ;
37
28
38
29
test ( 'should invoke callback on error' , async ( ) => {
39
- const callback = jest . fn ( ) ;
40
30
const compilation = { errors : [ ] } ;
41
31
42
- await addAllAssetsToCompilation ( [ { } ] , compilation , pluginMock , callback ) ;
32
+ await expect (
33
+ addAllAssetsToCompilation ( [ { } ] , compilation , pluginMock ) ,
34
+ ) . rejects . toThrowError ( ) ;
43
35
44
36
expect ( compilation . errors ) . toMatchSnapshot ( ) ;
45
-
46
- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
47
- expect ( callback ) . toHaveBeenCalledWith ( compilation . errors [ 0 ] , pluginMock ) ;
48
37
} ) ;
49
38
50
39
test ( 'should reject on error' , async ( ) => {
@@ -60,64 +49,48 @@ test('should reject on error', async () => {
60
49
} ) ;
61
50
62
51
test ( "should add file using compilation's publicPath" , async ( ) => {
63
- const callback = jest . fn ( ) ;
64
52
const compilation = { options : { output : { publicPath : 'vendor/' } } } ;
65
53
const pluginData = Object . assign ( { assets : { js : [ ] , css : [ ] } } , pluginMock ) ;
66
54
67
55
await addAllAssetsToCompilation (
68
56
[ { filepath : path . join ( __dirname , 'my-file.js' ) } ] ,
69
57
compilation ,
70
58
pluginData ,
71
- callback ,
72
59
) ;
73
60
74
61
expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
75
-
76
- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
77
- expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
78
62
} ) ;
79
63
80
64
test ( 'should used passed in publicPath' , async ( ) => {
81
- const callback = jest . fn ( ) ;
82
65
const compilation = { options : { output : { publicPath : 'vendor/' } } } ;
83
66
const pluginData = Object . assign ( { assets : { js : [ ] , css : [ ] } } , pluginMock ) ;
84
67
85
68
await addAllAssetsToCompilation (
86
69
[ { filepath : 'my-file.js' , publicPath : 'pp' } ] ,
87
70
compilation ,
88
71
pluginData ,
89
- callback ,
90
72
) ;
91
73
92
74
expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
93
-
94
- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
95
- expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
96
75
} ) ;
97
76
98
77
// TODO: No idea what this does, actually... Coverage currently hits it, but the logic is untested.
99
78
test . skip ( 'should handle missing `publicPath`' , ( ) => { } ) ;
100
79
101
80
test ( 'should add file missing "/" to public path' , async ( ) => {
102
- const callback = jest . fn ( ) ;
103
81
const compilation = { options : { output : { publicPath : 'vendor' } } } ;
104
82
const pluginData = Object . assign ( { assets : { js : [ ] , css : [ ] } } , pluginMock ) ;
105
83
106
84
await addAllAssetsToCompilation (
107
85
[ { filepath : 'my-file.js' } ] ,
108
86
compilation ,
109
87
pluginData ,
110
- callback ,
111
88
) ;
112
89
113
90
expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
114
-
115
- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
116
- expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
117
91
} ) ;
118
92
119
93
test ( 'should add sourcemap to compilation' , async ( ) => {
120
- const callback = jest . fn ( ) ;
121
94
const addFileToAssetsStub = jest . fn ( ) ;
122
95
const compilation = { options : { output : { } } } ;
123
96
const pluginData = {
@@ -130,14 +103,10 @@ test('should add sourcemap to compilation', async () => {
130
103
[ { filepath : 'my-file.js' } ] ,
131
104
compilation ,
132
105
pluginData ,
133
- callback ,
134
106
) ;
135
107
136
108
expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
137
109
138
- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
139
- expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
140
-
141
110
expect ( addFileToAssetsStub ) . toHaveBeenCalledTimes ( 2 ) ;
142
111
expect ( addFileToAssetsStub . mock . calls [ 0 ] ) . toEqual ( [
143
112
'my-file.js' ,
@@ -150,7 +119,6 @@ test('should add sourcemap to compilation', async () => {
150
119
} ) ;
151
120
152
121
test ( 'should skip adding sourcemap to compilation if set to false' , async ( ) => {
153
- const callback = jest . fn ( ) ;
154
122
const addFileToAssetsStub = jest . fn ( ) ;
155
123
const compilation = { options : { output : { } } } ;
156
124
const pluginData = {
@@ -163,20 +131,15 @@ test('should skip adding sourcemap to compilation if set to false', async () =>
163
131
[ { filepath : 'my-file.js' , includeSourcemap : false } ] ,
164
132
compilation ,
165
133
pluginData ,
166
- callback ,
167
134
) ;
168
135
169
136
expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
170
137
171
- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
172
- expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
173
-
174
138
expect ( addFileToAssetsStub ) . toHaveBeenCalledTimes ( 1 ) ;
175
139
expect ( addFileToAssetsStub ) . toHaveBeenCalledWith ( 'my-file.js' , compilation ) ;
176
140
} ) ;
177
141
178
142
test ( 'should include hash of file content if option is set' , async ( ) => {
179
- const callback = jest . fn ( ) ;
180
143
const compilation = {
181
144
options : { output : { } } ,
182
145
assets : {
@@ -189,17 +152,12 @@ test('should include hash of file content if option is set', async () => {
189
152
[ { filepath : 'my-file.js' , hash : true } ] ,
190
153
compilation ,
191
154
pluginData ,
192
- callback ,
193
155
) ;
194
156
195
157
expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
196
-
197
- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
198
- expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
199
158
} ) ;
200
159
201
160
test ( 'should add to css if `typeOfAsset` is css' , async ( ) => {
202
- const callback = jest . fn ( ) ;
203
161
const compilation = {
204
162
options : { output : { } } ,
205
163
assets : {
@@ -212,17 +170,12 @@ test('should add to css if `typeOfAsset` is css', async () => {
212
170
[ { filepath : 'my-file.css' , typeOfAsset : 'css' } ] ,
213
171
compilation ,
214
172
pluginData ,
215
- callback ,
216
173
) ;
217
174
218
175
expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
219
-
220
- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
221
- expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
222
176
} ) ;
223
177
224
178
test ( 'should replace compilation assets key if `outputPath` is set' , async ( ) => {
225
- const callback = jest . fn ( ) ;
226
179
const source = { source : ( ) => 'test' } ;
227
180
const addFileToAssetsMock = ( filename , compilation ) => {
228
181
const name = path . basename ( filename ) ;
@@ -242,7 +195,6 @@ test('should replace compilation assets key if `outputPath` is set', async () =>
242
195
[ { filepath : 'my-file.js' , outputPath : 'assets' } ] ,
243
196
compilation ,
244
197
pluginData ,
245
- callback ,
246
198
) ;
247
199
248
200
expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
@@ -254,7 +206,6 @@ test('should replace compilation assets key if `outputPath` is set', async () =>
254
206
} ) ;
255
207
256
208
test ( 'filter option should exclude some files' , async ( ) => {
257
- const callback = jest . fn ( ) ;
258
209
const compilation = { options : { output : { publicPath : 'vendor/' } } } ;
259
210
const pluginData = Object . assign ( { assets : { js : [ ] , css : [ ] } } , pluginMock ) ;
260
211
@@ -267,49 +218,35 @@ test('filter option should exclude some files', async () => {
267
218
] ,
268
219
compilation ,
269
220
pluginData ,
270
- callback ,
271
221
) ;
272
222
273
223
expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
274
-
275
- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
276
- expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
277
224
} ) ;
278
225
279
226
test ( 'filter option should include some files' , async ( ) => {
280
- const callback = jest . fn ( ) ;
281
227
const compilation = { options : { output : { publicPath : 'vendor/' } } } ;
282
228
const pluginData = Object . assign ( { assets : { js : [ ] , css : [ ] } } , pluginMock ) ;
283
229
284
230
await addAllAssetsToCompilation (
285
231
[ { filepath : path . join ( __dirname , 'my-file.js' ) , files : [ 'index.*' ] } ] ,
286
232
compilation ,
287
233
pluginData ,
288
- callback ,
289
234
) ;
290
235
291
236
expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
292
-
293
- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
294
- expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
295
237
} ) ;
296
238
297
239
test ( 'filter option should include some files with string option' , async ( ) => {
298
- const callback = jest . fn ( ) ;
299
240
const compilation = { options : { output : { publicPath : 'vendor/' } } } ;
300
241
const pluginData = Object . assign ( { assets : { js : [ ] , css : [ ] } } , pluginMock ) ;
301
242
302
243
await addAllAssetsToCompilation (
303
244
[ { filepath : path . join ( __dirname , 'my-file.js' ) , files : 'index.*' } ] ,
304
245
compilation ,
305
246
pluginData ,
306
- callback ,
307
247
) ;
308
248
309
249
expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
310
-
311
- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
312
- expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
313
250
} ) ;
314
251
315
252
test ( 'use globby to find multi file' , async ( ) => {
0 commit comments