diff --git a/.github/workflows/basic-workflow.yml b/.github/workflows/basic-workflow.yml index 2d13fe9..92884f1 100644 --- a/.github/workflows/basic-workflow.yml +++ b/.github/workflows/basic-workflow.yml @@ -39,7 +39,7 @@ jobs: - name: Run Client Unit Tests with Coverage working-directory: frontend - run: npm run test:coverage + run: npm run test:unit-coverage # Backend steps diff --git a/.github/workflows/complete-workflow.yml b/.github/workflows/complete-workflow.yml index 6d2ab30..a68deec 100644 --- a/.github/workflows/complete-workflow.yml +++ b/.github/workflows/complete-workflow.yml @@ -19,9 +19,25 @@ jobs: run: working-directory: backend/pcmod + services: + mysql: + image: mysql:8.0 + env: + MYSQL_DATABASE: pcmod + MYSQL_ROOT_PASSWORD: password + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=5 + steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up JDK 25 uses: actions/setup-java@v4 @@ -30,25 +46,45 @@ jobs: distribution: 'temurin' cache: 'maven' - - name: Server Unit Tests (Services + Mocks) - run: ./mvnw test -Dgroups="server-unit" - - - name: Server Integration Tests (Services + Testcontainers) - run: ./mvnw test -Dgroups="server-integration" + - name: Server Tests (JUnit, Testcontainers, Rest Assured) + env: + DB_URL: jdbc:mysql://localhost:3306/pcmod + DB_USERNAME: root + DB_PASSWORD: password + run: ./mvnw verify '-Dtest=!es.codeurjcstudents.pcmod.e2e.ui.**' - - name: Server System Tests (API REST with Rest Assured) - run: ./mvnw test -Dgroups="server-system" + - name: Save JaCoCo Report + uses: actions/upload-artifact@v4 + with: + name: jacoco-report + path: backend/pcmod/target/site/jacoco/jacoco.xml client-tests: - name: Frontend Unit Tests (Virtual DOM / Vitest) + name: Frontend Unit and Integration Tests (Virtual DOM / Vitest) runs-on: ubuntu-latest defaults: run: working-directory: frontend + services: + mysql: + image: mysql:8.0 + env: + MYSQL_DATABASE: pcmod + MYSQL_ROOT_PASSWORD: password + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=5 + steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up Node.js uses: actions/setup-node@v4 @@ -60,17 +96,59 @@ jobs: - name: Install dependencies run: npm ci - - name: Client Unit Tests (Components + Virtual DOM) - run: npm run test:unit + - name: Set up JDK 25 + uses: actions/setup-java@v4 + with: + java-version: '25' + distribution: 'temurin' + cache: 'maven' + + - name: Run backend and Client Unit and Integration Tests (Virtual DOM / Vitest) + env: + HEADLESS_TESTS: "true" + NODE_TLS_REJECT_UNAUTHORIZED: "0" + DB_URL: jdbc:mysql://localhost:3306/pcmod + DB_USERNAME: root + DB_PASSWORD: password + run: | + cd ../backend/pcmod + ./mvnw spring-boot:run > /dev/null 2>&1 < /dev/null & + + npx wait-on https-get://localhost:8443/api/v1/components/ + + cd ../../frontend + npm run test:coverage + + - name: Save LCOV Report + uses: actions/upload-artifact@v4 + with: + name: lcov-report + path: frontend/coverage/lcov.info - client-server-integration-tests: - name: E2E & Integration (Chrome + Selenium) + client-server-tests: + name: E2E Client-Server Tests (Chrome + Selenium) runs-on: ubuntu-latest needs: [server-tests, client-tests] + services: + mysql: + image: mysql:8.0 + env: + MYSQL_DATABASE: pcmod + MYSQL_ROOT_PASSWORD: password + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=5 + steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up JDK 25 uses: actions/setup-java@v4 @@ -86,22 +164,50 @@ jobs: cache: 'npm' cache-dependency-path: frontend/package-lock.json + - name: Install dependencies + run: npm ci + working-directory: frontend + - name: Set up Chrome for Selenium uses: browser-actions/setup-chrome@v1 with: chrome-version: stable - - name: Prepare and Launch Full Environment + - name: E2E Client-Server Tests (Selenium) env: HEADLESS_TESTS: "true" NODE_TLS_REJECT_UNAUTHORIZED: "0" + DB_URL: jdbc:mysql://localhost:3306/pcmod + DB_USERNAME: root + DB_PASSWORD: password run: | cd frontend - npm run dev & + npm run dev > /dev/null 2>&1 < /dev/null & cd ../backend/pcmod - ./mvnw spring-boot:run & + ./mvnw spring-boot:run > /dev/null 2>&1 < /dev/null & - npx wait-on http-get://localhost:5173 https-get://localhost:8443/ + npx wait-on http-get://localhost:5173 https-get://localhost:8443/api/v1/components/ - ./mvnw test -Dgroups="client-server-integration,client-system" \ No newline at end of file + ./mvnw test -Dgroups="client-system" + + # SonarCloud Analysis + - name: Download JaCoCo Report + uses: actions/download-artifact@v4 + with: + name: jacoco-report + path: backend/pcmod/target/site/jacoco + + - name: Download LCOV Report + uses: actions/download-artifact@v4 + with: + name: lcov-report + path: frontend/coverage + + - name: SonarCloud Analysis + uses: sonarsource/sonarcloud-github-action@v3.1.0 + with: + projectBaseDir: . + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/backend/pcmod/src/main/resources/application.properties b/backend/pcmod/src/main/resources/application.properties index fd601b7..7633fb9 100644 --- a/backend/pcmod/src/main/resources/application.properties +++ b/backend/pcmod/src/main/resources/application.properties @@ -7,10 +7,10 @@ server.ssl.key-store-password=password server.ssl.key-password=secret server.ssl.key-alias=selfsigned -spring.datasource.url=${DB_URL} -spring.datasource.username=${DB_USERNAME} -spring.datasource.password=${DB_PASSWORD} -spring.jpa.hibernate.ddl-auto=${DB_MODE} +spring.datasource.url=${DB_URL:jdbc:mysql://localhost:3306/pcmod} +spring.datasource.username=${DB_USERNAME:root} +spring.datasource.password=${DB_PASSWORD:password} +spring.jpa.hibernate.ddl-auto=${DB_MODE:create-drop} spring.servlet.encoding.charset=UTF-8 spring.servlet.encoding.enabled=true diff --git a/backend/pcmod/src/test/java/es/codeurjcstudents/pcmod/e2e/ui/ComponentsSystemTests.java b/backend/pcmod/src/test/java/es/codeurjcstudents/pcmod/e2e/ui/ComponentsSystemTests.java index 58e1785..b59c0b9 100644 --- a/backend/pcmod/src/test/java/es/codeurjcstudents/pcmod/e2e/ui/ComponentsSystemTests.java +++ b/backend/pcmod/src/test/java/es/codeurjcstudents/pcmod/e2e/ui/ComponentsSystemTests.java @@ -12,6 +12,7 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; @@ -24,7 +25,15 @@ public class ComponentsSystemTests { @BeforeEach public void setupTest() { - driver = new ChromeDriver(); + ChromeOptions options = new ChromeOptions(); + options.addArguments("--incognito"); + options.addArguments("--disable-notifications"); + options.addArguments("--disable-features=PasswordLeakDetection"); + options.addArguments("--headless"); + options.addArguments("--no-sandbox"); + options.addArguments("--disable-dev-shm-usage"); + + driver = new ChromeDriver(options); wait = new WebDriverWait(driver, Duration.ofSeconds(10)); } diff --git a/frontend/package.json b/frontend/package.json index 5b841f1..4d096c4 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -8,9 +8,8 @@ "start": "react-router-serve ./build/server/index.js", "typecheck": "react-router typegen && tsc", "test": "vitest", - "test:unit": "vitest run tests/unit", - "test:integration": "vitest run tests/integration", - "test:coverage": "vitest run tests/unit --coverage" + "test:unit-coverage": "vitest run tests/unit --coverage", + "test:coverage": "vitest run tests/ --coverage" }, "dependencies": { "@react-router/node": "8.0.0",