Skip to content

Commit c0e0e45

Browse files
committed
test: add test case
1 parent 3316c46 commit c0e0e45

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

test/mock-express/index.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 };

test/server.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const request = require('supertest');
99

1010
const middleware = require('../');
1111

12+
const { mockRequest, mockResponse } = require('./mock-express');
13+
1214
const webpackConfig = require('./fixtures/server-test/webpack.config');
1315
const webpackMultiConfig = require('./fixtures/server-test/webpack.array.config');
1416
const webpackQuerystringConfig = require('./fixtures/server-test/webpack.querystring.config');
@@ -311,6 +313,31 @@ describe('Server', () => {
311313
});
312314
});
313315

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+
314341
describe('custom mimeTypes', () => {
315342
beforeAll((done) => {
316343
app = express();

0 commit comments

Comments
 (0)