Improvements to apply_diff (#52)

This commit is contained in:
Matt Rubens
2024-12-08 10:51:40 -05:00
committed by GitHub
parent 23486f1d3a
commit c0b070e6f0
10 changed files with 159 additions and 48 deletions

View File

@@ -76,6 +76,15 @@ jest.mock('../../Cline', () => {
}
})
// Mock extract-text
jest.mock('../../../integrations/misc/extract-text', () => ({
extractTextFromFile: jest.fn().mockImplementation(async (filePath: string) => {
const content = 'const x = 1;\nconst y = 2;\nconst z = 3;'
const lines = content.split('\n')
return lines.map((line, index) => `${index + 1} | ${line}`).join('\n')
})
}))
// Spy on console.error and console.log to suppress expected messages
beforeAll(() => {
jest.spyOn(console, 'error').mockImplementation(() => {})
@@ -258,4 +267,10 @@ describe('ClineProvider', () => {
expect(mockContext.globalState.update).toHaveBeenCalledWith('soundEnabled', false)
expect(mockPostMessage).toHaveBeenCalled()
})
test('file content includes line numbers', async () => {
const { extractTextFromFile } = require('../../../integrations/misc/extract-text')
const result = await extractTextFromFile('test.js')
expect(result).toBe('1 | const x = 1;\n2 | const y = 2;\n3 | const z = 3;')
})
})