update fixing the build of the app

This commit is contained in:
2026-06-16 07:59:38 +02:00
parent 6abee5f8b6
commit 299ae17d80
3 changed files with 70 additions and 22 deletions

40
test/search.test.ts Normal file
View File

@@ -0,0 +1,40 @@
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, describe, expect, it } from 'vitest'
import { simpleGit } from 'simple-git'
import { listFiles, rgAvailable, searchContent } from '../src/main/search-service'
let dir = ''
afterEach(async () => { if (dir) await rm(dir, { recursive: true, force: true }) })
describe('search-service (real ripgrep via dynamic import)', () => {
it('ripgrep is available (catches the ESM require() regression)', async () => {
expect(await rgAvailable()).toBe(true)
})
it('finds content matches with line number + column', async () => {
dir = await mkdtemp(join(tmpdir(), 'helder-search-'))
await simpleGit(dir).init()
await writeFile(join(dir, 'a.ts'), 'const x = 1\nconst balance = 2\n')
await writeFile(join(dir, 'b.ts'), 'nothing relevant\n')
const groups = await searchContent(dir, 'balance')
expect(groups).toHaveLength(1)
expect(groups[0].path).toBe('a.ts')
expect(groups[0].hits[0].no).toBe(2)
expect(groups[0].hits[0].ln).toContain('balance')
expect(groups[0].hits[0].ix).toBe('const '.length)
})
it('returns [] for queries under 2 characters', async () => {
dir = await mkdtemp(join(tmpdir(), 'helder-search-'))
expect(await searchContent(dir, 'a')).toEqual([])
})
it('lists project files', async () => {
dir = await mkdtemp(join(tmpdir(), 'helder-search-'))
await simpleGit(dir).init()
await writeFile(join(dir, 'keep.ts'), 'x')
expect(await listFiles(dir)).toContain('keep.ts')
})
})