we went to mocks - now going to unit-setup.ts - centralized
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Has been cancelled

This commit is contained in:
2025-11-26 15:59:06 -08:00
parent d528a63bc3
commit d119e2a65c
4 changed files with 21 additions and 16 deletions

View File

@@ -95,7 +95,7 @@ jobs:
# --- Increase Node.js memory limit to prevent heap out of memory errors ---
# This is crucial for memory-intensive tasks like running tests and coverage.
NODE_OPTIONS: "--max-old-space-size=4096"
NODE_OPTIONS: "--max-old-space-size=8192"
run: |
# Fail-fast check to ensure secrets are configured in Gitea for testing.

View File

@@ -112,16 +112,18 @@ describe('WatchedItemsList (in shopping feature)', () => {
const itemsAsc = screen.getAllByRole('listitem');
expect(itemsAsc[0]).toHaveTextContent('Apples');
expect(itemsAsc[1]).toHaveTextContent('Bread');
expect(itemsAsc[2]).toHaveTextContent('Milk');
expect(itemsAsc[1]).toHaveTextContent('Bread'); // This was a duplicate, fixed.
expect(itemsAsc[2]).toHaveTextContent('Eggs');
expect(itemsAsc[3]).toHaveTextContent('Milk');
// Click to sort descending
fireEvent.click(sortButton);
const itemsDesc = screen.getAllByRole('listitem');
expect(itemsDesc[0]).toHaveTextContent('Milk');
expect(itemsDesc[1]).toHaveTextContent('Bread');
expect(itemsDesc[2]).toHaveTextContent('Apples');
expect(itemsDesc[1]).toHaveTextContent('Eggs');
expect(itemsDesc[2]).toHaveTextContent('Bread');
expect(itemsDesc[3]).toHaveTextContent('Apples');
});
it('should call onAddItemToList when plus icon is clicked', () => {

View File

@@ -1,6 +1,6 @@
// src/components/ProfileManager.test.tsx
import React from 'react';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { render, screen, fireEvent, waitFor, cleanup } from '@testing-library/react';
import { describe, it, expect, vi, beforeEach, type Mock } from 'vitest';
import { ProfileManager } from './ProfileManager';
import * as apiClient from '../../../services/apiClient';
@@ -364,7 +364,7 @@ const authenticatedProps = {
describe('ProfileManager Authenticated User Features', () => {
// Restore all spies after each test to ensure isolation
afterEach(() => {
vi.afterEach(() => {
vi.restoreAllMocks();
cleanup();
});

View File

@@ -27,6 +27,7 @@ describe('SystemCheck', () => {
beforeEach(() => {
vi.clearAllMocks();
// Reset API client mocks to resolve successfully by default.
mockedApiClient.pingBackend.mockResolvedValue(new Response('pong'));
mockedApiClient.checkStorage.mockResolvedValue(new Response(JSON.stringify({ success: true, message: 'Storage OK' })));
mockedApiClient.checkDbPoolHealth.mockResolvedValue(new Response(JSON.stringify({ success: true, message: 'DB Pool OK' })));
mockedApiClient.checkPm2Status.mockResolvedValue(new Response(JSON.stringify({ success: true, message: 'PM2 OK' })));
@@ -36,6 +37,11 @@ describe('SystemCheck', () => {
import.meta.env.VITE_API_KEY = originalViteApiKey;
});
// Restore all mocks after each test to ensure test isolation.
afterEach(() => {
vi.restoreAllMocks();
});
// Helper to set VITE_API_KEY
const setViteApiKey = (value: string | undefined) => {
import.meta.env.VITE_API_KEY = value;
@@ -68,19 +74,16 @@ describe('SystemCheck', () => {
});
it('should show API key as failed if VITE_API_KEY is not set', async () => {
// The most reliable way to test this is to mock the implementation of the check itself.
// Directly modifying import.meta.env can be flaky in test environments.
vi.spyOn(apiClient, 'pingBackend').mockImplementation(async () => {
// This check is synchronous in the component, but we can simulate its failure
// by throwing an error here, which prevents subsequent checks from running.
throw new Error('VITE_API_KEY is missing. Please add it to your .env file.');
});
// Set the API key to be undefined for this test.
setViteApiKey(undefined);
render(<SystemCheck />);
// The component will catch the error and display it.
// The component should synchronously detect the missing key and display an error.
// Subsequent async checks will be skipped.
await waitFor(() => {
expect(screen.getByText('VITE_API_KEY is missing. Please add it to your .env file.')).toBeInTheDocument();
// Verify that dependent checks are skipped.
expect(screen.getAllByText('Skipped: API key is not configured.').length).toBe(6);
});
});