Skip to content

Commit e4f317e

Browse files
committed
Initial draft of unit-tests for server
1 parent cb76f64 commit e4f317e

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

__tests__/__snapshots__/index.js.snap

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ Object {
116116
"NavLink": [Function],
117117
"ScalableRect": [Function],
118118
"config": Config {
119-
"dummyConfigKey": "Dummy config value",
119+
"SECRET": Object {
120+
"dummySecretKey": "Dummy Secret Value",
121+
},
122+
"dummyKey": "Dummy Value",
120123
},
121124
"isomorphy": Object {
122125
"buildTimestamp": [Function],

__tests__/server/server.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import _ from 'lodash';
2+
import serverFactory from 'server/server';
3+
4+
jest.mock('serve-favicon', () => jest.fn(() => (req, res, next) => next()));
5+
6+
jest.mock('webpack', () => {
7+
const mock = () => ({
8+
apply: jest.fn(),
9+
plugin: jest.fn(),
10+
watch: jest.fn(),
11+
});
12+
mock.ProgressPlugin = Object;
13+
return mock;
14+
});
15+
16+
jest.mock('webpack-hot-middleware', () =>
17+
jest.fn(() => (req, res, next) => next()));
18+
19+
const TEST_CONTEXT = `${__dirname}/test_data`;
20+
21+
const TEST_FAVICON_PATH = '/path/to/favicon.ico';
22+
23+
const TEST_WEBPACK_CONFIG = {
24+
context: TEST_CONTEXT,
25+
output: {
26+
path: '/path/to/assets',
27+
publicPath: '/test/public/path/',
28+
},
29+
};
30+
31+
afterEach(() => {
32+
delete process.env.DEV_TOOLS;
33+
jest.resetAllMocks();
34+
});
35+
36+
test('Favicon support', () => {
37+
const server = serverFactory(TEST_WEBPACK_CONFIG, {
38+
favicon: _.clone(TEST_FAVICON_PATH),
39+
});
40+
expect(require('serve-favicon')).toHaveBeenCalledWith(TEST_FAVICON_PATH);
41+
return server;
42+
});
43+
44+
test('Launch with dev tools', () => {
45+
process.env.DEV_TOOLS = true;
46+
const server = serverFactory(TEST_WEBPACK_CONFIG, {});
47+
return server;
48+
});

0 commit comments

Comments
 (0)