-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: disable socket injection when hot & liveReload are disabled (V4) #2601
Conversation
Codecov Report
@@ Coverage Diff @@
## v4 #2601 +/- ##
=======================================
Coverage 92.34% 92.35%
=======================================
Files 34 34
Lines 1320 1321 +1
Branches 372 373 +1
=======================================
+ Hits 1219 1220 +1
Misses 96 96
Partials 5 5
Continue to review full report at Codecov.
|
client-src/default/index.js
Outdated
log.error('[WDS] Disconnected!'); | ||
} else { | ||
log.error('[WDS] Hot Module Replacement & Live Reloading are disabled!'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree
lib/Server.js
Outdated
@@ -659,7 +659,9 @@ class Server { | |||
this.hostname = hostname; | |||
|
|||
return this.listeningApp.listen(port, hostname, (err) => { | |||
this.createSocketServer(); | |||
if (this.options.hot || this.options.liveReload !== false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this.options.liveReload
in normalizeOptions
with code:
options.liveReload = typeof options.liveReload !== "undefined" ? options.liveReload : true;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job, couple changes
client-src/default/index.js
Outdated
log.error('[WDS] Disconnected!'); | ||
} else { | ||
log.error('[WDS] Hot Module Replacement & Live Reloading are disabled!'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree
test/e2e/ClientOptions.test.js
Outdated
const res = []; | ||
const testOptions = Object.assign({}, baseOptions, options); | ||
|
||
// TODO: use async/await when Node.js v6 support is dropped |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use async/await already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hiroppy I tried many times to use async/await but every time I get errors or wrong results, my last attempt was :
cases.forEach(async ({ title, options }) => {
title += ` (${
Object.keys(mode).length ? mode.transportMode : 'default'
})`;
options = { ...mode, ...options };
testOptions = Object.assign({}, baseOptions, options);
await testServer.startAwaitingCompilation(config, testOptions); // and without await
it(title, (done) => {
const res = [];
runBrowser().then(({ page, browser }) => {
page.goto(`http://localhost:${port2}/main`);
page.on('console', ({ _text }) => {
res.push(_text);
});
// wait for load before closing the browser
page.waitForNavigation({ waitUntil: 'load' }).then(() => {
page.waitFor(beforeBrowserCloseDelay).then(() => {
browser.close().then(() => {
// Order doesn't matter, maybe we should improve that in future
expect(res.sort()).toMatchSnapshot();
testServer.close(done)
});
});
});
});
});
});
for now It works fine, I need help with rewriting this with async/await.
@Loonride any thoughts for this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the issue is forEach won't work with async, as in it won't wait for the previous iteration to finish before doing the next one, at the very top where you do cases.forEach
. Try doing a normal for loop and see if that fixes it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Loonride thanks for the hint, what fixed the issue was adding await
before it
& adding the server starter inside it
, not sure if converting the other promises helped ex :
await it(title, async (done) => {
await testServer.startAwaitingCompilation(config, testOptions);
const res = [];
const { page, browser } = await runBrowser();
page.goto(`http://localhost:${port2}/main`);
page.on('console', ({ _text }) => {
res.push(_text);
});
// wait for load before closing the browser
await page.waitForNavigation({ waitUntil: 'load' });
await page.waitFor(beforeBrowserCloseDelay);
await browser.close();
// Order doesn't matter, maybe we should improve that in future
await expect(res.sort()).toMatchSnapshot();
await testServer.close(done);
});
It's strange that using for
for the inner loop didn't work & skipped many tests.
Looks like |
@EslamHiko Please fix conflicts, sorry for the situation 😄 |
d2a0bfd
to
a66d157
Compare
/cc @evilebottnawi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @hiroppy
For Bugs and Features; did you add new tests?
Yes
Motivation / Use-Case
fix : #1831
Alternative to : #2133
Breaking Changes
The socket server will be disabled when
hot
andliveReload
are disabled.Additional Info
I updated the values of
liveReload: false
tests sincehot
became enabled by default.I added tests for
ws
and movedsocket-injection.test.js
toe2e
folder since e2e testing is the only way to testws
as it became the default websocket.Also I've updated
console.log
test intest/e2e/ClientOptions.test.js
to check for all WebSocket options.Not sure if logging tests in
test/e2e/ClientOptions.test.js
are enough so I don't know whether I should deletetest/e2e/socket-injection.test.js
or not.