Skip to content

Commit

Permalink
test: fix Jest mocking syntax for CI environment
Browse files Browse the repository at this point in the history
Co-Authored-By: Michael Latman <[email protected]>
  • Loading branch information
devin-ai-integration[bot] and michaellatman committed Dec 12, 2024
1 parent 81ff0cb commit 3b04d9b
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions src/utils/__tests__/config-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,16 @@ import { Package } from '../../types/package';
import fs from 'fs';
import path from 'path';

// Mock fs and path modules
jest.mock('fs', () => ({
existsSync: jest.fn(),
readFileSync: jest.fn(),
writeFileSync: jest.fn()
}));

jest.mock('path', () => ({
dirname: jest.fn(),
join: jest.fn()
}));
// Mock modules
jest.mock('fs');
jest.mock('path');

describe('ConfigManager', () => {
beforeEach(() => {
jest.clearAllMocks();
jest.mocked(fs.existsSync).mockReturnValue(true);
jest.mocked(fs.readFileSync).mockReturnValue('{"mcpServers":{}}');
jest.mocked(path.dirname).mockReturnValue('/mock/path');
jest.spyOn(fs, 'existsSync').mockReturnValue(true);
jest.spyOn(fs, 'readFileSync').mockReturnValue('{"mcpServers":{}}');
jest.spyOn(path, 'dirname').mockReturnValue('/mock/path');
});

describe('installPackage', () => {
Expand All @@ -40,7 +32,7 @@ describe('ConfigManager', () => {
TEST_KEY: 'test-value'
};

const writeFileSpy = jest.mocked(fs.writeFileSync);
const writeFileSpy = jest.spyOn(fs, 'writeFileSync');

await ConfigManager.installPackage(mockPackage, mockEnvVars);

Expand All @@ -62,7 +54,8 @@ describe('ConfigManager', () => {
license: 'MIT'
};

const writeFileSpy = jest.mocked(fs.writeFileSync);
const writeFileSpy = jest.spyOn(fs, 'writeFileSync');

await ConfigManager.installPackage(mockPackage);

expect(writeFileSpy).toHaveBeenCalled();
Expand All @@ -82,7 +75,8 @@ describe('ConfigManager', () => {
license: 'MIT'
};

const writeFileSpy = jest.mocked(fs.writeFileSync);
const writeFileSpy = jest.spyOn(fs, 'writeFileSync');

await ConfigManager.installPackage(mockPackage);

expect(writeFileSpy).toHaveBeenCalled();
Expand All @@ -104,7 +98,8 @@ describe('ConfigManager', () => {
args: ['--arg1', '--arg2']
};

const writeFileSpy = jest.mocked(fs.writeFileSync);
const writeFileSpy = jest.spyOn(fs, 'writeFileSync');

await ConfigManager.installPackage(mockPackage);

expect(writeFileSpy).toHaveBeenCalled();
Expand Down

0 comments on commit 3b04d9b

Please sign in to comment.