Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tests): move e2e tests for consultation-portal to their app #17008

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
**/*.log
**/tmp/
**/temp/
**/.next/

# Outputs
**/dist/
Expand Down
111 changes: 85 additions & 26 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ jobs:

outputs:
TEST_CHUNKS: ${{ steps.test_projects.outputs.CHUNKS }}
E2E_CI_CHUNKS: ${{ steps.e2e_ci_projects.outputs.CHUNKS }}
E2E_CHUNKS: ${{ steps.e2e_projects.outputs.CHUNKS }}
E2E_CI_BUILD_ID: ${{ steps.e2e_ci_projects.outputs.BUILD_ID }}
E2E_BUILD_ID: ${{ steps.e2e_projects.outputs.BUILD_ID }}
LINT_CHUNKS: ${{ steps.lint_projects.outputs.CHUNKS }}
BUILD_CHUNKS: ${{ steps.build_projects.outputs.CHUNKS }}
Expand Down Expand Up @@ -141,13 +143,25 @@ jobs:
echo "CHUNKS={\"projects\":$CHUNKS}" >> "$GITHUB_OUTPUT"
fi

- name: Prepare e2e-ci targets
id: e2e_ci_projects
env:
CHUNK_SIZE: 1
run: |
set -euo pipefail
CHUNKS="$(./scripts/ci/generate-chunks.sh e2e-ci)"
if [[ "$CHUNKS" != "[]" ]]; then
echo "CHUNKS={\"projects\":$CHUNKS}" >> "$GITHUB_OUTPUT"
fi
echo BUILD_ID="$GITHUB_RUN_ID-$GITHUB_RUN_NUMBER-$(uuidgen)" >> "$GITHUB_OUTPUT"

- name: Prepare e2e targets
id: e2e_projects
env:
CHUNK_SIZE: 1
run: |
set -euo pipefail
CHUNKS="$(./scripts/ci/generate-chunks.sh e2e-ci)"
CHUNKS="$(./scripts/ci/generate-chunks.sh e2e)"
if [[ "$CHUNKS" != "[]" ]]; then
echo "CHUNKS={\"projects\":$CHUNKS}" >> "$GITHUB_OUTPUT"
fi
Expand All @@ -172,23 +186,71 @@ jobs:
set -euo pipefail
node -r esbuild-register .github/actions/check-team-approval.ts release-managers
tests:
if: false
runs-on: ec2-runners
steps:
- run: echo "This step won't run"
# needs:
# - prepare
# if: needs.prepare.outputs.TEST_CHUNKS
# runs-on: ec2-runners
# container:
# image: public.ecr.aws/m3u4c4h9/island-is/actions-runner-public:latest
# timeout-minutes: 45
# env:
# AFFECTED_PROJECTS: ${{ matrix.projects }}
# MAX_JOBS: 1
# strategy:
# fail-fast: false
# matrix: ${{ fromJson(needs.prepare.outputs.TEST_CHUNKS) }}
# steps:
# - uses: actions/checkout@v4
# with:
# fetch-depth: 0

# - uses: actions/setup-node@v4
# with:
# node-version-file: 'package.json'

# - name: Setup yarn
# run: corepack enable

# - name: Get cache
# id: get-cache
# uses: ./.github/actions/get-cache
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# keys: ${{ needs.prepare.outputs.CACHE_KEYS }}
# enable-cache: 'node_modules,cypress,generated-files'

# - uses: ./.github/actions/unit-test
# with:
# dd-api-key: '${{ secrets.DD_API_KEY }}'
# codecov-token: ${{ secrets.CODECOV_TOKEN }}
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# docker-registry: 821090935708.dkr.ecr.eu-west-1.amazonaws.com/

Comment on lines +189 to +233
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove commented-out code

Instead of keeping the commented-out test job configuration, consider removing it entirely since it's tracked in version control. If this code needs to be referenced later, it can be found in the git history.

🧰 Tools
🪛 actionlint (1.7.4)

190-190: label "ec2-runners" is unknown. available labels are "windows-latest", "windows-latest-8-cores", "windows-2022", "windows-2019", "ubuntu-latest", "ubuntu-latest-4-cores", "ubuntu-latest-8-cores", "ubuntu-latest-16-cores", "ubuntu-24.04", "ubuntu-22.04", "ubuntu-20.04", "macos-latest", "macos-latest-xl", "macos-latest-xlarge", "macos-latest-large", "macos-15-xlarge", "macos-15-large", "macos-15", "macos-14-xl", "macos-14-xlarge", "macos-14-large", "macos-14", "macos-13-xl", "macos-13-xlarge", "macos-13-large", "macos-13", "macos-12-xl", "macos-12-xlarge", "macos-12-large", "macos-12", "self-hosted", "x64", "arm", "arm64", "linux", "macos", "windows". if it is a custom label for self-hosted runner, set list of labels in actionlint.yaml config file

