-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1491 from alphagov/ldeb-add-watch-js-test
Fix page reloads when prototype assets are changed
- Loading branch information
Showing
3 changed files
with
45 additions
and
1 deletion.
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
40 changes: 40 additions & 0 deletions
40
cypress/integration/1-watch-files/watch-javascripts.cypress.js
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,40 @@ | ||
const path = require('path') | ||
|
||
const { waitForApplication } = require('../utils') | ||
|
||
const appJs = path.join(Cypress.env('projectFolder'), 'app', 'assets', 'javascripts', 'application.js') | ||
const backupAppJs = path.join(Cypress.env('tempFolder'), 'temp-application.js') | ||
|
||
describe('watch application.js', () => { | ||
before(() => { | ||
waitForApplication() | ||
|
||
// backup application.js | ||
cy.task('copyFile', { source: appJs, target: backupAppJs }) | ||
}) | ||
|
||
after(() => { | ||
// restore files | ||
cy.task('copyFile', { source: backupAppJs, target: appJs }) | ||
}) | ||
|
||
it('changes to application.js should be reflected in browser', (done) => { | ||
const onAlert = cy.stub() | ||
cy.on('window:alert', onAlert) | ||
|
||
const markerText = 'window.GOVUKFrontend.initAll()' | ||
const newText = markerText + '\n ' + "window.alert('Test')" | ||
|
||
cy.task('replaceTextInFile', { | ||
filename: appJs, | ||
originalText: markerText, | ||
newText | ||
}) | ||
|
||
// wait for page to be reloaded by Browsersync | ||
cy.once('window:load', () => { | ||
expect(onAlert).to.be.calledWith('Test') | ||
done() | ||
}) | ||
}) | ||
}) |
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