Skip to content

Commit

Permalink
Merge pull request #1491 from alphagov/ldeb-add-watch-js-test
Browse files Browse the repository at this point in the history
Fix page reloads when prototype assets are changed
  • Loading branch information
lfdebrux authored Jul 29, 2022
2 parents 8f900ba + 456f24f commit 66a8e56
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

- [#1476: Update to GOV.UK Frontend 4.2.0](https://github.com/alphagov/govuk-prototype-kit/pull/1476)

### Fixes

- [#1491: Fix page reloads when prototype assets are changed](https://github.com/alphagov/govuk-prototype-kit/pull/1491)

### Other changes

- [#866: Remove docs from the Prototype Kit](https://github.com/alphagov/govuk-prototype-kit/issues/866)
Expand Down
40 changes: 40 additions & 0 deletions cypress/integration/1-watch-files/watch-javascripts.cypress.js
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()
})
})
})
2 changes: 1 addition & 1 deletion lib/build/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function runNodemon () {
ignore: [
'public/*',
'cypress/*',
`${paths.assets}*`,
`${paths.assets}/*`,
'node_modules/*'
]
})
Expand Down

0 comments on commit 66a8e56

Please sign in to comment.