-
Notifications
You must be signed in to change notification settings - Fork 237
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
Prevent management pages using "plugin" GOV.UK Frontend views #2355
Conversation
Plenty of failing tests to look at Nunjucks wise, management pages won’t have access to plugin filters, functions or Express.js app locals |
GOV.UK Frontend `nunjucksPaths` and `sass` config fields may potentially be `string | string[]` values one day
Prototype pages should use the “plugin” version by default although we’ll add an improved way to provide a backup version should the plugin be uninstalled
bd054fd
to
60ea990
Compare
Adds an option param to `getNunjucksAppEnv()` to append backup view directories
e9086d2
to
d3a4381
Compare
Jest uses Babel to hoist `jest.mock()` calls above `require()` already But this change avoids needing a second call to update the mock implementation in a `beforeEach()` when it would be too late to do so
This prevents Manage prototype pages using “plugin” GOV.UK Frontend Unlike other management pages, the handler `getTemplatesViewHandler()` will still pick up the GOV.UK Frontend “plugin” version
Management pages use locals like `serviceName` which custom Nunjucks environments don’t provide Here we’re restoring the same `app.locals` that the route’s `res.render()` included by default previously
d3a4381
to
293015b
Compare
We're all set on this one now I've made sure management pages keep Express.js app locals |
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.
Looks good to me
Thanks @BenSurgisonGDS, just added a CHANGELOG entry |
CHANGELOG.md
Outdated
@@ -8,6 +8,7 @@ | |||
|
|||
- [#2306: Locate GOV.UK Frontend using `require.resolve()`](https://github.com/alphagov/govuk-prototype-kit/pull/2306) | |||
- [#2349: Fix GOV.UK Frontend `initAll()` on management pages](https://github.com/alphagov/govuk-prototype-kit/pull/2349) | |||
- [#2355: Prevent management pages using "plugin" GOV.UK Frontend views](https://github.com/alphagov/govuk-prototype-kit/pull/2355) |
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.
This should be under "Unreleased" instead of "13.13.4".
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.
Nice spot, done ✅
99492e1
to
4781c10
Compare
|
||
beforeEach(() => { | ||
mockSend = jest.fn() | ||
res.status = jest.fn().mockReturnValue({ send: mockSend }) | ||
res.status = jest.fn().mockReturnValue({ send: res.send }) |
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.
Is there any reason we're not using:
res.status = jest.fn().mockReturnValue(res)
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.
No not at all, loads of ways to do this
Let me know if it's a blocker
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've added it this morning, nice improvement should we need it in future
There's another handy shorthand if it's helpful for other tests:
- lookupPackageInfo: jest.fn().mockImplementation((packageName) => {
+ lookupPackageInfo: jest.fn((packageName) => {
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.
Approved after Natalie's suggestion implemented
This PR fixes #2352 for management pages only
The fix uses
res.send()
with a custom Nunjucks environment as used bygetTemplatesViewHandler()
Management pages previously used Express.js
res.render()
with all plugin Nunjucks views availableGOV.UK Frontend v5 release
Without this bugfix, users upgrading to GOV.UK Frontend v5 would see management pages load Nunjucks views from GOV.UK Frontend v5 but fonts, assets, styles and scripts from GOV.UK Frontend v4