File tree Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const mockRequest = ( options = { } ) => {
4
+ return {
5
+ body : { } ,
6
+ cookies : { } ,
7
+ query : { } ,
8
+ params : { } ,
9
+ get : jest . fn ( ) ,
10
+ ...options ,
11
+ } ;
12
+ } ;
13
+
14
+ const mockResponse = ( options = { } ) => {
15
+ const res = {
16
+ cookie : jest . fn ( ) ,
17
+ clearCookie : jest . fn ( ) ,
18
+ download : jest . fn ( ) ,
19
+ format : jest . fn ( ) ,
20
+ json : jest . fn ( ) ,
21
+ jsonp : jest . fn ( ) ,
22
+ send : jest . fn ( ) ,
23
+ sendFile : jest . fn ( ) ,
24
+ sendStatus : jest . fn ( ) ,
25
+ setHeader : jest . fn ( ) ,
26
+ redirect : jest . fn ( ) ,
27
+ render : jest . fn ( ) ,
28
+ end : jest . fn ( ) ,
29
+ set : jest . fn ( ) ,
30
+ type : jest . fn ( ) ,
31
+ get : jest . fn ( ) ,
32
+ ...options ,
33
+ } ;
34
+ res . status = jest . fn ( ( ) => res ) ;
35
+ res . vary = jest . fn ( ( ) => res ) ;
36
+ return res ;
37
+ } ;
38
+
39
+ 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,31 @@ describe('Server', () => {
311
313
} ) ;
312
314
} ) ;
313
315
316
+ describe . only ( 'when res.setHeader is undefined' , ( ) => {
317
+ it ( 'should not throw error' , ( done ) => {
318
+ const req = mockRequest ( {
319
+ url : '/' ,
320
+ method : 'GET' ,
321
+ headers : {
322
+ Range : 'bytes=6000-' ,
323
+ } ,
324
+ } ) ;
325
+
326
+ const res = mockResponse ( {
327
+ getHeader : undefined ,
328
+ setHeader : jest . fn ( ) ,
329
+ } ) ;
330
+
331
+ const compiler = webpack ( webpackConfig ) ;
332
+ instance = middleware ( compiler , {
333
+ stats : 'errors-only' ,
334
+ logLevel,
335
+ } ) ;
336
+
337
+ instance ( req , res , jest . fn ( ) ) . then ( done ) ;
338
+ } ) ;
339
+ } ) ;
340
+
314
341
describe ( 'custom mimeTypes' , ( ) => {
315
342
beforeAll ( ( done ) => {
316
343
app = express ( ) ;
You can’t perform that action at this time.
0 commit comments