Skip to content

Commit

Permalink
Focussing on the tests we have.
Browse files Browse the repository at this point in the history
  • Loading branch information
nataliecarey committed Jan 21, 2024
1 parent 80ad9da commit 956afeb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 71 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/test-acceptance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
fail-fast: false # continue other tests if one test in matrix fails
matrix:
node-version: [20.x]
os: [macos-latest, windows-latest, ubuntu-latest]
type: [smoke, plugins, styles, dev, prod, errors]
os: [macos-latest, ubuntu-latest]
type: [plugins, dev]

name: Acceptance ${{ matrix.type }} test kit on Node v${{ matrix.node-version }} (${{ matrix.os }})
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -44,11 +44,6 @@ jobs:
- run: npm ci

- run: npm run test:acceptance:${{ matrix.type }}
env:
CYPRESS_REQUEST_TIMEOUT: 20000
CYPRESS_DEFAULT_COMMAND_TIMEOUT: 40000
CYPRESS_PAGE_LOAD_TIMEOUT: 120000
CYPRESS_RETRIES: 3

- if: ${{ failure() }}
uses: actions/upload-artifact@v3
Expand Down
32 changes: 0 additions & 32 deletions .github/workflows/test-heroku.yaml

This file was deleted.

4 changes: 3 additions & 1 deletion .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ jobs:
steps:
- uses: actions/checkout@v3

- run: npx govuk-prototype-kit@snapshot validate-plugin
- run: npm ci

- run: ./bin/cli validate-plugin validate-plugin
72 changes: 41 additions & 31 deletions lib/plugins/plugin-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ function reportInvalidKeys (invalidKeys) {
}

function validateConfigKeys (pluginConfig, argv) {
console.log('Config file exists, validating contents.')
const keysToAllowThrough = argv?.options?.keysToIgnoreIfUnknown || ''
const allowedKeys = knownKeys.concat(keysToAllowThrough.split(',').filter(key => !!key))
const invalidKeys = []
Expand Down Expand Up @@ -205,42 +204,53 @@ function validateConfigurationValues (pluginConfig, executionPath) {

async function validatePlugin (executionPath, argv) {
console.log()
const configPath = path.join(executionPath, 'govuk-prototype-kit.config.json')
await fse.exists(configPath).then(exists => {
if (exists) {
let pluginConfig
try {
pluginConfig = JSON.parse(fs.readFileSync(configPath, 'utf8'))
} catch (error) {
// Catch any syntax errors in the config
errors.push('Your govuk-prototype-kit.config.json file is not valid json.')
}
let configFileName = 'nowprototypeit.config.json or govuk-prototype-kit.config.json'
await Promise.all([
path.join(executionPath, 'nowprototypeit.config.json'),
path.join(executionPath, 'govuk-prototype-kit.config.json')
].map(async path => ({
path,
exists: await fse.exists(path)
})))
.then(configPaths => {
const mainConfigPath = configPaths.find(x => x.exists)?.path
if (mainConfigPath) {
configFileName = mainConfigPath.substring(path.dirname(mainConfigPath).length + 1)
let pluginConfig
try {
pluginConfig = JSON.parse(fs.readFileSync(mainConfigPath, 'utf8'))
} catch (error) {
// Catch any syntax errors in the config
errors.push(`Your ${configFileName} file is not valid json.`)
}

// Check if the json has contents
let isConfigEmpty = false
const { meta, ...configWithoutMeta } = pluginConfig || {}
if (JSON.stringify(configWithoutMeta) === '{}') {
isConfigEmpty = true
}
// Check if the json has contents
let isConfigEmpty = false
const { meta, ...configWithoutMeta } = pluginConfig || {}
if (JSON.stringify(configWithoutMeta) === '{}') {
isConfigEmpty = true
}

// Continue with the validation if there are no syntax errors in the config
if (pluginConfig) {
if (isConfigEmpty) {
const caveat = meta ? ' other than the metadata' : ''
errors.push(`There are no contents in your govuk-prototype.config file${caveat}!`)
} else {
// Perform the rest of the checks if the config file has contents
const validKeysPluginConfig = validateConfigKeys(pluginConfig, argv)
validateConfigurationValues(validKeysPluginConfig, executionPath)
// Continue with the validation if there are no syntax errors in the config
if (pluginConfig) {
if (isConfigEmpty) {
const caveat = meta ? ' other than the metadata' : ''
errors.push(`There are no contents in your govuk-prototype.config file${caveat}!`)
} else {

console.log(`Config file ${configFileName} exists, validating contents.`)
// Perform the rest of the checks if the config file has contents
const validKeysPluginConfig = validateConfigKeys(pluginConfig, argv)
validateConfigurationValues(validKeysPluginConfig, executionPath)
}
}
} else {
errors.push('The plugin does not have a nowprototypeit.config.json or govuk-prototype-kit.config.json file, all plugins must have this file to be valid.')
}
} else {
errors.push('The plugin does not have a govuk-prototype-kit.config.json file, all plugins must have this file to be valid.')
}
})
})
if (!errors.length > 0) {
console.log()
console.log(ansiColors.green('The plugin config is valid.'))
console.log(ansiColors.green(`The plugin config in ${configFileName} is valid.`))
console.log()
} else {
process.exitCode = 100
Expand Down

0 comments on commit 956afeb

Please sign in to comment.