From 95351541285ecc882661f4eb071cf011e0f55a1e Mon Sep 17 00:00:00 2001 From: Meier Lukas Date: Tue, 5 Nov 2024 21:11:14 +0100 Subject: [PATCH] ci: add e2e workflow (#1422) * ci: add e2e workflow * fix: skip showing error * fix: when e2e skipped, e2e still executed * fix: job env not accessible in if * fix: env not accessible at all in job if statement * fix: wrong env used for step ifs * ci: add reusable e2e-execution workflow * fix: e2e trigger fails not supported reusable workflow within steps * fix: composite e2e-execution action not found * fix: reference to composite action not working without checkout * fix: composite action has to be named action.yml * fix: id for docker should not have spaces * fix: shell property missing * fix: typo one dash to much * ci: add e2e tests * chore: change node-version to 22 * chore: move e2e tests to code-quality workflow as duration of e2e step is about 4 minutes * fix: deepsource issues --- .github/workflows/code-quality.yml | 28 ++++++++++++++++++++++++--- e2e/health-checks.spec.ts | 18 +++++++++++++++++ e2e/home.spec.ts | 16 +++++++++++++++ e2e/shared/create-homarr-container.ts | 14 ++++++++++++++ package.json | 7 ++++--- tsconfig.e2e.json | 8 ++++++++ 6 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 e2e/health-checks.spec.ts create mode 100644 e2e/home.spec.ts create mode 100644 e2e/shared/create-homarr-container.ts create mode 100644 tsconfig.e2e.json diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index a75c144b7..bed3d53b6 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -67,11 +67,33 @@ jobs: - name: Test run: pnpm test - - name: 'Report Coverage' + - name: "Report Coverage" # Set if: always() to also generate the report if tests are failing # Only works if you set `reportOnFailure: true` in your vite config as specified above - if: always() - uses: davelosert/vitest-coverage-report-action@v2 + if: always() + uses: davelosert/vitest-coverage-report-action@v2 + + e2e: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Setup + uses: ./tooling/github/setup + - name: Build docker image + id: build-docker-image + uses: docker/build-push-action@v6 + with: + platforms: linux/amd64 + context: . + push: false + tags: homarr-e2e + network: host + env: + SKIP_ENV_VALIDATION: true + - name: Run E2E Tests + shell: bash + run: pnpm test:e2e build: runs-on: ubuntu-latest diff --git a/e2e/health-checks.spec.ts b/e2e/health-checks.spec.ts new file mode 100644 index 000000000..24fd26c91 --- /dev/null +++ b/e2e/health-checks.spec.ts @@ -0,0 +1,18 @@ +import { describe, expect, test } from "vitest"; + +import { createHomarrContainer } from "./shared/create-homarr-container"; + +describe("Health checks", () => { + test("ready and live should return 200 OK", async () => { + // Arrange + const homarrContainer = await createHomarrContainer().start(); + + // Act + const readyResponse = await fetch(`http://localhost:${homarrContainer.getMappedPort(7575)}/api/health/ready`); + const liveResponse = await fetch(`http://localhost:${homarrContainer.getMappedPort(7575)}/api/health/live`); + + // Assert + expect(readyResponse.status).toBe(200); + expect(liveResponse.status).toBe(200); + }, 20_000); +}); diff --git a/e2e/home.spec.ts b/e2e/home.spec.ts new file mode 100644 index 000000000..e8550a3eb --- /dev/null +++ b/e2e/home.spec.ts @@ -0,0 +1,16 @@ +import { describe, expect, test } from "vitest"; + +import { createHomarrContainer } from "./shared/create-homarr-container"; + +describe("Home", () => { + test("should open with status code 200", async () => { + // Arrange + const homarrContainer = await createHomarrContainer().start(); + + // Act + const homeResponse = await fetch(`http://localhost:${homarrContainer.getMappedPort(7575)}/`); + + // Assert + expect(homeResponse.status).toBe(200); + }, 20_000); +}); diff --git a/e2e/shared/create-homarr-container.ts b/e2e/shared/create-homarr-container.ts new file mode 100644 index 000000000..84cbcc711 --- /dev/null +++ b/e2e/shared/create-homarr-container.ts @@ -0,0 +1,14 @@ +import { GenericContainer, Wait } from "testcontainers"; + +export const createHomarrContainer = () => { + if (!process.env.CI) { + throw new Error("This test should only be run in CI or with a homarr image named 'homarr-e2e'"); + } + + return new GenericContainer("homarr-e2e") + .withEnvironment({ + AUTH_SECRET: "secret", + }) + .withExposedPorts(7575) + .withWaitStrategy(Wait.forHttp("/api/health/ready", 7575)); +}; diff --git a/package.json b/package.json index 4a4782735..7591dad46 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,9 @@ "lint": "turbo lint --continue -- --cache --cache-location node_modules/.cache/.eslintcache", "lint:fix": "turbo lint --continue -- --fix --cache --cache-location node_modules/.cache/.eslintcache", "lint:ws": "pnpm dlx sherif@latest", - "test": "cross-env NODE_ENV=development vitest run --coverage.enabled", - "test:ui": "cross-env NODE_ENV=development vitest --ui --coverage.enabled", + "test": "cross-env NODE_ENV=development vitest run --exclude e2e --coverage.enabled ", + "test:e2e": "cross-env NODE_ENV=development vitest e2e", + "test:ui": "cross-env NODE_ENV=development vitest --exclude e2e --ui --coverage.enabled", "typecheck": "turbo typecheck", "with-env": "dotenv -e .env --" }, @@ -49,4 +50,4 @@ "trpc-swagger@1.2.6": "patches/trpc-swagger@1.2.6.patch" } } -} \ No newline at end of file +} diff --git a/tsconfig.e2e.json b/tsconfig.e2e.json new file mode 100644 index 000000000..a579361f9 --- /dev/null +++ b/tsconfig.e2e.json @@ -0,0 +1,8 @@ +{ + "extends": "@homarr/tsconfig/base.json", + "compilerOptions": { + "tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json" + }, + "include": ["e2e"], + "exclude": ["node_modules"] +}