diff --git a/.github/workflows/frontend-tests.yaml b/.github/workflows/frontend-tests.yaml
index 7a123ca..df7a9f6 100644
--- a/.github/workflows/frontend-tests.yaml
+++ b/.github/workflows/frontend-tests.yaml
@@ -4,17 +4,23 @@ on:
workflow_dispatch:
push:
branches: ["main"]
+ paths:
+ - "frontend/**"
pull_request:
branches: ["main"]
+ paths:
+ - "frontend/**"
concurrency:
- group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }}
- cancel-in-progress: true
+ group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }}
+ cancel-in-progress: true
+
env:
- FORCE_COLOR: "1"
+ FORCE_COLOR: "1"
+
jobs:
frontend_tests:
- if: '! github.event.pull_request.draft'
+ if: "! github.event.pull_request.draft"
runs-on: ubuntu-latest
name: Frontend Tests
strategy:
@@ -23,34 +29,30 @@ jobs:
steps:
- uses: actions/checkout@v4
+
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- - name: Cache node modules
- id: cache-npm
- uses: actions/cache@v4
- env:
- cache-name: cache-node-modules
- with:
- path: ~/.npm
- key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/frontend/package-lock.json') }}
- restore-keys: |
- ${{ runner.os }}-build-${{ env.cache-name }}-
- ${{ runner.os }}-build-
- ${{ runner.os }}-
+ cache: "npm"
+ cache-dependency-path: frontend/package-lock.json
+
- name: Install dependencies
working-directory: ./frontend
- run: npm ci
+ run: npm install
+
- name: Run tests with coverage
working-directory: ./frontend
run: CI=true npm run test -- --coverage .
+
- name: Git fetch unshallow
- run: |
- git fetch --unshallow
+ if: ${{ github.actor != 'dependabot[bot]' }}
+ run: git fetch --unshallow
+
- name: UI SonarCloud Scan
- uses: SonarSource/sonarcloud-github-action@master
+ uses: SonarSource/sonarcloud-github-action@v3
if: ${{ github.actor != 'dependabot[bot]' }}
+ continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
diff --git a/frontend/sonar-project.properties b/frontend/sonar-project.properties
index 3d49a33..1e89994 100644
--- a/frontend/sonar-project.properties
+++ b/frontend/sonar-project.properties
@@ -1,4 +1,4 @@
-sonar.projectKey=zipstack_visitran_ui
+sonar.projectKey=Zipstack_visitran
sonar.organization=zipstack
sonar.language=js
sonar.javascript.file.suffixes=.js,.jsx
diff --git a/frontend/src/ide/explorer/__tests__/explorer.test.js b/frontend/src/ide/explorer/__tests__/explorer.test.js
index a8f1818..d6635ed 100644
--- a/frontend/src/ide/explorer/__tests__/explorer.test.js
+++ b/frontend/src/ide/explorer/__tests__/explorer.test.js
@@ -1,10 +1,32 @@
import { render, screen } from "@testing-library/react";
+import "@testing-library/jest-dom";
+import { ErrorBoundary } from "../../../widgets/error_boundary";
-import "../../../setupTests";
-import { App } from "../../../app.jsx";
+describe("ErrorBoundary", () => {
+ test("renders children when no error occurs", () => {
+ render(
+ {}}>
+ Test Content
+
+ );
+ expect(screen.getByText("Test Content")).toBeInTheDocument();
+ });
-test("dummy test case to work with sonar", () => {
- render();
- const linkElement = screen.getByText(/Visitran/i);
- expect(linkElement).toBeInTheDocument();
+ test("renders fallback when child throws", () => {
+ const ThrowError = () => {
+ throw new Error("Test error");
+ };
+ // Suppress console.error for expected error
+ const spy = jest.spyOn(console, "error").mockImplementation(() => {});
+ render(
+ {}}
+ fallbackComponent={Error occurred
}
+ >
+
+
+ );
+ expect(screen.getByText("Error occurred")).toBeInTheDocument();
+ spy.mockRestore();
+ });
});