0d3cb498a3
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled
122 lines
3.7 KiB
TypeScript
122 lines
3.7 KiB
TypeScript
// Shared mock setup and lifecycle hooks for all HTTP provider test files.
|
|
import { afterAll, afterEach, beforeEach, vi } from 'vitest';
|
|
import { fetchWithCache } from '../../../src/cache';
|
|
import { runPython } from '../../../src/python/pythonUtils';
|
|
import { maybeLoadConfigFromExternalFile, maybeLoadFromExternalFile } from '../../../src/util/file';
|
|
import { functionCache } from '../../../src/util/functions/loadFunction';
|
|
|
|
// Mock console.warn to prevent test noise
|
|
const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(function () {});
|
|
|
|
vi.mock('../../../src/cache', async () => {
|
|
const actual = await vi.importActual<typeof import('../../../src/cache')>('../../../src/cache');
|
|
return {
|
|
...actual,
|
|
fetchWithCache: vi.fn(),
|
|
};
|
|
});
|
|
|
|
vi.mock('../../../src/util/fetch/index.ts', async () => {
|
|
const actual = await vi.importActual<typeof import('../../../src/util/fetch/index.ts')>(
|
|
'../../../src/util/fetch/index.ts',
|
|
);
|
|
return {
|
|
...actual,
|
|
fetchWithRetries: vi.fn(),
|
|
fetchWithTimeout: vi.fn(),
|
|
};
|
|
});
|
|
|
|
vi.mock('../../../src/util/file', async () => {
|
|
const actual =
|
|
await vi.importActual<typeof import('../../../src/util/file')>('../../../src/util/file');
|
|
return {
|
|
...actual,
|
|
maybeLoadFromExternalFile: vi.fn((input) => input),
|
|
maybeLoadConfigFromExternalFile: vi.fn((input) => input),
|
|
};
|
|
});
|
|
|
|
vi.mock('../../../src/esm', async (importOriginal) => {
|
|
return {
|
|
...(await importOriginal()),
|
|
|
|
importModule: vi.fn(async (_modulePath: string, functionName?: string) => {
|
|
const mockModule: Record<string, ReturnType<typeof vi.fn>> = {
|
|
default: vi.fn((data) => data.defaultField),
|
|
parseResponse: vi.fn((data) => data.specificField),
|
|
};
|
|
if (functionName) {
|
|
if (!(functionName in mockModule)) {
|
|
throw new Error(
|
|
`importModule mock: unexpected functionName "${functionName}". ` +
|
|
'Add it to the mockModule in setup.ts or use mockResolvedValueOnce.',
|
|
);
|
|
}
|
|
return mockModule[functionName];
|
|
}
|
|
return mockModule.default;
|
|
}),
|
|
};
|
|
});
|
|
|
|
vi.mock('../../../src/cliState', async () => {
|
|
const actual =
|
|
await vi.importActual<typeof import('../../../src/cliState')>('../../../src/cliState');
|
|
const mockState = { basePath: '/mock/base/path', config: {} };
|
|
return {
|
|
...actual,
|
|
...mockState,
|
|
default: mockState,
|
|
};
|
|
});
|
|
|
|
vi.mock('../../../src/python/pythonUtils', async () => {
|
|
const actual = await vi.importActual<typeof import('../../../src/python/pythonUtils')>(
|
|
'../../../src/python/pythonUtils',
|
|
);
|
|
return {
|
|
...actual,
|
|
runPython: vi.fn(),
|
|
};
|
|
});
|
|
|
|
// Mock jks-js module for JKS keystore tests in auth.test.ts - don't use importOriginal as the native module may fail to load
|
|
vi.mock('jks-js', () => ({
|
|
toPem: vi.fn(),
|
|
default: {
|
|
toPem: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
afterAll(() => {
|
|
consoleSpy.mockRestore();
|
|
});
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
vi.mocked(fetchWithCache).mockReset();
|
|
vi.mocked(maybeLoadFromExternalFile).mockReset();
|
|
vi.mocked(maybeLoadConfigFromExternalFile).mockReset();
|
|
vi.mocked(runPython).mockReset();
|
|
vi.mocked(fetchWithCache).mockImplementation(() => {
|
|
throw new Error(
|
|
'fetchWithCache called without mockResolvedValueOnce setup. ' +
|
|
'Add vi.mocked(fetchWithCache).mockResolvedValueOnce({...}) before calling provider.callApi().',
|
|
);
|
|
});
|
|
vi.mocked(maybeLoadFromExternalFile).mockImplementation(function (input: unknown) {
|
|
return input;
|
|
});
|
|
vi.mocked(maybeLoadConfigFromExternalFile).mockImplementation(function (input: unknown) {
|
|
return input;
|
|
});
|
|
Object.keys(functionCache).forEach((key) => {
|
|
delete functionCache[key];
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.resetAllMocks();
|
|
});
|