try try again - almost giving up
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 9m51s

This commit is contained in:
2025-12-06 14:54:28 -08:00
parent d941df6d7b
commit 59559c155d
2 changed files with 30 additions and 33 deletions

View File

@@ -24,7 +24,8 @@ const { mockGenerateContent, mockReadFile, mockToBuffer, mockExtract, mockSharp
// 2. Mock `fs` and `node:fs` using external object. Failed (hoisting issue).
// 3. Mock modules to return the HOISTED mock variables directly. Failed.
// 4. Inline mock definitions inside vi.mock factory. Failed (potentially due to complex object nesting).
// 5. Current Strategy: Use vi.fn() directly inside factory for GoogleGenAI and a unified factory for FS to ensure consistency.
// 5. Use vi.fn() directly inside factory. Failed (ReferenceError: Cannot access 'fsFactory' before initialization).
// 6. Current Strategy: Move fsFactory into vi.hoisted to ensure it exists before mocks are hoisted.
// 2. Mock the @google/genai SDK
vi.mock('@google/genai', () => {
@@ -38,11 +39,13 @@ vi.mock('@google/genai', () => {
});
// 3. Robust mock for file system operations
const fsFactory = () => ({
default: { readFile: mockReadFile },
readFile: mockReadFile,
promises: { readFile: mockReadFile }
});
const { fsFactory } = vi.hoisted(() => ({
fsFactory: () => ({
default: { readFile: mockReadFile },
readFile: mockReadFile,
promises: { readFile: mockReadFile }
})
}));
vi.mock('fs', fsFactory);
vi.mock('node:fs', fsFactory);

View File

@@ -5,28 +5,11 @@ import { describe, it, expect, vi, beforeEach, beforeAll, type Mock } from 'vite
// 2. Attempt: Hoisted spies attached to default export. Failed (0 calls).
// 3. Attempt: Function-as-object mock. Failed (TS error / 0 calls).
// 4. Attempt: Plain object mock. Failed (0 calls).
// 5. Current Strategy: Mock default export as a callable function with properties using Object.assign.
// 5. Attempt: Mock default export as a simple object using Object.assign. Failed (0 calls).
// 6. Current Strategy: Remove mock factory. Import real module and use vi.spyOn on the default export in the test body.
const { successSpy, errorSpy } = vi.hoisted(() => ({
successSpy: vi.fn(),
errorSpy: vi.fn(),
}));
vi.mock('../lib/toast', () => {
const toastFn = vi.fn();
// Assign properties to the function object itself to satisfy `toast.success` calls
Object.assign(toastFn, {
success: successSpy,
error: errorSpy,
});
return {
default: toastFn,
success: successSpy,
error: errorSpy,
__esModule: true,
};
});
// Remove the broken mock factory
vi.unmock('../lib/toast');
describe('Notification Service', () => {
beforeAll(() => {
@@ -60,13 +43,19 @@ describe('Notification Service', () => {
describe('notifySuccess', () => {
it('should call the injected toaster.success with correct options', async () => {
// Import the service
const { notifySuccess } = await import('./notificationService');
const message = 'Operation was successful!';
// 1. Import the dependency first
const toastModule = await import('../lib/toast');
const toast = toastModule.default;
// 2. Setup the spy BEFORE importing the service under test
const successSpy = vi.spyOn(toast, 'success').mockImplementation(() => 'id');
// 3. Import the service (which will use the spied toast object)
const { notifySuccess } = await import('./notificationService');
const message = 'Operation was successful!';
notifySuccess(message);
// Verify using the hoisted spy
expect(successSpy).toHaveBeenCalledTimes(1);
expect(successSpy).toHaveBeenCalledWith(
message,
@@ -83,9 +72,14 @@ describe('Notification Service', () => {
describe('notifyError', () => {
it('should call the injected toaster.error with correct options', async () => {
const { notifyError } = await import('./notificationService');
const message = 'Something went wrong!';
const toastModule = await import('../lib/toast');
const toast = toastModule.default;
const errorSpy = vi.spyOn(toast, 'error').mockImplementation(() => 'id');
const { notifyError } = await import('./notificationService');
const message = 'Something went wrong!';
notifyError(message);
expect(errorSpy).toHaveBeenCalledTimes(1);