Skip to content

Commit

Permalink
Align review app with tests
Browse files Browse the repository at this point in the history
Try to be consistent with the approach taken in the tests by checking for the presence of the `CI` or `HEROKU_APP` environment variables.

This ensures that we only enable certain optimisations when we know we’re running against an up-to-date build (on CI or when deployed to Heroku).

Co-authored-by: Colin Rotherham <colin.rotherham@digital.cabinet-office.gov.uk>
  • Loading branch information
36degrees and colinrotherham committed Jan 17, 2024
1 parent 71b68f3 commit 75c6832
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
8 changes: 3 additions & 5 deletions packages/govuk-frontend-review/src/app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ export default async () => {

// Feature flags
const flags = /** @type {FeatureFlags} */ ({
isDeployedToHeroku: !!process.env.HEROKU_APP,
isDevelopment: !['test', 'production'].includes(process.env.NODE_ENV),
isDevelopment: !process.env.HEROKU_APP && !process.env.CI,

// Check for JSDoc, SassDoc and Rollup stats
hasDocsScripts: await hasPath(join(paths.app, 'dist/docs/jsdoc')),
Expand Down Expand Up @@ -221,7 +220,7 @@ export default async () => {
env,

// Skip Nunjucks render from cache in development
fixture: !flags.isDevelopment ? fixture : undefined
fixture: flags.isDevelopment ? undefined : fixture
})

let bodyClasses = 'app-template__body'
Expand Down Expand Up @@ -278,8 +277,7 @@ export default async () => {

/**
* @typedef {object} FeatureFlags
* @property {boolean} isDeployedToHeroku - Review app using `HEROKU_APP`
* @property {boolean} isDevelopment - Review app not using `NODE_ENV` production or test
* @property {boolean} isDevelopment - Review app not in CI or on Heroku
* @property {boolean} hasDocsStyles - Stylesheets documentation (SassDoc) is available
* @property {boolean} hasDocsScripts - JavaScripts documentation (JSDoc) is available
* @property {boolean} hasStats - Rollup stats are available
Expand Down
4 changes: 2 additions & 2 deletions packages/govuk-frontend-review/src/common/middleware/docs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ router.get('/', (req, res) => {
* Sass docs latest release (when deployed)
*/
router.use('/sass', ({ app }, res, next) => {
const { isDeployedToHeroku } =
const { isDevelopment } =
/** @type {import('../../app.mjs').FeatureFlags} */ (app.get('flags'))

if (isDeployedToHeroku) {
if (!isDevelopment) {
return res.redirect(
'https://frontend.design-system.service.gov.uk/sass-api-reference/'
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function renderer(app) {
{
dev: true, // log stack traces
express: app, // the Express.js review app that nunjucks should install to
noCache: !flags.isDeployedToHeroku, // use cache when deployed only
noCache: flags.isDevelopment, // use cache in development only
watch: flags.isDevelopment // reload templates in development only
},
{
Expand Down

0 comments on commit 75c6832

Please sign in to comment.