-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): add liveReload option to enable/disable live reloading (#…
…1889) * feat(server): add liveReload option to enable/disable live reloading * test(server): move live reload tests to new file * fix(server): use this.options * test: use master's snapshot * test: update snapshot * test: update snapshot 2 * test: fix snapshot
- Loading branch information
Showing
7 changed files
with
148 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const fs = require('fs'); | ||
const helper = require('./helper'); | ||
const config = require('./fixtures/contentbase-config/webpack.config'); | ||
|
||
const contentBasePublic = path.join( | ||
__dirname, | ||
'fixtures/contentbase-config/public' | ||
); | ||
|
||
describe('liveReload', () => { | ||
let server; | ||
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 | ||
); | ||
}); | ||
|
||
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 | ||
); | ||
}); | ||
|
||
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'); | ||
}, 1000); | ||
}); | ||
}); | ||
}); |
Large diffs are not rendered by default.
Oops, something went wrong.