webpack-hot-middleware
Advanced tools
Comparing version 2.6.0 to 2.6.1
@@ -18,3 +18,3 @@ /*eslint-env browser*/ | ||
if (document.body) { | ||
if (typeof document !== 'undefined' && document.body) { | ||
document.body.appendChild(clientOverlay); | ||
@@ -21,0 +21,0 @@ } |
@@ -28,3 +28,5 @@ /*eslint-env browser*/ | ||
if (typeof window.EventSource === 'undefined') { | ||
if (typeof window === 'undefined') { | ||
// do nothing | ||
} else if (typeof window.EventSource === 'undefined') { | ||
console.warn( | ||
@@ -36,7 +38,7 @@ "webpack-hot-middleware's client requires EventSource to work. " + | ||
} else { | ||
connect(); | ||
connect(window.EventSource); | ||
} | ||
function connect() { | ||
var source = new window.EventSource(options.path); | ||
function connect(EventSource) { | ||
var source = new EventSource(options.path); | ||
var lastActivity = new Date(); | ||
@@ -76,3 +78,3 @@ | ||
source.close(); | ||
setTimeout(connect, options.timeout); | ||
setTimeout(function() { connect(EventSource); }, options.timeout); | ||
} | ||
@@ -79,0 +81,0 @@ |
{ | ||
"name": "webpack-hot-middleware", | ||
"version": "2.6.0", | ||
"version": "2.6.1", | ||
"description": "Webpack hot reloading you can attach to your own server", | ||
@@ -5,0 +5,0 @@ "main": "middleware.js", |
@@ -91,2 +91,19 @@ # Webpack Hot Middleware | ||
## Other Frameworks | ||
### Hapi | ||
Use the [hapi-webpack-plugin](https://www.npmjs.com/package/hapi-webpack-plugin). | ||
### Koa | ||
```js | ||
var app = koa(); | ||
app.use(function* (next) { | ||
yield require("webpack-hot-middleware")(compiler).bind(null, this.req, this.res); | ||
yield next; | ||
}); | ||
``` | ||
## Troubleshooting | ||
@@ -117,13 +134,2 @@ | ||
### Use with koa | ||
```js | ||
var app = koa(); | ||
app.use(function* (next) { | ||
yield require("webpack-hot-middleware")(compiler).bind(null, this.req, this.res); | ||
yield next; | ||
}); | ||
``` | ||
## License | ||
@@ -130,0 +136,0 @@ |
@@ -6,6 +6,20 @@ /* eslint-env mocha, browser */ | ||
describe("client", function() { | ||
var client, clientOverlay, processUpdate; | ||
var s, client, clientOverlay, processUpdate; | ||
beforeEach(function() { | ||
s = sinon.sandbox.create(); | ||
}); | ||
afterEach(function() { | ||
s.restore(); | ||
}); | ||
context("with default options", function() { | ||
beforeEach(setup()); | ||
beforeEach(function setup() { | ||
global.__resourceQuery = ''; // eslint-disable-line no-underscore-dangle | ||
global.window = { | ||
EventSource: sinon.stub().returns({ | ||
close: sinon.spy() | ||
}) | ||
}; | ||
}); | ||
beforeEach(loadClient); | ||
@@ -45,2 +59,26 @@ it("should connect to __webpack_hmr", function() { | ||
context("with no browser environment", function() { | ||
beforeEach(function setup() { | ||
global.__resourceQuery = ''; // eslint-disable-line no-underscore-dangle | ||
delete global.window; | ||
}); | ||
beforeEach(loadClient); | ||
it("should not connect", function() { | ||
// doesn't error | ||
}); | ||
}); | ||
context("with no EventSource", function() { | ||
beforeEach(function setup() { | ||
global.__resourceQuery = ''; // eslint-disable-line no-underscore-dangle | ||
global.window = {}; | ||
s.stub(console, 'warn'); | ||
}); | ||
beforeEach(loadClient); | ||
it("should emit warning and not connect", function() { | ||
sinon.assert.calledOnce(console.warn); | ||
sinon.assert.calledWithMatch(console.warn, /EventSource/); | ||
}); | ||
}); | ||
function makeMessage(obj) { | ||
@@ -71,14 +109,2 @@ return { data: typeof obj === 'string' ? obj : JSON.stringify(obj) }; | ||
}); | ||
function setup(options) { | ||
options = options || {}; | ||
return function() { | ||
global.__resourceQuery = options.resourceQuery || ''; // eslint-disable-line no-underscore-dangle, max-len | ||
global.window = { | ||
EventSource: sinon.stub().returns({ | ||
close: sinon.spy() | ||
}) | ||
}; | ||
}; | ||
} | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33250
712
138