File tree 3 files changed +74
-1
lines changed
3 files changed +74
-1
lines changed Original file line number Diff line number Diff line change @@ -103,7 +103,7 @@ module.exports = function wrapper(context) {
103
103
contentType += '; charset=UTF-8' ;
104
104
}
105
105
106
- if ( ! res . getHeader ( 'Content-Type' ) ) {
106
+ if ( ! res . getHeader || ! res . getHeader ( 'Content-Type' ) ) {
107
107
res . setHeader ( 'Content-Type' , contentType ) ;
108
108
}
109
109
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const mockRequest = ( options = { } ) =>
4
+ Object . assign (
5
+ {
6
+ body : { } ,
7
+ cookies : { } ,
8
+ query : { } ,
9
+ params : { } ,
10
+ get : jest . fn ( ) ,
11
+ } ,
12
+ options
13
+ ) ;
14
+
15
+ const mockResponse = ( options = { } ) => {
16
+ const res = Object . assign (
17
+ {
18
+ cookie : jest . fn ( ) ,
19
+ clearCookie : jest . fn ( ) ,
20
+ download : jest . fn ( ) ,
21
+ format : jest . fn ( ) ,
22
+ json : jest . fn ( ) ,
23
+ jsonp : jest . fn ( ) ,
24
+ send : jest . fn ( ) ,
25
+ sendFile : jest . fn ( ) ,
26
+ sendStatus : jest . fn ( ) ,
27
+ setHeader : jest . fn ( ) ,
28
+ redirect : jest . fn ( ) ,
29
+ render : jest . fn ( ) ,
30
+ end : jest . fn ( ) ,
31
+ set : jest . fn ( ) ,
32
+ type : jest . fn ( ) ,
33
+ get : jest . fn ( ) ,
34
+ } ,
35
+ options
36
+ ) ;
37
+ res . status = jest . fn ( ( ) => res ) ;
38
+ res . vary = jest . fn ( ( ) => res ) ;
39
+ return res ;
40
+ } ;
41
+
42
+ module . exports = { mockRequest, mockResponse } ;
Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ const request = require('supertest');
9
9
10
10
const middleware = require ( '../' ) ;
11
11
12
+ const { mockRequest, mockResponse } = require ( './mock-express' ) ;
13
+
12
14
const webpackConfig = require ( './fixtures/server-test/webpack.config' ) ;
13
15
const webpackMultiConfig = require ( './fixtures/server-test/webpack.array.config' ) ;
14
16
const webpackQuerystringConfig = require ( './fixtures/server-test/webpack.querystring.config' ) ;
@@ -311,6 +313,35 @@ describe('Server', () => {
311
313
} ) ;
312
314
} ) ;
313
315
316
+ /**
317
+ * ref: #385, for that koa-webpack@4.x doesn't pass in res.getHeader method.
318
+ */
319
+ describe ( 'Should work when res.getHeader is undefined' , ( ) => {
320
+ it ( 'should not throw error' , ( done ) => {
321
+ const req = mockRequest ( {
322
+ url : '/' ,
323
+ method : 'GET' ,
324
+ headers : {
325
+ Range : 'bytes=6000-' ,
326
+ } ,
327
+ } ) ;
328
+
329
+ const res = mockResponse ( {
330
+ getHeader : undefined ,
331
+ setHeader : jest . fn ( ) ,
332
+ } ) ;
333
+
334
+ const compiler = webpack ( webpackConfig ) ;
335
+ instance = middleware ( compiler , {
336
+ stats : 'errors-only' ,
337
+ logLevel,
338
+ } ) ;
339
+
340
+ instance ( req , res , jest . fn ( ) ) . then ( done ) ;
341
+ } ) ;
342
+ afterAll ( close ) ;
343
+ } ) ;
344
+
314
345
describe ( 'custom mimeTypes' , ( ) => {
315
346
beforeAll ( ( done ) => {
316
347
app = express ( ) ;
You can’t perform that action at this time.
0 commit comments