Skip to content

Commit

Permalink
Adding a feature flag to leave the previous behaviour and test in tact.
Browse files Browse the repository at this point in the history
  • Loading branch information
nataliecarey committed May 11, 2023
1 parent 6cef5c0 commit 15e9f87
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
const { managePluginsPagePath, performPluginAction } = require('../plugin-utils')
const { uninstallPlugin, installPlugin } = require('../../utils')
const path = require('path')

const plugin = 'govuk-frontend'
const pluginName = 'GOV.UK Frontend'
const dependentPlugin = '@govuk-prototype-kit/common-templates'
const appConfigPath = path.join('app', 'config.json')

describe('Manage prototype pages without govuk-frontend', () => {
before(() => {
cy.task('copyFromStarterFiles', { filename: appConfigPath })
cy.task('addToConfigJson', { allowGovukFrontendUninstall: true })
})
after(() => {
cy.task('copyFromStarterFiles', { filename: appConfigPath })
})
it('Uninstall govuk-frontend', () => {
uninstallPlugin(dependentPlugin)

Expand Down
10 changes: 10 additions & 0 deletions cypress/events/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// core dependencies
const fs = require('fs')
const fsp = fs.promises
const fse = require('fs-extra')
const path = require('path')

// npm dependencies
Expand Down Expand Up @@ -283,6 +284,15 @@ module.exports = function setupNodeEvents (on, config) {
.then(makeSureCypressCanInterpretTheResult)
},

addToConfigJson: (additionalConfig) => {
log(`Adding config JSON => ${downloadsFolder}`)
const appConfigPath = path.join(config.env.projectFolder, 'app', 'config.json')
return fse.readJson(appConfigPath)
.then(existingConfig => Object.assign({}, existingConfig, additionalConfig))
.then(newConfig => fse.writeJson(appConfigPath, newConfig))
.then(makeSureCypressCanInterpretTheResult)
},

log: (message) => {
log(message)
return makeSureCypressCanInterpretTheResult()
Expand Down
1 change: 1 addition & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function getConfig (config, swallowError = true) {
overrideOrDefault('logPerformanceSummary', 'LOG_PERFORMANCE_SUMMARY', asNumber, undefined)
overrideOrDefault('verbose', 'VERBOSE', asBoolean, false)
overrideOrDefault('showPrereleases', 'SHOW_PRERELEASES', asBoolean, false)
overrideOrDefault('allowGovukFrontendUninstall', 'ALLOW_GOVUK_FRONTEND_UNINSTALL', asBoolean, false)

if (config.serviceName === undefined) {
config.serviceName = 'GOV.UK Prototype Kit'
Expand Down
1 change: 1 addition & 0 deletions lib/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('config', () => {
useNjkExtensions: false,
logPerformance: false,
showPrereleases: false,
allowGovukFrontendUninstall: false,
verbose: false
})

Expand Down
6 changes: 5 additions & 1 deletion lib/manage-prototype-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,11 @@ async function getPluginDetails () {
const pluginPkgPath = path.join(projectDir, 'node_modules', pack.packageName, 'package.json')
const pluginPkg = await fse.pathExists(pluginPkgPath) ? await fse.readJson(pluginPkgPath) : {}
pack.installedVersion = pluginPkg.version
if (!['govuk-prototype-kit', 'govuk-frontend'].includes(pack.packageName)) {
const mandatoryPlugins = ['govuk-prototype-kit']
if (!config.getConfig().allowGovukFrontendUninstall) {
mandatoryPlugins.push('govuk-frontend')
}
if (!mandatoryPlugins.includes(pack.packageName)) {
pack.uninstallLink = `${contextPath}/plugins/uninstall?package=${encodeURIComponent(pack.packageName)}`
}
}
Expand Down

0 comments on commit 15e9f87

Please sign in to comment.