File tree Expand file tree Collapse file tree 3 files changed +74
-1
lines changed Expand file tree Collapse file tree 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) {
103103 contentType += '; charset=UTF-8' ;
104104 }
105105
106- if ( ! res . getHeader ( 'Content-Type' ) ) {
106+ if ( ! res . getHeader || ! res . getHeader ( 'Content-Type' ) ) {
107107 res . setHeader ( 'Content-Type' , contentType ) ;
108108 }
109109
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');
99
1010const middleware = require ( '../' ) ;
1111
12+ const { mockRequest, mockResponse } = require ( './mock-express' ) ;
13+
1214const webpackConfig = require ( './fixtures/server-test/webpack.config' ) ;
1315const webpackMultiConfig = require ( './fixtures/server-test/webpack.array.config' ) ;
1416const webpackQuerystringConfig = require ( './fixtures/server-test/webpack.querystring.config' ) ;
@@ -311,6 +313,35 @@ describe('Server', () => {
311313 } ) ;
312314 } ) ;
313315
316+ /**
317+ * ref: #385, for that [email protected] 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+
314345 describe ( 'custom mimeTypes' , ( ) => {
315346 beforeAll ( ( done ) => {
316347 app = express ( ) ;
You can’t perform that action at this time.
0 commit comments