@@ -20,31 +20,20 @@ test('assets should should be reversed', () => {
2020 expect ( new AddAssetHtmlPlugin ( [ 'a' , 'b' ] ) . assets ) . toEqual ( [ 'b' , 'a' ] ) ;
2121} ) ;
2222
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-
3223test ( 'should not reject success' , async ( ) => {
3324 expect ( await addAllAssetsToCompilation ( [ ] , { } , pluginMock ) ) . toEqual (
3425 pluginMock ,
3526 ) ;
3627} ) ;
3728
3829test ( 'should invoke callback on error' , async ( ) => {
39- const callback = jest . fn ( ) ;
4030 const compilation = { errors : [ ] } ;
4131
42- await addAllAssetsToCompilation ( [ { } ] , compilation , pluginMock , callback ) ;
32+ await expect (
33+ addAllAssetsToCompilation ( [ { } ] , compilation , pluginMock ) ,
34+ ) . rejects . toThrowError ( ) ;
4335
4436 expect ( compilation . errors ) . toMatchSnapshot ( ) ;
45-
46- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
47- expect ( callback ) . toHaveBeenCalledWith ( compilation . errors [ 0 ] , pluginMock ) ;
4837} ) ;
4938
5039test ( 'should reject on error' , async ( ) => {
@@ -60,64 +49,48 @@ test('should reject on error', async () => {
6049} ) ;
6150
6251test ( "should add file using compilation's publicPath" , async ( ) => {
63- const callback = jest . fn ( ) ;
6452 const compilation = { options : { output : { publicPath : 'vendor/' } } } ;
6553 const pluginData = Object . assign ( { assets : { js : [ ] , css : [ ] } } , pluginMock ) ;
6654
6755 await addAllAssetsToCompilation (
6856 [ { filepath : path . join ( __dirname , 'my-file.js' ) } ] ,
6957 compilation ,
7058 pluginData ,
71- callback ,
7259 ) ;
7360
7461 expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
75-
76- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
77- expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
7862} ) ;
7963
8064test ( 'should used passed in publicPath' , async ( ) => {
81- const callback = jest . fn ( ) ;
8265 const compilation = { options : { output : { publicPath : 'vendor/' } } } ;
8366 const pluginData = Object . assign ( { assets : { js : [ ] , css : [ ] } } , pluginMock ) ;
8467
8568 await addAllAssetsToCompilation (
8669 [ { filepath : 'my-file.js' , publicPath : 'pp' } ] ,
8770 compilation ,
8871 pluginData ,
89- callback ,
9072 ) ;
9173
9274 expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
93-
94- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
95- expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
9675} ) ;
9776
9877// TODO: No idea what this does, actually... Coverage currently hits it, but the logic is untested.
9978test . skip ( 'should handle missing `publicPath`' , ( ) => { } ) ;
10079
10180test ( 'should add file missing "/" to public path' , async ( ) => {
102- const callback = jest . fn ( ) ;
10381 const compilation = { options : { output : { publicPath : 'vendor' } } } ;
10482 const pluginData = Object . assign ( { assets : { js : [ ] , css : [ ] } } , pluginMock ) ;
10583
10684 await addAllAssetsToCompilation (
10785 [ { filepath : 'my-file.js' } ] ,
10886 compilation ,
10987 pluginData ,
110- callback ,
11188 ) ;
11289
11390 expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
114-
115- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
116- expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
11791} ) ;
11892
11993test ( 'should add sourcemap to compilation' , async ( ) => {
120- const callback = jest . fn ( ) ;
12194 const addFileToAssetsStub = jest . fn ( ) ;
12295 const compilation = { options : { output : { } } } ;
12396 const pluginData = {
@@ -130,14 +103,10 @@ test('should add sourcemap to compilation', async () => {
130103 [ { filepath : 'my-file.js' } ] ,
131104 compilation ,
132105 pluginData ,
133- callback ,
134106 ) ;
135107
136108 expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
137109
138- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
139- expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
140-
141110 expect ( addFileToAssetsStub ) . toHaveBeenCalledTimes ( 2 ) ;
142111 expect ( addFileToAssetsStub . mock . calls [ 0 ] ) . toEqual ( [
143112 'my-file.js' ,
@@ -150,7 +119,6 @@ test('should add sourcemap to compilation', async () => {
150119} ) ;
151120
152121test ( 'should skip adding sourcemap to compilation if set to false' , async ( ) => {
153- const callback = jest . fn ( ) ;
154122 const addFileToAssetsStub = jest . fn ( ) ;
155123 const compilation = { options : { output : { } } } ;
156124 const pluginData = {
@@ -163,20 +131,15 @@ test('should skip adding sourcemap to compilation if set to false', async () =>
163131 [ { filepath : 'my-file.js' , includeSourcemap : false } ] ,
164132 compilation ,
165133 pluginData ,
166- callback ,
167134 ) ;
168135
169136 expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
170137
171- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
172- expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
173-
174138 expect ( addFileToAssetsStub ) . toHaveBeenCalledTimes ( 1 ) ;
175139 expect ( addFileToAssetsStub ) . toHaveBeenCalledWith ( 'my-file.js' , compilation ) ;
176140} ) ;
177141
178142test ( 'should include hash of file content if option is set' , async ( ) => {
179- const callback = jest . fn ( ) ;
180143 const compilation = {
181144 options : { output : { } } ,
182145 assets : {
@@ -189,17 +152,12 @@ test('should include hash of file content if option is set', async () => {
189152 [ { filepath : 'my-file.js' , hash : true } ] ,
190153 compilation ,
191154 pluginData ,
192- callback ,
193155 ) ;
194156
195157 expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
196-
197- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
198- expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
199158} ) ;
200159
201160test ( 'should add to css if `typeOfAsset` is css' , async ( ) => {
202- const callback = jest . fn ( ) ;
203161 const compilation = {
204162 options : { output : { } } ,
205163 assets : {
@@ -212,17 +170,12 @@ test('should add to css if `typeOfAsset` is css', async () => {
212170 [ { filepath : 'my-file.css' , typeOfAsset : 'css' } ] ,
213171 compilation ,
214172 pluginData ,
215- callback ,
216173 ) ;
217174
218175 expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
219-
220- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
221- expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
222176} ) ;
223177
224178test ( 'should replace compilation assets key if `outputPath` is set' , async ( ) => {
225- const callback = jest . fn ( ) ;
226179 const source = { source : ( ) => 'test' } ;
227180 const addFileToAssetsMock = ( filename , compilation ) => {
228181 const name = path . basename ( filename ) ;
@@ -242,7 +195,6 @@ test('should replace compilation assets key if `outputPath` is set', async () =>
242195 [ { filepath : 'my-file.js' , outputPath : 'assets' } ] ,
243196 compilation ,
244197 pluginData ,
245- callback ,
246198 ) ;
247199
248200 expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
@@ -254,7 +206,6 @@ test('should replace compilation assets key if `outputPath` is set', async () =>
254206} ) ;
255207
256208test ( 'filter option should exclude some files' , async ( ) => {
257- const callback = jest . fn ( ) ;
258209 const compilation = { options : { output : { publicPath : 'vendor/' } } } ;
259210 const pluginData = Object . assign ( { assets : { js : [ ] , css : [ ] } } , pluginMock ) ;
260211
@@ -267,49 +218,35 @@ test('filter option should exclude some files', async () => {
267218 ] ,
268219 compilation ,
269220 pluginData ,
270- callback ,
271221 ) ;
272222
273223 expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
274-
275- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
276- expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
277224} ) ;
278225
279226test ( 'filter option should include some files' , async ( ) => {
280- const callback = jest . fn ( ) ;
281227 const compilation = { options : { output : { publicPath : 'vendor/' } } } ;
282228 const pluginData = Object . assign ( { assets : { js : [ ] , css : [ ] } } , pluginMock ) ;
283229
284230 await addAllAssetsToCompilation (
285231 [ { filepath : path . join ( __dirname , 'my-file.js' ) , files : [ 'index.*' ] } ] ,
286232 compilation ,
287233 pluginData ,
288- callback ,
289234 ) ;
290235
291236 expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
292-
293- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
294- expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
295237} ) ;
296238
297239test ( 'filter option should include some files with string option' , async ( ) => {
298- const callback = jest . fn ( ) ;
299240 const compilation = { options : { output : { publicPath : 'vendor/' } } } ;
300241 const pluginData = Object . assign ( { assets : { js : [ ] , css : [ ] } } , pluginMock ) ;
301242
302243 await addAllAssetsToCompilation (
303244 [ { filepath : path . join ( __dirname , 'my-file.js' ) , files : 'index.*' } ] ,
304245 compilation ,
305246 pluginData ,
306- callback ,
307247 ) ;
308248
309249 expect ( pluginData . assets ) . toMatchSnapshot ( ) ;
310-
311- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
312- expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
313250} ) ;
314251
315252test ( 'use globby to find multi file' , async ( ) => {
0 commit comments