Skip to content

Commit 1f9f9dc

Browse files
hiroppyevilebottnawi
authored andcommitted
test(utils): increase coverage (#2156)
1 parent 9c171d1 commit 1f9f9dc

12 files changed

+273
-9
lines changed

lib/utils/runBonjour.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
22

3-
function runBonjour(options) {
3+
function runBonjour({ port }) {
44
const bonjour = require('bonjour')();
55

66
bonjour.publish({
77
name: 'Webpack Dev Server',
8-
port: options.port,
8+
port,
99
type: 'http',
1010
subtypes: ['webpack'],
1111
});

test/server/utils/ runBonjour.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
const runBonjour = require('../../../lib/utils/runBonjour');
4+
5+
describe('runBonjour', () => {
6+
let mock;
7+
let publish = jest.fn();
8+
let unpublishAll = jest.fn();
9+
10+
beforeAll(() => {
11+
mock = jest.mock('bonjour', () => () => {
12+
return {
13+
publish,
14+
unpublishAll,
15+
};
16+
});
17+
});
18+
19+
afterEach(() => {
20+
publish = jest.fn();
21+
unpublishAll = jest.fn();
22+
});
23+
24+
afterAll(() => {
25+
mock.mockRestore();
26+
});
27+
28+
it('should call bonjour.publish', () => {
29+
runBonjour({
30+
port: 1111,
31+
});
32+
33+
expect(publish.mock.calls[0][0]).toMatchSnapshot();
34+
});
35+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`runBonjour should call bonjour.publish 1`] = `
4+
Object {
5+
"name": "Webpack Dev Server",
6+
"port": 1111,
7+
"subtypes": Array [
8+
"webpack",
9+
],
10+
"type": "http",
11+
}
12+
`;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`colors error should disable color 1`] = `"test"`;
4+
5+
exports[`colors error should enable color 1`] = `"test"`;
6+
7+
exports[`colors info should disable color 1`] = `"test"`;
8+
9+
exports[`colors info should enable color 1`] = `"test"`;

test/server/utils/__snapshots__/createConfig.test.js.snap

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,21 @@ Object {
699699
}
700700
`;
701701

702+
exports[`createConfig liveReload option 1`] = `
703+
Object {
704+
"hot": true,
705+
"hotOnly": false,
706+
"liveReload": false,
707+
"noInfo": true,
708+
"port": 8080,
709+
"publicPath": "/",
710+
"stats": Object {
711+
"cached": false,
712+
"cachedAssets": false,
713+
},
714+
}
715+
`;
716+
702717
exports[`createConfig mimeTypes option - with force 1`] = `
703718
Object {
704719
"hot": true,
@@ -835,7 +850,22 @@ Object {
835850
}
836851
`;
837852

838-
exports[`createConfig overlay 1`] = `
853+
exports[`createConfig overlay option (in devServer config) 1`] = `
854+
Object {
855+
"hot": true,
856+
"hotOnly": false,
857+
"noInfo": true,
858+
"overlay": true,
859+
"port": 8080,
860+
"publicPath": "/",
861+
"stats": Object {
862+
"cached": false,
863+
"cachedAssets": false,
864+
},
865+
}
866+
`;
867+
868+
exports[`createConfig overlay option 1`] = `
839869
Object {
840870
"hot": true,
841871
"hotOnly": false,
@@ -967,6 +997,21 @@ Object {
967997
}
968998
`;
969999

1000+
exports[`createConfig profile option 1`] = `
1001+
Object {
1002+
"hot": true,
1003+
"hotOnly": false,
1004+
"noInfo": true,
1005+
"port": 8080,
1006+
"profile": "profile",
1007+
"publicPath": "/",
1008+
"stats": Object {
1009+
"cached": false,
1010+
"cachedAssets": false,
1011+
},
1012+
}
1013+
`;
1014+
9701015
exports[`createConfig progress option (devServer config) 1`] = `
9711016
Object {
9721017
"hot": true,
@@ -1155,6 +1200,51 @@ Object {
11551200
}
11561201
`;
11571202

1203+
exports[`createConfig sockHost option 1`] = `
1204+
Object {
1205+
"hot": true,
1206+
"hotOnly": false,
1207+
"noInfo": true,
1208+
"port": 8080,
1209+
"publicPath": "/",
1210+
"sockHost": true,
1211+
"stats": Object {
1212+
"cached": false,
1213+
"cachedAssets": false,
1214+
},
1215+
}
1216+
`;
1217+
1218+
exports[`createConfig sockPath option 1`] = `
1219+
Object {
1220+
"hot": true,
1221+
"hotOnly": false,
1222+
"noInfo": true,
1223+
"port": 8080,
1224+
"publicPath": "/",
1225+
"sockPath": "path",
1226+
"stats": Object {
1227+
"cached": false,
1228+
"cachedAssets": false,
1229+
},
1230+
}
1231+
`;
1232+
1233+
exports[`createConfig sockPort option 1`] = `
1234+
Object {
1235+
"hot": true,
1236+
"hotOnly": false,
1237+
"noInfo": true,
1238+
"port": 8080,
1239+
"publicPath": "/",
1240+
"sockPort": "port",
1241+
"stats": Object {
1242+
"cached": false,
1243+
"cachedAssets": false,
1244+
},
1245+
}
1246+
`;
1247+
11581248
exports[`createConfig socket option (devServer config) 1`] = `
11591249
Object {
11601250
"hot": true,

test/server/utils/__snapshots__/findPort.test.js.snap

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/server/utils/colors.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
const colors = require('../../../lib/utils/colors');
4+
5+
describe('colors', () => {
6+
describe('info', () => {
7+
it('should disable color', () => {
8+
expect(colors.info(false, 'test')).toMatchSnapshot();
9+
});
10+
11+
it('should enable color', () => {
12+
expect(colors.info(true, 'test')).toMatchSnapshot();
13+
});
14+
});
15+
16+
describe('error', () => {
17+
it('should disable color', () => {
18+
expect(colors.error(false, 'test')).toMatchSnapshot();
19+
});
20+
21+
it('should enable color', () => {
22+
expect(colors.error(true, 'test')).toMatchSnapshot();
23+
});
24+
});
25+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const createCertificate = require('../../../lib/utils/createCertificate');
4+
5+
describe('createCertificate', () => {
6+
it('should have keys', () => {
7+
expect(createCertificate([{ name: 'commonName', value: 'wds' }])).toEqual(
8+
expect.objectContaining({
9+
private: expect.any(String),
10+
public: expect.any(String),
11+
cert: expect.any(String),
12+
fingerprint: expect.any(String),
13+
})
14+
);
15+
});
16+
});

test/server/utils/createConfig.test.js

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,19 @@ describe('createConfig', () => {
980980
expect(config).toMatchSnapshot();
981981
});
982982

983-
it('overlay', () => {
983+
it('overlay option', () => {
984+
const config = createConfig(
985+
webpackConfig,
986+
Object.assign({}, argv, {
987+
overlay: true,
988+
}),
989+
{ port: 8080 }
990+
);
991+
992+
expect(config).toMatchSnapshot();
993+
});
994+
995+
it('overlay option (in devServer config)', () => {
984996
const config = createConfig(
985997
Object.assign({}, webpackConfig, {
986998
devServer: { overlay: true },
@@ -991,4 +1003,64 @@ describe('createConfig', () => {
9911003

9921004
expect(config).toMatchSnapshot();
9931005
});
1006+
1007+
it('sockHost option', () => {
1008+
const config = createConfig(
1009+
webpackConfig,
1010+
Object.assign({}, argv, {
1011+
sockHost: true,
1012+
}),
1013+
{ port: 8080 }
1014+
);
1015+
1016+
expect(config).toMatchSnapshot();
1017+
});
1018+
1019+
it('sockPath option', () => {
1020+
const config = createConfig(
1021+
webpackConfig,
1022+
Object.assign({}, argv, {
1023+
sockPath: 'path',
1024+
}),
1025+
{ port: 8080 }
1026+
);
1027+
1028+
expect(config).toMatchSnapshot();
1029+
});
1030+
1031+
it('sockPort option', () => {
1032+
const config = createConfig(
1033+
webpackConfig,
1034+
Object.assign({}, argv, {
1035+
sockPort: 'port',
1036+
}),
1037+
{ port: 8080 }
1038+
);
1039+
1040+
expect(config).toMatchSnapshot();
1041+
});
1042+
1043+
it('liveReload option', () => {
1044+
const config = createConfig(
1045+
webpackConfig,
1046+
Object.assign({}, argv, {
1047+
liveReload: false,
1048+
}),
1049+
{ port: 8080 }
1050+
);
1051+
1052+
expect(config).toMatchSnapshot();
1053+
});
1054+
1055+
it('profile option', () => {
1056+
const config = createConfig(
1057+
webpackConfig,
1058+
Object.assign({}, argv, {
1059+
profile: 'profile',
1060+
}),
1061+
{ port: 8080 }
1062+
);
1063+
1064+
expect(config).toMatchSnapshot();
1065+
});
9941066
});

test/server/utils/createDomain.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const createDomain = require('../../../lib/utils/createDomain');
77
const [port1, port2] = require('../../ports-map').createDomain;
88
const config = require('./../../fixtures/simple-config/webpack.config');
99

10-
describe('check utility functions', () => {
10+
describe('createDomain', () => {
1111
let compiler;
1212
let server;
1313

0 commit comments

Comments
 (0)