From 956afeb819858c6a32154962bbf64c193867960e Mon Sep 17 00:00:00 2001 From: Natalie Carey Date: Sun, 21 Jan 2024 18:16:55 +0000 Subject: [PATCH] Focussing on the tests we have. --- .github/workflows/test-acceptance.yaml | 9 +--- .github/workflows/test-heroku.yaml | 32 ------------ .github/workflows/validate.yaml | 4 +- lib/plugins/plugin-validator.js | 72 +++++++++++++++----------- 4 files changed, 46 insertions(+), 71 deletions(-) delete mode 100644 .github/workflows/test-heroku.yaml diff --git a/.github/workflows/test-acceptance.yaml b/.github/workflows/test-acceptance.yaml index 7b879b4acf..12c6e606fa 100644 --- a/.github/workflows/test-acceptance.yaml +++ b/.github/workflows/test-acceptance.yaml @@ -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 }} @@ -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 diff --git a/.github/workflows/test-heroku.yaml b/.github/workflows/test-heroku.yaml deleted file mode 100644 index 1b15ea5544..0000000000 --- a/.github/workflows/test-heroku.yaml +++ /dev/null @@ -1,32 +0,0 @@ -name: Tests (Heroku) - -on: - push: - branches: - - main - - support/* - pull_request: - -jobs: - test-heroku: - - name: Test kit on Heroku - runs-on: ubuntu-latest - - env: - CYPRESS_CACHE_FOLDER: ~/.cache/Cypress - - steps: - - uses: actions/checkout@v3 - - name: Use Node v18 - uses: actions/setup-node@v3 - with: - cache: 'npm' - node-version: '20' - - name: Cache Cypress binary - uses: actions/cache@v3 - with: - path: ~/.cache/Cypress - key: cypress-${{ runner.os }}-cypress-${{ hashFiles('**/package.json') }} - - run: npm ci - - run: npm run test:heroku diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml index 0dc1eb99da..fa2f3e8d4c 100644 --- a/.github/workflows/validate.yaml +++ b/.github/workflows/validate.yaml @@ -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 diff --git a/lib/plugins/plugin-validator.js b/lib/plugins/plugin-validator.js index 9fb928cbc0..7b8e29017e 100644 --- a/lib/plugins/plugin-validator.js +++ b/lib/plugins/plugin-validator.js @@ -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 = [] @@ -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