diff --git a/.github/actions/acceptance-tests-setup/action.yaml b/.github/actions/acceptance-tests-setup/action.yaml new file mode 100644 index 0000000000..0542e42f8c --- /dev/null +++ b/.github/actions/acceptance-tests-setup/action.yaml @@ -0,0 +1,47 @@ +name: Acceptance tests +description: "Run acceptance tests for this repo" + +inputs: + + targetComponent: + description: Name of the component under test + required: true + + skipRestore: + description: 'Skips restoring from caches' + required: false + default: true + +runs: + using: "composite" + + steps: + - name: Fetch terraform output + uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5 + with: + name: terraform-output-${{ inputs.targetComponent }} + + - name: "Restore node_modules from cache" + uses: ./.github/actions/node-modules-cache + with: + node_version: "22.22.0" + skip_restore: "${{ inputs.skipRestore }}" + + - name: Generate outputs file + shell: bash + run: | + root_dir=${GITHUB_WORKSPACE} + mv ./terraform_output.json ./sandbox_tf_outputs.json + npm run generate-outputs sandbox-output + + - name: "Restore playwright dependencies from cache" + uses: ./.github/actions/playwright-cache + with: + playwright_version: "1.59.1" + skip_restore: "${{ inputs.skipRestore }}" + + - name: "Restore next build from cache" + uses: ./.github/actions/next-build-cache + with: + node_version: "22.22.0" + skip_restore: "${{ inputs.skipRestore }}" diff --git a/.github/actions/acceptance-tests/action.yaml b/.github/actions/acceptance-tests/action.yaml index 68c8e5cfd5..9855f37f6c 100644 --- a/.github/actions/acceptance-tests/action.yaml +++ b/.github/actions/acceptance-tests/action.yaml @@ -23,21 +23,12 @@ runs: using: "composite" steps: - - name: Fetch terraform output - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5 + - name: Acceptance tests setup + uses: ./.github/actions/acceptance-tests-setup with: - name: terraform-output-${{ inputs.targetComponent }} - - name: "Repo setup" - shell: bash - run: | - npm ci + skipRestore: false + targetComponent: "${{ inputs.targetComponent }}" - - name: Generate outputs file - shell: bash - run: | - root_dir=${GITHUB_WORKSPACE} - mv ./terraform_output.json ./sandbox_tf_outputs.json - npm run generate-outputs sandbox-output - name: Run test - ${{ inputs.testType }} shell: bash diff --git a/.github/actions/next-build-cache/action.yaml b/.github/actions/next-build-cache/action.yaml new file mode 100644 index 0000000000..dc5072cec1 --- /dev/null +++ b/.github/actions/next-build-cache/action.yaml @@ -0,0 +1,34 @@ +name: 'Node modules cache + setup' +description: 'Run nextjs build, restoring from cache if possible' + +inputs: + node_version: + description: 'Node.js version' + required: true + cache_lock_path: + description: 'Path(s) to package-lock.json for cache key' + required: false + default: '**/package-lock.json' + skip_restore: + description: 'Skips restoring next build' + required: false + default: false + +runs: + using: 'composite' + steps: + + - name: 'Restore next build from cache' + id: next-build-cache + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 + with: + path: | + frontend/.next + key: ${{ runner.os }}-next-build-${{ inputs.node_version }}-${{ hashFiles(inputs.cache_lock_path) }} + lookup-only: ${{ inputs.skip_restore }} + + - name: 'Install dependencies (cache miss)' + if: steps.node-modules-cache.outputs.cache-hit != 'true' + shell: bash + run: | + INCLUDE_AUTH_PAGES=true npm run build diff --git a/.github/actions/node-modules-cache/action.yaml b/.github/actions/node-modules-cache/action.yaml index 3a13ec9376..9d398031d2 100644 --- a/.github/actions/node-modules-cache/action.yaml +++ b/.github/actions/node-modules-cache/action.yaml @@ -33,8 +33,6 @@ runs: node_modules **/node_modules key: ${{ runner.os }}-node-${{ inputs.node_version }}-${{ hashFiles(inputs.cache_lock_path) }} - restore-keys: | - ${{ runner.os }}-node-${{ inputs.node_version }}- lookup-only: ${{ inputs.skip_restore }} - name: 'Install dependencies (cache miss)' diff --git a/.github/actions/playwright-cache/action.yaml b/.github/actions/playwright-cache/action.yaml new file mode 100644 index 0000000000..b2cc1e8c13 --- /dev/null +++ b/.github/actions/playwright-cache/action.yaml @@ -0,0 +1,34 @@ +name: 'Playwright browser cache' +description: 'Cache Playwright browser binaries and install system dependencies' + +inputs: + playwright_version: + description: 'Playwright version to cache.' + required: true + default: '' + skip_restore: + description: 'Skips restoring playwright browser cache' + required: false + default: false + +runs: + using: 'composite' + steps: + + - name: 'Restore Playwright browsers from cache' + id: playwright-cache + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 + with: + path: ~/.cache/ms-playwright + key: ${{ runner.os }}-playwright-${{ inputs.playwright_version }} + lookup-only: ${{ inputs.skip_restore }} + + - name: 'Install Playwright browsers (cache miss)' + if: steps.playwright-cache.outputs.cache-hit != 'true' + shell: bash + run: npx playwright install --with-deps + + - name: 'Install Playwright system dependencies (cache hit)' + if: steps.playwright-cache.outputs.cache-hit == 'true' + shell: bash + run: npx playwright install-deps diff --git a/.github/workflows/stage-4-acceptance.yaml b/.github/workflows/stage-4-acceptance.yaml index 25a6b1f935..38a706e659 100644 --- a/.github/workflows/stage-4-acceptance.yaml +++ b/.github/workflows/stage-4-acceptance.yaml @@ -46,4 +46,5 @@ jobs: --targetWorkflow "dispatch-contextual-tests-dynamic-env.yaml" \ --targetEnvironment "pr${{ inputs.pr_number }}" \ --targetAccountGroup "nhs-notify-template-management-dev" \ - --targetComponent "sbx" + --targetComponent "sbx" \ + --internalRef "feature/CCM-18086_acceptance-tests-setup" diff --git a/scripts/tests/api.sh b/scripts/tests/api.sh index 01beadfb7d..8e7550eb90 100755 --- a/scripts/tests/api.sh +++ b/scripts/tests/api.sh @@ -1,9 +1,7 @@ #!/bin/bash set -euo pipefail -cd "$(git rev-parse --show-toplevel)" -npx playwright install --with-deps > /dev/null -cd tests/test-team +cd "$(git rev-parse --show-toplevel)/tests/test-team" TEST_EXIT_CODE=0 npm run test:api || TEST_EXIT_CODE=$? echo "TEST_EXIT_CODE=$TEST_EXIT_CODE" diff --git a/scripts/tests/backend.sh b/scripts/tests/backend.sh index 8b8440d45b..ad371ae3e5 100755 --- a/scripts/tests/backend.sh +++ b/scripts/tests/backend.sh @@ -1,9 +1,7 @@ #!/bin/bash set -euo pipefail -cd "$(git rev-parse --show-toplevel)" -npx playwright install --with-deps > /dev/null -cd tests/test-team +cd "$(git rev-parse --show-toplevel)/tests/test-team" TEST_EXIT_CODE=0 npm run test:backend || TEST_EXIT_CODE=$? echo "TEST_EXIT_CODE=$TEST_EXIT_CODE" diff --git a/scripts/tests/event.sh b/scripts/tests/event.sh index 881be48eb3..35e94d02bc 100755 --- a/scripts/tests/event.sh +++ b/scripts/tests/event.sh @@ -1,9 +1,7 @@ #!/bin/bash set -euo pipefail -cd "$(git rev-parse --show-toplevel)" -npx playwright install --with-deps > /dev/null -cd tests/test-team +cd "$(git rev-parse --show-toplevel)/tests/test-team" TEST_EXIT_CODE=0 npm run test:event || TEST_EXIT_CODE=$? echo "TEST_EXIT_CODE=$TEST_EXIT_CODE" diff --git a/scripts/tests/ui-accessibility.sh b/scripts/tests/ui-accessibility.sh index d139b5d5f8..e81e33bbdb 100755 --- a/scripts/tests/ui-accessibility.sh +++ b/scripts/tests/ui-accessibility.sh @@ -1,9 +1,7 @@ #!/bin/bash set -euo pipefail -cd "$(git rev-parse --show-toplevel)" -npx playwright install --with-deps > /dev/null -cd tests/test-team +cd "$(git rev-parse --show-toplevel)/tests/test-team" TEST_EXIT_CODE=0 npm run test:accessibility || TEST_EXIT_CODE=$? echo "TEST_EXIT_CODE=$TEST_EXIT_CODE" diff --git a/scripts/tests/ui-component.sh b/scripts/tests/ui-component.sh index eb028b139d..39b2dbc5e7 100755 --- a/scripts/tests/ui-component.sh +++ b/scripts/tests/ui-component.sh @@ -1,9 +1,7 @@ #!/bin/bash set -euo pipefail -cd "$(git rev-parse --show-toplevel)" -npx playwright install --with-deps > /dev/null -cd tests/test-team +cd "$(git rev-parse --show-toplevel)/tests/test-team" TEST_EXIT_CODE=0 npm run test:component || TEST_EXIT_CODE=$? echo "TEST_EXIT_CODE=$TEST_EXIT_CODE" diff --git a/scripts/tests/ui-e2e.sh b/scripts/tests/ui-e2e.sh index a8e40b9480..14ddc9282b 100755 --- a/scripts/tests/ui-e2e.sh +++ b/scripts/tests/ui-e2e.sh @@ -1,9 +1,7 @@ #!/bin/bash set -euo pipefail -cd "$(git rev-parse --show-toplevel)" -npx playwright install --with-deps > /dev/null -cd tests/test-team +cd "$(git rev-parse --show-toplevel)/tests/test-team" TEST_EXIT_CODE=0 npm run test:e2e || TEST_EXIT_CODE=$? echo "TEST_EXIT_CODE=$TEST_EXIT_CODE" diff --git a/scripts/tests/ui-user-timeout.sh b/scripts/tests/ui-user-timeout.sh index 5aa840909c..a588b1c39a 100755 --- a/scripts/tests/ui-user-timeout.sh +++ b/scripts/tests/ui-user-timeout.sh @@ -1,9 +1,7 @@ #!/bin/bash set -euo pipefail -cd "$(git rev-parse --show-toplevel)" -npx playwright install --with-deps > /dev/null -cd tests/test-team +cd "$(git rev-parse --show-toplevel)/tests/test-team" TEST_EXIT_CODE=0 npm run test:user-timeout || TEST_EXIT_CODE=$? echo "TEST_EXIT_CODE=$TEST_EXIT_CODE" diff --git a/tests/test-team/config/accessibility/accessibility.config.ts b/tests/test-team/config/accessibility/accessibility.config.ts index 8b7291b954..d4446c1d4b 100644 --- a/tests/test-team/config/accessibility/accessibility.config.ts +++ b/tests/test-team/config/accessibility/accessibility.config.ts @@ -2,11 +2,6 @@ import path from 'node:path'; import { defineConfig, devices } from '@playwright/test'; import baseConfig from '../playwright.config'; -const buildCommand = [ - 'INCLUDE_AUTH_PAGES=true', - 'npm run build && npm run start', -].join(' '); - export default defineConfig({ ...baseConfig, fullyParallel: true, @@ -46,7 +41,7 @@ export default defineConfig({ /* Run your local dev server before starting the tests */ webServer: { timeout: 4 * 60 * 1000, // 4 minutes - command: buildCommand, + command: 'npm run start', cwd: path.resolve(__dirname, '../../../..'), url: 'http://localhost:3000/templates/create-and-submit-templates', reuseExistingServer: !process.env.CI, diff --git a/tests/test-team/config/api/api.setup.ts b/tests/test-team/config/api/api.setup.ts index 1d89bceade..fa00c77d72 100644 --- a/tests/test-team/config/api/api.setup.ts +++ b/tests/test-team/config/api/api.setup.ts @@ -4,6 +4,8 @@ import { BackendConfigHelper } from 'nhs-notify-web-template-management-util-bac import { getTestContext } from 'helpers/context/context'; setup('api test setup', async () => { + setup.setTimeout(60_000); + const backendConfig = BackendConfigHelper.fromTerraformOutputsFile( path.join(__dirname, '..', '..', '..', '..', 'sandbox_tf_outputs.json') ); diff --git a/tests/test-team/config/component/component.config.ts b/tests/test-team/config/component/component.config.ts index b8e6883298..b0ea81d550 100644 --- a/tests/test-team/config/component/component.config.ts +++ b/tests/test-team/config/component/component.config.ts @@ -2,11 +2,6 @@ import path from 'node:path'; import { defineConfig, devices } from '@playwright/test'; import baseConfig from '../playwright.config'; -const buildCommand = [ - 'INCLUDE_AUTH_PAGES=true', - 'npm run build && npm run start', -].join(' '); - export default defineConfig({ ...baseConfig, @@ -46,7 +41,7 @@ export default defineConfig({ /* Run your local dev server before starting the tests */ webServer: { timeout: 4 * 60 * 1000, // 4 minutes - command: buildCommand, + command: 'npm run start', cwd: path.resolve(__dirname, '../../../..'), url: 'http://localhost:3000/templates/create-and-submit-templates', reuseExistingServer: !process.env.CI, diff --git a/tests/test-team/config/e2e/e2e.config.ts b/tests/test-team/config/e2e/e2e.config.ts index 1f40fe915d..f2a61b8ba7 100644 --- a/tests/test-team/config/e2e/e2e.config.ts +++ b/tests/test-team/config/e2e/e2e.config.ts @@ -2,11 +2,6 @@ import path from 'node:path'; import { defineConfig, devices } from '@playwright/test'; import baseConfig from '../playwright.config'; -const buildCommand = [ - 'INCLUDE_AUTH_PAGES=true', - 'npm run build && npm run start', -].join(' '); - export default defineConfig({ ...baseConfig, fullyParallel: true, @@ -46,7 +41,7 @@ export default defineConfig({ /* Run your local dev server before starting the tests */ webServer: { timeout: 4 * 60 * 1000, // 4 minutes - command: buildCommand, + command: 'npm run start', cwd: path.resolve(__dirname, '../../../..'), url: 'http://localhost:3000/templates/create-and-submit-templates', reuseExistingServer: !process.env.CI, diff --git a/tests/test-team/config/user-timeout/user-timeout.config.ts b/tests/test-team/config/user-timeout/user-timeout.config.ts index bc3871d8da..b902e5827a 100644 --- a/tests/test-team/config/user-timeout/user-timeout.config.ts +++ b/tests/test-team/config/user-timeout/user-timeout.config.ts @@ -2,13 +2,6 @@ import path from 'node:path'; import { defineConfig, devices } from '@playwright/test'; import baseConfig from '../playwright.config'; -const buildCommand = [ - 'INCLUDE_AUTH_PAGES=true', - 'NEXT_PUBLIC_TIME_TILL_LOGOUT_SECONDS=25', - 'NEXT_PUBLIC_PROMPT_SECONDS_BEFORE_LOGOUT=5', - 'npm run build && npm run start', -].join(' '); - export default defineConfig({ ...baseConfig, @@ -50,7 +43,7 @@ export default defineConfig({ /* Run your local dev server before starting the tests */ webServer: { timeout: 4 * 60 * 1000, // 4 minutes - command: buildCommand, + command: 'npm run start', cwd: path.resolve(__dirname, '../../../..'), url: 'http://localhost:3000/templates/create-and-submit-templates', reuseExistingServer: !process.env.CI,