(runner-label)

e2e-ci:
needs:
- prepare
if: needs.prepare.outputs.TEST_CHUNKS
if: needs.prepare.outputs.E2E_CI_CHUNKS
runs-on: ec2-runners
container:
image: public.ecr.aws/m3u4c4h9/island-is/actions-runner-public:latest
timeout-minutes: 45
env:
AFFECTED_PROJECTS: ${{ matrix.projects }}
MAX_JOBS: 1
AFFECTED_PROJECT: ${{ matrix.projects }}
CYPRESS_PROJECT_ID: 4q7jz8
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
API_MOCKS: 'true'
NODE_OPTIONS: --max-old-space-size=4096
E2E_CI_BUILD_ID: '${{ needs.prepare.outputs.E2E_CI_BUILD_ID }}-${{ github.run_attempt }}'
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare.outputs.TEST_CHUNKS) }}
matrix: ${{ fromJson(needs.prepare.outputs.E2E_CI_CHUNKS) }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v4
with:
Expand All @@ -205,13 +267,8 @@ jobs:
keys: ${{ needs.prepare.outputs.CACHE_KEYS }}
enable-cache: 'node_modules,cypress,generated-files'

- uses: ./.github/actions/unit-test
with:
dd-api-key: '${{ secrets.DD_API_KEY }}'
codecov-token: ${{ secrets.CODECOV_TOKEN }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
docker-registry: 821090935708.dkr.ecr.eu-west-1.amazonaws.com/
- name: Running e2e tests
run: ./scripts/ci/40_e2e.sh "${AFFECTED_PROJECT}"

e2e:
needs:
Expand All @@ -220,12 +277,9 @@ jobs:
runs-on: ec2-runners
container:
image: public.ecr.aws/m3u4c4h9/island-is/actions-runner-public:latest
timeout-minutes: 45
timeout-minutes: 35
env:
AFFECTED_PROJECT: ${{ matrix.projects }}
CYPRESS_PROJECT_ID: 4q7jz8
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
API_MOCKS: 'true'
NODE_OPTIONS: --max-old-space-size=4096
E2E_BUILD_ID: '${{ needs.prepare.outputs.E2E_BUILD_ID }}-${{ github.run_attempt }}'
strategy:
Expand All @@ -241,16 +295,18 @@ jobs:
- name: Setup yarn
run: corepack enable

- name: Get cache
id: get-cache
uses: ./.github/actions/get-cache
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
keys: ${{ needs.prepare.outputs.CACHE_KEYS }}
enable-cache: 'node_modules,cypress,generated-files'
- name: Install Root Dependencies
run: yarn install --immutable

- name: Install Infra Dependencies
working-directory: infra
run: yarn install --immutable

- name: Running e2e tests
run: ./scripts/ci/40_e2e.sh "${AFFECTED_PROJECT}"
run: yarn e2e "${AFFECTED_PROJECT}"

- name: Stop and Clean Docker Compose
run: docker compose down

linting-workspace:
needs:
Expand Down Expand Up @@ -410,12 +466,15 @@ jobs:
- run-shellcheck
- formatting
- e2e
- e2e-ci
- build
steps:
- name: Check prepare success
run: '[[ ${{ needs.prepare.result }} == "success" ]] || exit 1'
- name: Check tests success
run: '[[ ${{ needs.tests.result }} != "failure" ]] || exit 1'
- name: Check e2e-ci success
run: '[[ ${{ needs.e2e-ci.result }} != "failure" ]] || exit 1'
- name: Check e2e success
run: '[[ ${{ needs.e2e.result }} != "failure" ]] || exit 1'
- name: Check linting success
Expand Down
87 changes: 87 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
ARG NODE_IMAGE_TAG=20.15.0-alpine3.20

# Stage 1: Install dependencies
FROM node:${NODE_IMAGE_TAG} AS dependencies

# Set working directory
WORKDIR /app

# Install Python3 and build tools
RUN apk add --no-cache python3 py3-pip make g++ && ln -sf /usr/bin/python3 /usr/bin/python

# Copy only package management files
COPY package.json yarn.lock ./
COPY .yarn/ .yarn
COPY .yarnrc.yml .yarnrc.yml
COPY ./apps/native/app/package.json ./apps/native/app/package.json

# Install dependencies
RUN --mount=type=cache,target=/app/.yarn/cache \
yarn install --immutable && yarn cache clean

# Stage 2: Final runtime image
FROM node:${NODE_IMAGE_TAG}

# Install Python (runtime requirement if needed)
RUN apk add --no-cache python3 py3-pip && ln -sf /usr/bin/python3 /usr/bin/python

# Enable Corepack and Yarn 3.2.3
RUN corepack enable && corepack prepare [email protected] --activate

# Set working directory
WORKDIR /app

# Copy from dependencies stage
COPY --from=dependencies /app/node_modules ./node_modules
COPY --from=dependencies /app/yarn.lock ./yarn.lock
COPY --from=dependencies /app/.yarn/ ./.yarn
COPY --from=dependencies /app/.yarnrc.yml ./.yarnrc.yml

# Copy source code and necessary configuration files
COPY ./apps ./apps
COPY ./libs ./libs
COPY ./infra ./infra
COPY ./tools ./tools
COPY ./tsconfig.base.json ./
COPY ./tsconfig.shared.json ./
COPY ./package.json ./

Comment on lines +23 to +48
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add security best practices

Consider enhancing the security of the final image:

  1. Run as non-root user
  2. Add HEALTHCHECK
  3. Set proper file permissions
 # Copy source code and necessary configuration files
 COPY ./apps ./apps
 COPY ./libs ./libs
 COPY ./infra ./infra
 COPY ./tools ./tools           
 COPY ./tsconfig.base.json ./   
 COPY ./tsconfig.shared.json ./      
 COPY ./package.json ./          
+
+# Create non-root user
+RUN addgroup -S appgroup && adduser -S appuser -G appgroup
+RUN chown -R appuser:appgroup /app
+USER appuser
+
+# Add healthcheck
+HEALTHCHECK --interval=30s --timeout=3s \
+  CMD wget --no-verbose --tries=1 --spider http://localhost:4200/samradsgatt || exit 1

Committable suggestion skipped: line range outside the PR's diff.

# Verify Yarn version in runtime container
RUN yarn --version

# Default command to run the app
CMD ["yarn", "nx", "serve"]

# ARG NODE_IMAGE_TAG=20.15.0-alpine3.20
# FROM node:${NODE_IMAGE_TAG} AS build

# WORKDIR /app

# # Install build dependencies
# RUN apk add --no-cache \
# python3 \
# py3-pip \
# make \
# g++

# # Set Python symlink
# RUN ln -sf /usr/bin/python3 /usr/bin/python

# # Install dependencies
# COPY package.json yarn.lock ./
# COPY .yarn/ .yarn
# COPY .yarnrc.yml .yarnrc.yml
# COPY ./apps/native/app/package.json ./apps/native/app/package.json

# # Run yarn install
# RUN --mount=type=cache,target=/app/.yarn/cache \
# yarn install --immutable

# # Copy source code
# COPY . .

# # Verify installation
# RUN yarn nx --version

# # Set default entrypoint
# CMD ["yarn", "nx"]
18 changes: 18 additions & 0 deletions apps/consultation-portal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ Login here https://island-is.awsapps.com/start#/ (Contact devops if you need acc
Copy env variables as instructed [here](https://docs.devland.is/technical-overview/devops/dockerizing#troubleshooting) (image arrows 1,2,3)
Paste env variables into terminal

## E2E Testing

### Quick Start

To run the E2E tests for the `consultation-portal` app:

```bash
# Install dependencies
yarn install && yarn codegen

# Start the server
yarn nx e2e consultation-portal
```
Comment on lines +74 to +84
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance the Quick Start guide with additional setup details.

The current instructions might be insufficient for first-time users. Consider adding:

  1. Prerequisites (e.g., required environment variables)
  2. Whether the API needs to be running
  3. Brief explanation of what the tests verify
  4. Common issues and troubleshooting steps

Here's a suggested enhancement:

 ### Quick Start
 
+Prerequisites:
+- Ensure you have the required environment variables (see Development section above)
+- The API should be running locally (follow steps 1-5 in the Development section)
+
 To run the E2E tests for the `consultation-portal` app:
 
 ```bash
 # Install dependencies
 yarn install && yarn codegen
 
 # Start the server
 yarn nx e2e consultation-portal

+These tests verify both authenticated and unauthenticated user flows in the consultation portal.
+
+#### Troubleshooting
+
+If the tests fail, ensure:
+- All environment variables are properly set
+- The API is running and accessible
+- You have the necessary permissions


<!-- This is an auto-generated comment by CodeRabbit -->


### More Resources

For further details, refer to the [E2E Testing Library README](../../libs/testing/e2e/README.md).

## Project owner

- [Stjórnarráðið](https://www.stjornarradid.is)
Expand Down
Loading
Loading