diff options
Diffstat (limited to 'packages/core/src/utils/getFolderStructure.test.ts')
| -rw-r--r-- | packages/core/src/utils/getFolderStructure.test.ts | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/packages/core/src/utils/getFolderStructure.test.ts b/packages/core/src/utils/getFolderStructure.test.ts index aecd35c5..b3e5b723 100644 --- a/packages/core/src/utils/getFolderStructure.test.ts +++ b/packages/core/src/utils/getFolderStructure.test.ts @@ -4,11 +4,13 @@ * SPDX-License-Identifier: Apache-2.0 */ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { describe, it, expect, vi, beforeEach, afterEach, Mock } from 'vitest'; import fsPromises from 'fs/promises'; import { Dirent as FSDirent } from 'fs'; import * as nodePath from 'path'; import { getFolderStructure } from './getFolderStructure.js'; +import * as gitUtils from './gitUtils.js'; vi.mock('path', async (importOriginal) => { const original = (await importOriginal()) as typeof nodePath; @@ -20,6 +22,7 @@ vi.mock('path', async (importOriginal) => { }); vi.mock('fs/promises'); +vi.mock('./gitUtils.js'); // Import 'path' again here, it will be the mocked version import * as path from 'path'; @@ -276,3 +279,61 @@ Showing up to 3 items (files + folders). expect(structure.trim()).toBe(expected); }); }); + +describe('getFolderStructure gitignore', () => { + beforeEach(() => { + vi.resetAllMocks(); + (path.resolve as Mock).mockImplementation((str: string) => str); + + (fsPromises.readdir as Mock).mockImplementation(async (p) => { + const path = p.toString(); + if (path === '/test/project') { + return [ + createDirent('file1.txt', 'file'), + createDirent('node_modules', 'dir'), + createDirent('ignored.txt', 'file'), + createDirent('.gemini', 'dir'), + ] as any; + } + if (path === '/test/project/node_modules') { + return [createDirent('some-package', 'dir')] as any; + } + if (path === '/test/project/.gemini') { + return [ + createDirent('config.yaml', 'file'), + createDirent('logs.json', 'file'), + ] as any; + } + return []; + }); + + (fsPromises.readFile as Mock).mockImplementation(async (p) => { + const path = p.toString(); + if (path === '/test/project/.gitignore') { + return 'ignored.txt\nnode_modules/\n.gemini/\n!/.gemini/config.yaml'; + } + return ''; + }); + + vi.mocked(gitUtils.isGitRepository).mockReturnValue(true); + }); + + it('should ignore files and folders specified in .gitignore', async () => { + const structure = await getFolderStructure('/test/project', { + projectRoot: '/test/project', + }); + expect(structure).not.toContain('ignored.txt'); + expect(structure).toContain('node_modules/...'); + expect(structure).not.toContain('logs.json'); + }); + + it('should not ignore files if respectGitIgnore is false', async () => { + const structure = await getFolderStructure('/test/project', { + projectRoot: '/test/project', + respectGitIgnore: false, + }); + expect(structure).toContain('ignored.txt'); + // node_modules is still ignored by default + expect(structure).toContain('node_modules/...'); + }); +}); |
