fix unit test

This commit is contained in:
duanfuxiang 2025-01-07 14:47:40 +08:00
parent 6f66e548aa
commit d461e231f0
2 changed files with 11 additions and 2 deletions

View File

@ -233,7 +233,7 @@ export function parseInfioSettings(data: unknown): InfioSettings {
const migratedData = migrateSettings(data as Record<string, unknown>) const migratedData = migrateSettings(data as Record<string, unknown>)
return InfioSettingsSchema.parse(migratedData) return InfioSettingsSchema.parse(migratedData)
} catch (error) { } catch (error) {
console.warn('Invalid settings provided, using defaults:', error) // console.warn('Invalid settings provided, using defaults:', error)
return InfioSettingsSchema.parse({ ...DEFAULT_AUTOCOMPLETE_SETTINGS }) return InfioSettingsSchema.parse({ ...DEFAULT_AUTOCOMPLETE_SETTINGS })
} }
} }

View File

@ -12,6 +12,15 @@ describe('calculateFileDistance', () => {
} }
} }
// Mock TFolder class
class MockTFolder extends TFolder {
path: string
constructor(path: string) {
super()
this.path = path
}
}
it('should calculate the correct distance between files in the same folder', () => { it('should calculate the correct distance between files in the same folder', () => {
const file1 = new MockTFile('folder/file1.md') const file1 = new MockTFile('folder/file1.md')
const file2 = new MockTFile('folder/file2.md') const file2 = new MockTFile('folder/file2.md')
@ -53,7 +62,7 @@ describe('calculateFileDistance', () => {
it('should calculate the correct distance between a folder and a file', () => { it('should calculate the correct distance between a folder and a file', () => {
const file = new MockTFile('folder1/folder2/file1.md') const file = new MockTFile('folder1/folder2/file1.md')
const folder = new MockTFile('folder1/folder2') const folder = new MockTFolder('folder1/folder2')
if (!(folder instanceof TFolder)) { if (!(folder instanceof TFolder)) {
throw new Error('Expected folder to be a TFolder instance') throw new Error('Expected folder to be a TFolder instance')
} }