diff --git a/packages/bruno-electron/src/app/dotenv-watcher.js b/packages/bruno-electron/src/app/dotenv-watcher.js index aef09e6a7..e504b75d2 100644 --- a/packages/bruno-electron/src/app/dotenv-watcher.js +++ b/packages/bruno-electron/src/app/dotenv-watcher.js @@ -100,10 +100,9 @@ class DotEnvWatcher { this.collectionWatchers.get(collectionPath).close(); } - const dotEnvPattern = path.join(collectionPath, '.env*'); - - const watcher = chokidar.watch(dotEnvPattern, { + const watcher = chokidar.watch(collectionPath, { ...DEFAULT_WATCHER_OPTIONS, + disableGlobbing: true, awaitWriteFinish: { stabilityThreshold: 80, pollInterval: 100 @@ -151,10 +150,9 @@ class DotEnvWatcher { this.workspaceWatchers.get(workspacePath).close(); } - const dotEnvPattern = path.join(workspacePath, '.env*'); - - const watcher = chokidar.watch(dotEnvPattern, { + const watcher = chokidar.watch(workspacePath, { ...DEFAULT_WATCHER_OPTIONS, + disableGlobbing: true, awaitWriteFinish: { stabilityThreshold: 80, pollInterval: 250 diff --git a/tests/dotenv/special-chars-collection-path/dotenv-special-chars.spec.ts b/tests/dotenv/special-chars-collection-path/dotenv-special-chars.spec.ts new file mode 100644 index 000000000..07172961c --- /dev/null +++ b/tests/dotenv/special-chars-collection-path/dotenv-special-chars.spec.ts @@ -0,0 +1,47 @@ +import { test, expect } from '../../../playwright'; +import { createCollection, createEnvironment, closeAllCollections } from '../../utils/page'; + +test.describe('DotEnv file in collection with special characters in path', () => { + test.afterEach(async ({ page }) => { + await closeAllCollections(page); + }); + + test('should detect .env file in collection with brackets in collection name', async ({ page, createTmpDir }) => { + const collectionName = 'My API (v2)'; + const tmpDir = await createTmpDir(collectionName); + + await test.step('Create collection with brackets in name', async () => { + await createCollection(page, collectionName, tmpDir); + }); + + await test.step('Create a collection environment to access env settings', async () => { + await createEnvironment(page, 'Test Env', 'collection'); + }); + + await test.step('Open environment config and create .env file', async () => { + // Open the environment selector to see the .ENV FILES section + await page.getByTestId('environment-selector-trigger').click(); + + // The .env Files section is collapsed by default — click to expand it + const dotEnvSection = page.locator('.section-header').filter({ hasText: '.env Files' }); + await dotEnvSection.waitFor({ state: 'visible' }); + await dotEnvSection.click(); + + // Now click the + button to create a new .env file + const addButton = dotEnvSection.locator('.section-actions button'); + await addButton.click(); + + // Type the .env file name and press Enter + const nameInput = page.locator('.environment-name-input'); + await nameInput.press('Enter'); + + // Wait for success toast + await expect(page.getByText('.env file created!')).toBeVisible(); + }); + + await test.step('Verify .env file is detected by watcher and shown in UI', async () => { + const dotEnvBadge = page.locator('.section-header').filter({ hasText: '.env Files' }).locator('.section-badge'); + await expect(dotEnvBadge).toHaveText('1'); + }); + }); +});