Skip to content

Commit 04fa8c8

Browse files
author
Glen Mailer
committedJan 31, 2021
Apply prettier formatting updates
1 parent b81cfd5 commit 04fa8c8

17 files changed

+215
-210
lines changed
 

‎.eslintrc

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
{
2-
"extends": "eslint:recommended",
3-
"env": {
4-
"node": true
5-
},
6-
"plugins": [
7-
"prettier"
8-
],
9-
"rules": {
10-
"no-console": "off",
11-
"prettier/prettier": [
12-
"error"
13-
]
14-
}
2+
"extends": "eslint:recommended",
3+
"env": {
4+
"node": true
5+
},
6+
"plugins": ["prettier"],
7+
"rules": {
8+
"no-console": "off",
9+
"prettier/prettier": ["error"]
10+
}
1511
}

‎.mocharc.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"reporter": "spec",
3-
"exit": true
4-
}
2+
"reporter": "spec",
3+
"exit": true
4+
}

‎client-overlay.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var entities = new Entities();
4040

4141
function showProblems(type, lines) {
4242
clientOverlay.innerHTML = '';
43-
lines.forEach(function(msg) {
43+
lines.forEach(function (msg) {
4444
msg = ansiHTML(entities.encode(msg));
4545
var div = document.createElement('div');
4646
div.style.marginBottom = '26px';
@@ -73,7 +73,7 @@ function problemType(type) {
7373
);
7474
}
7575

76-
module.exports = function(options) {
76+
module.exports = function (options) {
7777
for (var color in options.ansiColors) {
7878
if (color in colors) {
7979
colors[color] = options.ansiColors[color];

‎client.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function EventSourceWrapper() {
7878
var listeners = [];
7979

8080
init();
81-
var timer = setInterval(function() {
81+
var timer = setInterval(function () {
8282
if (new Date() - lastActivity > options.timeout) {
8383
handleDisconnect();
8484
}
@@ -110,7 +110,7 @@ function EventSourceWrapper() {
110110
}
111111

112112
return {
113-
addMessageListener: function(fn) {
113+
addMessageListener: function (fn) {
114114
listeners.push(fn);
115115
},
116116
};
@@ -176,7 +176,7 @@ function createReporter() {
176176
var previousProblems = null;
177177
function log(type, obj) {
178178
var newProblems = obj[type]
179-
.map(function(msg) {
179+
.map(function (msg) {
180180
return strip(msg);
181181
})
182182
.join('\n');
@@ -205,10 +205,10 @@ function createReporter() {
205205
}
206206

207207
return {
208-
cleanProblemsCache: function() {
208+
cleanProblemsCache: function () {
209209
previousProblems = null;
210210
},
211-
problems: function(type, obj) {
211+
problems: function (type, obj) {
212212
if (options.warn) {
213213
log(type, obj);
214214
}
@@ -221,10 +221,10 @@ function createReporter() {
221221
}
222222
return true;
223223
},
224-
success: function() {
224+
success: function () {
225225
if (overlay) overlay.clear();
226226
},
227-
useCustomOverlay: function(customOverlay) {
227+
useCustomOverlay: function (customOverlay) {
228228
overlay = customOverlay;
229229
},
230230
};

‎example/client.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var time = document.getElementById('time');
55
var timer = setInterval(updateClock, 1000);
66

77
function updateClock() {
8-
time.innerHTML = (new Date()).toString();
8+
time.innerHTML = new Date().toString();
99
}
1010

1111
// Edit these styles to see them take effect immediately
@@ -28,7 +28,7 @@ require('assert');
2828

2929
if (module.hot) {
3030
module.hot.accept();
31-
module.hot.dispose(function() {
31+
module.hot.dispose(function () {
3232
clearInterval(timer);
3333
});
3434
}

‎example/index-multientry.html

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
<!DOCTYPE html>
22
<html>
3-
<head>
4-
<meta charset="utf-8">
5-
<meta name=viewport content="width=device-width, initial-scale=1">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
66
<title>Webpack Hot Middleware Multiple Entry Point Example</title>
7-
</head>
8-
<body>
9-
<div id="app">
10-
<p id="time">Date</p>
11-
<input
12-
type="text" size="40" style="text-align: center"
7+
</head>
8+
<body>
9+
<div id="app">
10+
<p id="time">Date</p>
11+
<input
12+
type="text"
13+
size="40"
14+
style="text-align: center"
1315
placeholder="Type something in here to prove state isn't lost"
14-
/>
15-
</div>
16-
<script src="/client.js"></script>
17-
<script src="/extra.js"></script>
18-
</body>
16+
/>
17+
</div>
18+
<script src="/client.js"></script>
19+
<script src="/extra.js"></script>
20+
</body>
1921
</html>

‎example/index.html

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
<!DOCTYPE html>
22
<html>
3-
<head>
4-
<meta charset="utf-8">
5-
<meta name=viewport content="width=device-width, initial-scale=1">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
66
<title>Webpack Hot Middleware Example</title>
7-
</head>
8-
<body>
9-
<div id="app">
10-
<p id="time">Date</p>
11-
<input
12-
type="text" size="40" style="text-align: center"
7+
</head>
8+
<body>
9+
<div id="app">
10+
<p id="time">Date</p>
11+
<input
12+
type="text"
13+
size="40"
14+
style="text-align: center"
1315
placeholder="Type something in here to prove state isn't lost"
14-
/>
15-
</div>
16-
<script src="/bundle.js"></script>
17-
</body>
16+
/>
17+
</div>
18+
<script src="/bundle.js"></script>
19+
</body>
1820
</html>

‎example/server.js

+22-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var http = require('http');
22

33
var express = require('express');
44

5-
require('console-stamp')(console, "HH:MM:ss.l");
5+
require('console-stamp')(console, 'HH:MM:ss.l');
66

77
var app = express();
88

@@ -11,36 +11,44 @@ app.use(require('morgan')('short'));
1111
// ************************************
1212
// This is the real meat of the example
1313
// ************************************
14-
(function() {
15-
14+
(function () {
1615
// Step 1: Create & configure a webpack compiler
1716
var webpack = require('webpack');
18-
var webpackConfig = require(process.env.WEBPACK_CONFIG ? process.env.WEBPACK_CONFIG : './webpack.config');
17+
var webpackConfig = require(process.env.WEBPACK_CONFIG
18+
? process.env.WEBPACK_CONFIG
19+
: './webpack.config');
1920
var compiler = webpack(webpackConfig);
2021

2122
// Step 2: Attach the dev middleware to the compiler & the server
22-
app.use(require("webpack-dev-middleware")(compiler, {
23-
logLevel: 'warn', publicPath: webpackConfig.output.publicPath
24-
}));
23+
app.use(
24+
require('webpack-dev-middleware')(compiler, {
25+
logLevel: 'warn',
26+
publicPath: webpackConfig.output.publicPath,
27+
})
28+
);
2529

2630
// Step 3: Attach the hot middleware to the compiler & the server
27-
app.use(require("webpack-hot-middleware")(compiler, {
28-
log: console.log, path: '/__webpack_hmr', heartbeat: 10 * 1000
29-
}));
31+
app.use(
32+
require('webpack-hot-middleware')(compiler, {
33+
log: console.log,
34+
path: '/__webpack_hmr',
35+
heartbeat: 10 * 1000,
36+
})
37+
);
3038
})();
3139

3240
// Do anything you like with the rest of your express application.
3341

34-
app.get("/", function(req, res) {
42+
app.get('/', function (req, res) {
3543
res.sendFile(__dirname + '/index.html');
3644
});
37-
app.get("/multientry", function(req, res) {
45+
app.get('/multientry', function (req, res) {
3846
res.sendFile(__dirname + '/index-multientry.html');
3947
});
4048

4149
if (require.main === module) {
4250
var server = http.createServer(app);
43-
server.listen(process.env.PORT || 1616, function() {
44-
console.log("Listening on %j", server.address());
51+
server.listen(process.env.PORT || 1616, function () {
52+
console.log('Listening on %j', server.address());
4553
});
4654
}

‎example/webpack.config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ module.exports = {
99
// useful if you run your app from another point like django
1010
'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000',
1111
// And then the actual application
12-
'./client.js'
12+
'./client.js',
1313
],
1414
output: {
1515
path: __dirname,
1616
publicPath: '/',
17-
filename: 'bundle.js'
17+
filename: 'bundle.js',
1818
},
1919
devtool: '#source-map',
2020
plugins: [
2121
new webpack.HotModuleReplacementPlugin(),
22-
new webpack.NoEmitOnErrorsPlugin()
22+
new webpack.NoEmitOnErrorsPlugin(),
2323
],
2424
};

‎example/webpack.config.multientry.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var webpack = require('webpack');
2-
var hotMiddlewareScript = 'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000&reload=true';
2+
var hotMiddlewareScript =
3+
'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000&reload=true';
34

45
module.exports = {
56
mode: 'development',
@@ -8,17 +9,17 @@ module.exports = {
89
entry: {
910
// Add the client which connects to our middleware
1011
client: ['./client.js', hotMiddlewareScript],
11-
extra: ['./extra.js', hotMiddlewareScript]
12+
extra: ['./extra.js', hotMiddlewareScript],
1213
},
1314
output: {
1415
path: __dirname,
1516
publicPath: '/',
16-
filename: '[name].js'
17+
filename: '[name].js',
1718
},
1819
devtool: '#source-map',
1920
plugins: [
2021
new webpack.optimize.OccurrenceOrderPlugin(),
2122
new webpack.HotModuleReplacementPlugin(),
22-
new webpack.NoEmitOnErrorsPlugin()
23+
new webpack.NoEmitOnErrorsPlugin(),
2324
],
2425
};

‎helpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var parse = require('url').parse;
22

3-
exports.pathMatch = function(url, path) {
3+
exports.pathMatch = function (url, path) {
44
try {
55
return parse(url).pathname === path;
66
} catch (e) {

‎middleware.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function webpackHotMiddleware(compiler, opts) {
3333
latestStats = statsResult;
3434
publishStats('built', latestStats, eventStream, opts.log);
3535
}
36-
var middleware = function(req, res, next) {
36+
var middleware = function (req, res, next) {
3737
if (closed) return next();
3838
if (!pathMatch(req.url, opts.path)) return next();
3939
eventStream.handler(req, res);
@@ -43,11 +43,11 @@ function webpackHotMiddleware(compiler, opts) {
4343
publishStats('sync', latestStats, eventStream);
4444
}
4545
};
46-
middleware.publish = function(payload) {
46+
middleware.publish = function (payload) {
4747
if (closed) return;
4848
eventStream.publish(payload);
4949
};
50-
middleware.close = function() {
50+
middleware.close = function () {
5151
if (closed) return;
5252
// Can't remove compiler plugins, so we just set a flag and noop if closed
5353
// https://github.com/webpack/tapable/issues/32#issuecomment-350644466
@@ -62,24 +62,24 @@ function createEventStream(heartbeat) {
6262
var clientId = 0;
6363
var clients = {};
6464
function everyClient(fn) {
65-
Object.keys(clients).forEach(function(id) {
65+
Object.keys(clients).forEach(function (id) {
6666
fn(clients[id]);
6767
});
6868
}
6969
var interval = setInterval(function heartbeatTick() {
70-
everyClient(function(client) {
70+
everyClient(function (client) {
7171
client.write('data: \uD83D\uDC93\n\n');
7272
});
7373
}, heartbeat).unref();
7474
return {
75-
close: function() {
75+
close: function () {
7676
clearInterval(interval);
77-
everyClient(function(client) {
77+
everyClient(function (client) {
7878
if (!client.finished) client.end();
7979
});
8080
clients = {};
8181
},
82-
handler: function(req, res) {
82+
handler: function (req, res) {
8383
var headers = {
8484
'Access-Control-Allow-Origin': '*',
8585
'Content-Type': 'text/event-stream;charset=utf-8',
@@ -101,13 +101,13 @@ function createEventStream(heartbeat) {
101101
res.write('\n');
102102
var id = clientId++;
103103
clients[id] = res;
104-
req.on('close', function() {
104+
req.on('close', function () {
105105
if (!res.finished) res.end();
106106
delete clients[id];
107107
});
108108
},
109-
publish: function(payload) {
110-
everyClient(function(client) {
109+
publish: function (payload) {
110+
everyClient(function (client) {
111111
client.write('data: ' + JSON.stringify(payload) + '\n\n');
112112
});
113113
},
@@ -125,7 +125,7 @@ function publishStats(action, statsResult, eventStream, log) {
125125
});
126126
// For multi-compiler, stats will be an object with a 'children' array of stats
127127
var bundles = extractBundles(stats);
128-
bundles.forEach(function(stats) {
128+
bundles.forEach(function (stats) {
129129
var name = stats.name || '';
130130

131131
// Fallback to compilation name in case of 1 bundle (if it exists)
@@ -168,7 +168,7 @@ function extractBundles(stats) {
168168

169169
function buildModuleMap(modules) {
170170
var map = {};
171-
modules.forEach(function(module) {
171+
modules.forEach(function (module) {
172172
map[module.id] = module.name;
173173
});
174174
return map;

‎process-update.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ var applyOptions = {
1818
ignoreUnaccepted: true,
1919
ignoreDeclined: true,
2020
ignoreErrored: true,
21-
onUnaccepted: function(data) {
21+
onUnaccepted: function (data) {
2222
console.warn(
2323
'Ignored an update to unaccepted module ' + data.chain.join(' -> ')
2424
);
2525
},
26-
onDeclined: function(data) {
26+
onDeclined: function (data) {
2727
console.warn(
2828
'Ignored an update to declined module ' + data.chain.join(' -> ')
2929
);
3030
},
31-
onErrored: function(data) {
31+
onErrored: function (data) {
3232
console.error(data.error);
3333
console.warn(
3434
'Ignored an error while updating module ' +
@@ -45,15 +45,15 @@ function upToDate(hash) {
4545
return lastHash == __webpack_hash__;
4646
}
4747

48-
module.exports = function(hash, moduleMap, options) {
48+
module.exports = function (hash, moduleMap, options) {
4949
var reload = options.reload;
5050
if (!upToDate(hash) && module.hot.status() == 'idle') {
5151
if (options.log) console.log('[HMR] Checking for updates on the server...');
5252
check();
5353
}
5454

5555
function check() {
56-
var cb = function(err, updatedModules) {
56+
var cb = function (err, updatedModules) {
5757
if (err) return handleError(err);
5858

5959
if (!updatedModules) {
@@ -65,7 +65,7 @@ module.exports = function(hash, moduleMap, options) {
6565
return null;
6666
}
6767

68-
var applyCallback = function(applyErr, renewedModules) {
68+
var applyCallback = function (applyErr, renewedModules) {
6969
if (applyErr) return handleError(applyErr);
7070

7171
if (!upToDate()) check();
@@ -77,7 +77,7 @@ module.exports = function(hash, moduleMap, options) {
7777
// webpack 2 promise
7878
if (applyResult && applyResult.then) {
7979
// HotModuleReplacement.runtime.js refers to the result as `outdatedModules`
80-
applyResult.then(function(outdatedModules) {
80+
applyResult.then(function (outdatedModules) {
8181
applyCallback(null, outdatedModules);
8282
});
8383
applyResult.catch(applyCallback);
@@ -87,15 +87,15 @@ module.exports = function(hash, moduleMap, options) {
8787
var result = module.hot.check(false, cb);
8888
// webpack 2 promise
8989
if (result && result.then) {
90-
result.then(function(updatedModules) {
90+
result.then(function (updatedModules) {
9191
cb(null, updatedModules);
9292
});
9393
result.catch(cb);
9494
}
9595
}
9696

9797
function logUpdates(updatedModules, renewedModules) {
98-
var unacceptedModules = updatedModules.filter(function(moduleId) {
98+
var unacceptedModules = updatedModules.filter(function (moduleId) {
9999
return renewedModules && renewedModules.indexOf(moduleId) < 0;
100100
});
101101

@@ -110,7 +110,7 @@ module.exports = function(hash, moduleMap, options) {
110110
hmrDocsUrl +
111111
' for more details.'
112112
);
113-
unacceptedModules.forEach(function(moduleId) {
113+
unacceptedModules.forEach(function (moduleId) {
114114
console.warn('[HMR] - ' + (moduleMap[moduleId] || moduleId));
115115
});
116116
}
@@ -123,7 +123,7 @@ module.exports = function(hash, moduleMap, options) {
123123
console.log('[HMR] Nothing hot updated.');
124124
} else {
125125
console.log('[HMR] Updated modules:');
126-
renewedModules.forEach(function(moduleId) {
126+
renewedModules.forEach(function (moduleId) {
127127
console.log('[HMR] - ' + (moduleMap[moduleId] || moduleId));
128128
});
129129
}

‎test/client-test.js

+33-33
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
var sinon = require('sinon');
44

5-
describe('client', function() {
5+
describe('client', function () {
66
var s, client, clientOverlay, processUpdate;
77

8-
beforeEach(function() {
8+
beforeEach(function () {
99
s = sinon.createSandbox({ useFakeTimers: true });
1010
});
11-
afterEach(function() {
11+
afterEach(function () {
1212
s.restore();
1313
});
1414

15-
context('with default options', function() {
15+
context('with default options', function () {
1616
beforeEach(function setup() {
1717
global.__resourceQuery = ''; // eslint-disable-line no-underscore-dangle
1818
global.document = {};
@@ -23,12 +23,12 @@ describe('client', function() {
2323
};
2424
});
2525
beforeEach(loadClient);
26-
it('should connect to __webpack_hmr', function() {
26+
it('should connect to __webpack_hmr', function () {
2727
sinon.assert.calledOnce(window.EventSource);
2828
sinon.assert.calledWithNew(window.EventSource);
2929
sinon.assert.calledWith(window.EventSource, '/__webpack_hmr');
3030
});
31-
it('should trigger webpack on successful builds', function() {
31+
it('should trigger webpack on successful builds', function () {
3232
var eventSource = window.EventSource.lastCall.returnValue;
3333
eventSource.onmessage(
3434
makeMessage({
@@ -42,7 +42,7 @@ describe('client', function() {
4242
);
4343
sinon.assert.calledOnce(processUpdate);
4444
});
45-
it('should trigger webpack on successful syncs', function() {
45+
it('should trigger webpack on successful syncs', function () {
4646
var eventSource = window.EventSource.lastCall.returnValue;
4747
eventSource.onmessage(
4848
makeMessage({
@@ -56,7 +56,7 @@ describe('client', function() {
5656
);
5757
sinon.assert.calledOnce(processUpdate);
5858
});
59-
it('should call subscribeAll handler on default messages', function() {
59+
it('should call subscribeAll handler on default messages', function () {
6060
var spy = sinon.spy();
6161
client.subscribeAll(spy);
6262
var message = {
@@ -74,7 +74,7 @@ describe('client', function() {
7474
sinon.assert.calledOnce(spy);
7575
sinon.assert.calledWith(spy, message);
7676
});
77-
it('should call subscribeAll handler on custom messages', function() {
77+
it('should call subscribeAll handler on custom messages', function () {
7878
var spy = sinon.spy();
7979
client.subscribeAll(spy);
8080

@@ -88,7 +88,7 @@ describe('client', function() {
8888
sinon.assert.calledOnce(spy);
8989
sinon.assert.calledWith(spy, { action: 'thingy' });
9090
});
91-
it('should call only custom handler on custom messages', function() {
91+
it('should call only custom handler on custom messages', function () {
9292
var spy = sinon.spy();
9393
client.subscribe(spy);
9494

@@ -108,7 +108,7 @@ describe('client', function() {
108108
sinon.assert.calledWith(spy, { custom: 'thingy' });
109109
sinon.assert.notCalled(processUpdate);
110110
});
111-
it('should not trigger webpack on errored builds', function() {
111+
it('should not trigger webpack on errored builds', function () {
112112
var eventSource = window.EventSource.lastCall.returnValue;
113113
eventSource.onmessage(
114114
makeMessage({
@@ -122,7 +122,7 @@ describe('client', function() {
122122
);
123123
sinon.assert.notCalled(processUpdate);
124124
});
125-
it('should show overlay on errored builds', function() {
125+
it('should show overlay on errored builds', function () {
126126
var eventSource = window.EventSource.lastCall.returnValue;
127127
eventSource.onmessage(
128128
makeMessage({
@@ -140,7 +140,7 @@ describe('client', function() {
140140
'Actually, 2 things broke',
141141
]);
142142
});
143-
it('should hide overlay after errored build fixed', function() {
143+
it('should hide overlay after errored build fixed', function () {
144144
var eventSource = window.EventSource.lastCall.returnValue;
145145
eventSource.onmessage(
146146
makeMessage({
@@ -165,7 +165,7 @@ describe('client', function() {
165165
sinon.assert.calledOnce(clientOverlay.showProblems);
166166
sinon.assert.calledOnce(clientOverlay.clear);
167167
});
168-
it('should hide overlay after errored build becomes warning', function() {
168+
it('should hide overlay after errored build becomes warning', function () {
169169
var eventSource = window.EventSource.lastCall.returnValue;
170170
eventSource.onmessage(
171171
makeMessage({
@@ -190,7 +190,7 @@ describe('client', function() {
190190
sinon.assert.calledOnce(clientOverlay.showProblems);
191191
sinon.assert.calledOnce(clientOverlay.clear);
192192
});
193-
it('should trigger webpack on warning builds', function() {
193+
it('should trigger webpack on warning builds', function () {
194194
var eventSource = window.EventSource.lastCall.returnValue;
195195
eventSource.onmessage(
196196
makeMessage({
@@ -204,7 +204,7 @@ describe('client', function() {
204204
);
205205
sinon.assert.calledOnce(processUpdate);
206206
});
207-
it('should not overlay on warning builds', function() {
207+
it('should not overlay on warning builds', function () {
208208
var eventSource = window.EventSource.lastCall.returnValue;
209209
eventSource.onmessage(
210210
makeMessage({
@@ -218,7 +218,7 @@ describe('client', function() {
218218
);
219219
sinon.assert.notCalled(clientOverlay.showProblems);
220220
});
221-
it('should show overlay after warning build becomes error', function() {
221+
it('should show overlay after warning build becomes error', function () {
222222
var eventSource = window.EventSource.lastCall.returnValue;
223223
eventSource.onmessage(
224224
makeMessage({
@@ -245,7 +245,7 @@ describe('client', function() {
245245
it("should test more of the client's functionality");
246246
});
247247

248-
context('with overlayWarnings: true', function() {
248+
context('with overlayWarnings: true', function () {
249249
beforeEach(function setup() {
250250
global.__resourceQuery = '?overlayWarnings=true'; // eslint-disable-line no-underscore-dangle
251251
global.document = {};
@@ -256,7 +256,7 @@ describe('client', function() {
256256
};
257257
});
258258
beforeEach(loadClient);
259-
it('should show overlay on errored builds', function() {
259+
it('should show overlay on errored builds', function () {
260260
var eventSource = window.EventSource.lastCall.returnValue;
261261
eventSource.onmessage(
262262
makeMessage({
@@ -274,7 +274,7 @@ describe('client', function() {
274274
'Actually, 2 things broke',
275275
]);
276276
});
277-
it('should hide overlay after errored build fixed', function() {
277+
it('should hide overlay after errored build fixed', function () {
278278
var eventSource = window.EventSource.lastCall.returnValue;
279279
eventSource.onmessage(
280280
makeMessage({
@@ -299,7 +299,7 @@ describe('client', function() {
299299
sinon.assert.calledOnce(clientOverlay.showProblems);
300300
sinon.assert.calledOnce(clientOverlay.clear);
301301
});
302-
it('should show overlay on warning builds', function() {
302+
it('should show overlay on warning builds', function () {
303303
var eventSource = window.EventSource.lastCall.returnValue;
304304
eventSource.onmessage(
305305
makeMessage({
@@ -316,7 +316,7 @@ describe('client', function() {
316316
"This isn't great, but it's not terrible",
317317
]);
318318
});
319-
it('should hide overlay after warning build fixed', function() {
319+
it('should hide overlay after warning build fixed', function () {
320320
var eventSource = window.EventSource.lastCall.returnValue;
321321
eventSource.onmessage(
322322
makeMessage({
@@ -341,7 +341,7 @@ describe('client', function() {
341341
sinon.assert.calledOnce(clientOverlay.showProblems);
342342
sinon.assert.calledOnce(clientOverlay.clear);
343343
});
344-
it('should update overlay after errored build becomes warning', function() {
344+
it('should update overlay after errored build becomes warning', function () {
345345
var eventSource = window.EventSource.lastCall.returnValue;
346346
eventSource.onmessage(
347347
makeMessage({
@@ -369,7 +369,7 @@ describe('client', function() {
369369
});
370370
});
371371

372-
context('with name options', function() {
372+
context('with name options', function () {
373373
beforeEach(function setup() {
374374
global.__resourceQuery = '?name=test'; // eslint-disable-line no-underscore-dangle
375375
global.window = {
@@ -379,7 +379,7 @@ describe('client', function() {
379379
};
380380
});
381381
beforeEach(loadClient);
382-
it('should not trigger webpack if event obj name is different', function() {
382+
it('should not trigger webpack if event obj name is different', function () {
383383
var eventSource = window.EventSource.lastCall.returnValue;
384384
eventSource.onmessage(
385385
makeMessage({
@@ -394,7 +394,7 @@ describe('client', function() {
394394
);
395395
sinon.assert.notCalled(processUpdate);
396396
});
397-
it('should not trigger webpack on successful syncs if obj name is different', function() {
397+
it('should not trigger webpack on successful syncs if obj name is different', function () {
398398
var eventSource = window.EventSource.lastCall.returnValue;
399399
eventSource.onmessage(
400400
makeMessage({
@@ -411,25 +411,25 @@ describe('client', function() {
411411
});
412412
});
413413

414-
context('with no browser environment', function() {
414+
context('with no browser environment', function () {
415415
beforeEach(function setup() {
416416
global.__resourceQuery = ''; // eslint-disable-line no-underscore-dangle
417417
delete global.window;
418418
});
419419
beforeEach(loadClient);
420-
it('should not connect', function() {
420+
it('should not connect', function () {
421421
// doesn't error
422422
});
423423
});
424424

425-
context('with no EventSource', function() {
425+
context('with no EventSource', function () {
426426
beforeEach(function setup() {
427427
global.__resourceQuery = ''; // eslint-disable-line no-underscore-dangle
428428
global.window = {};
429429
s.stub(console, 'warn');
430430
});
431431
beforeEach(loadClient);
432-
it('should emit warning and not connect', function() {
432+
it('should emit warning and not connect', function () {
433433
sinon.assert.calledOnce(console.warn);
434434
sinon.assert.calledWithMatch(console.warn, /EventSource/);
435435
});
@@ -445,10 +445,10 @@ describe('client', function() {
445445
client = require(path);
446446
}
447447

448-
beforeEach(function() {
448+
beforeEach(function () {
449449
clientOverlay = { showProblems: sinon.stub(), clear: sinon.stub() };
450450
var clientOverlayModule = {
451-
exports: function() {
451+
exports: function () {
452452
return clientOverlay;
453453
},
454454
};
@@ -459,7 +459,7 @@ describe('client', function() {
459459
exports: processUpdate,
460460
};
461461
});
462-
afterEach(function() {
462+
afterEach(function () {
463463
delete require.cache[require.resolve('../client-overlay')];
464464
delete require.cache[require.resolve('../process-update')];
465465
});

‎test/helpers-test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ var assert = require('assert');
33

44
var helpers = require('../helpers');
55

6-
describe('helpers', function() {
7-
describe('pathMatch', function() {
6+
describe('helpers', function () {
7+
describe('pathMatch', function () {
88
var pathMatch = helpers.pathMatch;
9-
it('should match exact path', function() {
9+
it('should match exact path', function () {
1010
assert.ok(pathMatch('/path', '/path'));
1111
});
12-
it('should match path with querystring', function() {
12+
it('should match path with querystring', function () {
1313
assert.ok(pathMatch('/path?abc=123', '/path'));
1414
});
15-
it('should not match different path', function() {
15+
it('should not match different path', function () {
1616
assert.equal(pathMatch('/another', '/path'), false);
1717
});
18-
it('should not match path with other stuff on the end', function() {
18+
it('should not match path with other stuff on the end', function () {
1919
assert.equal(pathMatch('/path-and', '/path'), false);
2020
});
2121
});

‎test/middleware-test.js

+42-44
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ var supertest = require('supertest');
88
var express = require('express');
99
var webpackHotMiddleware = require('../middleware');
1010

11-
describe('middleware', function() {
11+
describe('middleware', function () {
1212
var s, compiler, app, middleware;
1313

14-
context('with default options', function() {
15-
beforeEach(setupServer({ log: function() {} }));
14+
context('with default options', function () {
15+
beforeEach(setupServer({ log: function () {} }));
1616

17-
it('should create eventStream on /__webpack_hmr', function(done) {
17+
it('should create eventStream on /__webpack_hmr', function (done) {
1818
request('/__webpack_hmr')
1919
.expect('Content-Type', /^text\/event-stream\b/)
2020
.end(done);
2121
});
22-
it('should heartbeat every 10 seconds', function(done) {
23-
request('/__webpack_hmr').end(function(err, res) {
22+
it('should heartbeat every 10 seconds', function (done) {
23+
request('/__webpack_hmr').end(function (err, res) {
2424
if (err) return done(err);
2525

2626
// Tick 3 times, then verify
2727
var i = 0;
2828
tick(10, 'seconds');
29-
res.on('data', function() {
29+
res.on('data', function () {
3030
if (++i < 3) {
3131
tick(10, 'seconds');
3232
} else {
@@ -36,15 +36,15 @@ describe('middleware', function() {
3636

3737
function verify() {
3838
assert.equal(res.events.length, 3);
39-
res.events.every(function(chunk) {
39+
res.events.every(function (chunk) {
4040
assert(/^data: /.test(chunk));
4141
});
4242
done();
4343
}
4444
});
4545
});
46-
it('should notify clients when bundle rebuild begins', function(done) {
47-
request('/__webpack_hmr').end(function(err, res) {
46+
it('should notify clients when bundle rebuild begins', function (done) {
47+
request('/__webpack_hmr').end(function (err, res) {
4848
if (err) return done(err);
4949

5050
res.on('data', verify);
@@ -59,8 +59,8 @@ describe('middleware', function() {
5959
}
6060
});
6161
});
62-
it('should notify clients when bundle is complete', function(done) {
63-
request('/__webpack_hmr').end(function(err, res) {
62+
it('should notify clients when bundle is complete', function (done) {
63+
request('/__webpack_hmr').end(function (err, res) {
6464
if (err) return done(err);
6565

6666
res.on('data', verify);
@@ -84,8 +84,8 @@ describe('middleware', function() {
8484
}
8585
});
8686
});
87-
it('should notify clients when bundle is complete (multicompiler)', function(done) {
88-
request('/__webpack_hmr').end(function(err, res) {
87+
it('should notify clients when bundle is complete (multicompiler)', function (done) {
88+
request('/__webpack_hmr').end(function (err, res) {
8989
if (err) return done(err);
9090

9191
res.once('data', verify);
@@ -120,7 +120,7 @@ describe('middleware', function() {
120120
}
121121
});
122122
});
123-
it('should notify new clients about current compilation state', function(done) {
123+
it('should notify new clients about current compilation state', function (done) {
124124
compiler.emit(
125125
'done',
126126
stats({
@@ -132,15 +132,15 @@ describe('middleware', function() {
132132
})
133133
);
134134

135-
request('/__webpack_hmr').end(function(err, res) {
135+
request('/__webpack_hmr').end(function (err, res) {
136136
if (err) return done(err);
137137
assert.equal(res.events.length, 1);
138138
var event = JSON.parse(res.events[0].substring(5));
139139
assert.equal(event.action, 'sync');
140140
done();
141141
});
142142
});
143-
it('should fallback to the compilation name if no stats name is provided and there is one stats object', function(done) {
143+
it('should fallback to the compilation name if no stats name is provided and there is one stats object', function (done) {
144144
compiler.emit(
145145
'done',
146146
stats({
@@ -152,7 +152,7 @@ describe('middleware', function() {
152152
})
153153
);
154154

155-
request('/__webpack_hmr').end(function(err, res) {
155+
request('/__webpack_hmr').end(function (err, res) {
156156
if (err) return done(err);
157157

158158
var event = JSON.parse(res.events[0].substring(5));
@@ -161,13 +161,13 @@ describe('middleware', function() {
161161
});
162162
});
163163
it('should have tests on the payload of bundle complete');
164-
it('should notify all clients', function(done) {
165-
request('/__webpack_hmr').end(function(err, res) {
164+
it('should notify all clients', function (done) {
165+
request('/__webpack_hmr').end(function (err, res) {
166166
if (err) return done(err);
167167
res.on('data', verify);
168168
when();
169169
});
170-
request('/__webpack_hmr').end(function(err, res) {
170+
request('/__webpack_hmr').end(function (err, res) {
171171
if (err) return done(err);
172172
res.on('data', verify);
173173
when();
@@ -189,8 +189,8 @@ describe('middleware', function() {
189189
done();
190190
}
191191
});
192-
it('should allow custom events to be published', function(done) {
193-
request('/__webpack_hmr').end(function(err, res) {
192+
it('should allow custom events to be published', function (done) {
193+
request('/__webpack_hmr').end(function (err, res) {
194194
if (err) return done(err);
195195
res.on('data', verify);
196196

@@ -206,25 +206,25 @@ describe('middleware', function() {
206206
});
207207
// Express HTTP/2 support is in progress: https://github.com/expressjs/express/pull/3390
208208
it('should not contain `connection: keep-alive` header for HTTP/2 request');
209-
it('should contain `connection: keep-alive` header for HTTP/1 request', function(done) {
210-
request('/__webpack_hmr').end(function(err, res) {
209+
it('should contain `connection: keep-alive` header for HTTP/1 request', function (done) {
210+
request('/__webpack_hmr').end(function (err, res) {
211211
if (err) return done(err);
212212
assert.equal(res.headers['connection'], 'keep-alive');
213213
done();
214214
});
215215
});
216216

217-
it('should end event stream clients and disable compiler hooks on close', function(done) {
218-
request('/__webpack_hmr').end(function(err, res) {
217+
it('should end event stream clients and disable compiler hooks on close', function (done) {
218+
request('/__webpack_hmr').end(function (err, res) {
219219
if (err) return done(err);
220220

221221
var called = 0;
222-
res.on('data', function() {
222+
res.on('data', function () {
223223
called++;
224224
});
225225

226-
res.on('end', function() {
227-
middleware({}, {}, function(err) {
226+
res.on('end', function () {
227+
middleware({}, {}, function (err) {
228228
assert(!err);
229229
assert.equal(called, 3);
230230
done();
@@ -242,50 +242,48 @@ describe('middleware', function() {
242242
});
243243
});
244244

245-
beforeEach(function() {
245+
beforeEach(function () {
246246
s = sinon.createSandbox();
247247
s.useFakeTimers();
248248
compiler = new events.EventEmitter();
249249
compiler.plugin = compiler.on;
250250
});
251-
afterEach(function() {
251+
afterEach(function () {
252252
s.restore();
253253
});
254254
function tick(time, unit) {
255255
if (unit == 'seconds') time *= 1000;
256256
s.clock.tick(time + 10); // +10ms for some leeway
257257
}
258258
function setupServer(opts) {
259-
return function() {
259+
return function () {
260260
app = express();
261261
middleware = webpackHotMiddleware(compiler, opts);
262262
app.use(middleware);
263263
};
264264
}
265265
function request(path) {
266266
// Wrap some stuff up so supertest works with streaming responses
267-
var req = supertest(app)
268-
.get(path)
269-
.buffer(false);
267+
var req = supertest(app).get(path).buffer(false);
270268
var end = req.end;
271-
req.end = function(callback) {
272-
req.on('error', callback).on('response', function(res) {
269+
req.end = function (callback) {
270+
req.on('error', callback).on('response', function (res) {
273271
Object.defineProperty(res, 'events', {
274-
get: function() {
272+
get: function () {
275273
return res.text.trim().split('\n\n');
276274
},
277275
});
278-
res.on('data', function(chunk) {
276+
res.on('data', function (chunk) {
279277
res.text = (res.text || '') + chunk;
280278
});
281-
process.nextTick(function() {
282-
req.assert(null, res, function(err) {
279+
process.nextTick(function () {
280+
req.assert(null, res, function (err) {
283281
callback(err, res);
284282
});
285283
});
286284
});
287285

288-
end.call(req, function() {});
286+
end.call(req, function () {});
289287
};
290288
return req;
291289
}
@@ -294,7 +292,7 @@ describe('middleware', function() {
294292
compilation: {
295293
name: 'compilation',
296294
},
297-
toJson: function() {
295+
toJson: function () {
298296
return data;
299297
},
300298
};

‎test/realistic-test.js

+25-27
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ var webpackHotMiddleware = require('../middleware');
1212

1313
var app, compiler;
1414

15-
describe('realistic single compiler', function() {
15+
describe('realistic single compiler', function () {
1616
var clientCode = path.resolve(__dirname, './fixtures/single/client.js');
17-
before(function() {
17+
before(function () {
1818
require('fs').writeFileSync(clientCode, 'var a = ' + Math.random() + ';\n');
1919

2020
compiler = webpack({
@@ -35,22 +35,22 @@ describe('realistic single compiler', function() {
3535
);
3636
app.use(
3737
webpackHotMiddleware(compiler, {
38-
log: function() {},
38+
log: function () {},
3939
})
4040
);
4141
});
4242

43-
it('should create eventStream on /__webpack_hmr', function(done) {
43+
it('should create eventStream on /__webpack_hmr', function (done) {
4444
request('/__webpack_hmr')
4545
.expect('Content-Type', /^text\/event-stream\b/)
4646
.end(done);
4747
});
4848

49-
describe('first build', function() {
50-
it('should publish sync event', function(done) {
49+
describe('first build', function () {
50+
it('should publish sync event', function (done) {
5151
request('/__webpack_hmr')
5252
.expect('Content-Type', /^text\/event-stream\b/)
53-
.end(function(err, res) {
53+
.end(function (err, res) {
5454
if (err) return done(err);
5555

5656
var event = JSON.parse(res.events[0].substring(5));
@@ -67,12 +67,12 @@ describe('realistic single compiler', function() {
6767
});
6868
});
6969
});
70-
describe('after file change', function() {
70+
describe('after file change', function () {
7171
var res;
72-
before(function(done) {
72+
before(function (done) {
7373
request('/__webpack_hmr')
7474
.expect('Content-Type', /^text\/event-stream\b/)
75-
.end(function(err, _res) {
75+
.end(function (err, _res) {
7676
if (err) return done(err);
7777

7878
res = _res;
@@ -84,12 +84,12 @@ describe('realistic single compiler', function() {
8484
);
8585
});
8686
});
87-
it('should publish building event', function(done) {
87+
it('should publish building event', function (done) {
8888
waitUntil(
89-
function() {
89+
function () {
9090
return res.events.length >= 2;
9191
},
92-
function() {
92+
function () {
9393
var event = JSON.parse(res.events[1].substring(5));
9494

9595
assert.equal(event.action, 'building');
@@ -98,12 +98,12 @@ describe('realistic single compiler', function() {
9898
}
9999
);
100100
});
101-
it('should publish built event', function(done) {
101+
it('should publish built event', function (done) {
102102
waitUntil(
103-
function() {
103+
function () {
104104
return res.events.length >= 3;
105105
},
106-
function() {
106+
function () {
107107
var event = JSON.parse(res.events[2].substring(5));
108108

109109
assert.equal(event.action, 'built');
@@ -123,28 +123,26 @@ describe('realistic single compiler', function() {
123123

124124
function request(path) {
125125
// Wrap some stuff up so supertest works with streaming responses
126-
var req = supertest(app)
127-
.get(path)
128-
.buffer(false);
126+
var req = supertest(app).get(path).buffer(false);
129127
var end = req.end;
130-
req.end = function(callback) {
131-
req.on('error', callback).on('response', function(res) {
128+
req.end = function (callback) {
129+
req.on('error', callback).on('response', function (res) {
132130
Object.defineProperty(res, 'events', {
133-
get: function() {
131+
get: function () {
134132
return res.text.trim().split('\n\n');
135133
},
136134
});
137-
res.on('data', function(chunk) {
135+
res.on('data', function (chunk) {
138136
res.text = (res.text || '') + chunk;
139137
});
140-
process.nextTick(function() {
141-
req.assert(null, res, function(err) {
138+
process.nextTick(function () {
139+
req.assert(null, res, function (err) {
142140
callback(err, res);
143141
});
144142
});
145143
});
146144

147-
end.call(req, function() {});
145+
end.call(req, function () {});
148146
};
149147
return req;
150148
}
@@ -153,7 +151,7 @@ function waitUntil(condition, body) {
153151
if (condition()) {
154152
body();
155153
} else {
156-
setTimeout(function() {
154+
setTimeout(function () {
157155
waitUntil(condition, body);
158156
}, 50);
159157
}

0 commit comments

Comments
 (0)
Please sign in to comment.