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
add liveReload option to enable/disable refreshing the page #1812
Changes from all commits
03f1dae
3b7a72d
6e56bc9
3dd9206
252b73f
d3149c1
e858aa5
bebf0f4
bb8acfa
ac6da29
569c914
d86b591
92cddd7
ff3d872
17e1fc0
22d5c98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,110 @@ describe('ContentBase', () => { | |
let server; | ||
let req; | ||
|
||
describe('Test disabling live reloading', () => { | ||
const nestedFile = path.join(contentBasePublic, 'assets/example.txt'); | ||
|
||
jest.setTimeout(30000); | ||
|
||
beforeAll((done) => { | ||
server = helper.start( | ||
config, | ||
{ | ||
contentBase: contentBasePublic, | ||
watchContentBase: true, | ||
liveReload: false, | ||
}, | ||
done | ||
); | ||
req = request(server.app); | ||
}); | ||
|
||
afterAll((done) => { | ||
helper.close(() => { | ||
done(); | ||
}); | ||
fs.truncateSync(nestedFile); | ||
}); | ||
|
||
it('Should not reload on changing files', (done) => { | ||
let reloaded = false; | ||
|
||
server.contentBaseWatchers[0].on('change', () => { | ||
// it means that file has changed | ||
|
||
// simulating server behaviour | ||
if (server.options.liveReload !== false) { | ||
Object.defineProperty(window.location, 'reload', { | ||
configurable: true, | ||
}); | ||
window.location.reload = jest.fn(); | ||
window.location.reload(); | ||
reloaded = true; | ||
} | ||
expect(reloaded).toBe(false); | ||
|
||
done(); | ||
}); | ||
|
||
// change file content | ||
setTimeout(() => { | ||
fs.writeFileSync(nestedFile, 'Heyo', 'utf8'); | ||
}, 1000); | ||
}); | ||
}); | ||
|
||
describe('Testing live reloading', () => { | ||
const nestedFile = path.join(contentBasePublic, 'assets/example.txt'); | ||
|
||
jest.setTimeout(30000); | ||
|
||
beforeAll((done) => { | ||
server = helper.start( | ||
config, | ||
{ | ||
contentBase: contentBasePublic, | ||
watchContentBase: true, | ||
liveReload: true, | ||
}, | ||
done | ||
); | ||
req = request(server.app); | ||
}); | ||
|
||
afterAll((done) => { | ||
helper.close(() => { | ||
done(); | ||
}); | ||
fs.truncateSync(nestedFile); | ||
}); | ||
|
||
it('Should reload on changing files', (done) => { | ||
let reloaded = false; | ||
|
||
server.contentBaseWatchers[0].on('change', () => { | ||
// it means that files has changed | ||
|
||
// simulating server behaviour | ||
if (server.options.liveReload !== false) { | ||
Object.defineProperty(window.location, 'reload', { | ||
configurable: true, | ||
}); | ||
window.location.reload = jest.fn(); | ||
window.location.reload(); | ||
reloaded = true; | ||
} | ||
expect(reloaded).toBe(true); | ||
|
||
done(); | ||
}); | ||
|
||
// change file content | ||
setTimeout(() => { | ||
fs.writeFileSync(nestedFile, 'Heyo', 'utf8'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed many typos, now is everything ok? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, this comment is my mistake. Sorry... |
||
}, 1000); | ||
}); | ||
}); | ||
|
||
describe('to directory', () => { | ||
const nestedFile = path.join(contentBasePublic, 'assets/example.txt'); | ||
|
||
|
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.
webpack-dev-server/lib/utils/createConfig.js
Line 114 in 9a86d02
--no-live-reload
because be defaultliveReload
should betrue