Files
bruno/tests/environments/global-env-process-env-resolution/global-env-process-env-resolution.spec.ts
Abhishek S Lal fabba4d296 fix: resolve process.env variables in global environment level (#7600)
* feat: enhance environment variable resolution in EnvironmentVariablesTable

- Added logic to populate process environment variables from the active workspace when no collection is selected, allowing for proper resolution of {{process.env.X}}.
- Updated workspace actions to map scratch collections to their respective workspaces, ensuring that environment variables can be resolved correctly.

This improves the user experience by providing access to workspace-specific environment variables in the environment variables table.

* refactor: improve state selection and add test IDs for better testing

- Refactored the state selection logic in EnvironmentVariablesTable for clarity.
- Added data-testid attributes to various components including CollapsibleSection, DotEnvFileDetails, DotEnvRawView, and EnvironmentList to enhance testability.
- This change aims to streamline component interactions and facilitate easier testing.

* feat: add test IDs to EnvironmentList for improved testability

- Introduced data-testid attributes to the EnvironmentList component, enhancing the ability to target elements in tests.
- This update includes test IDs for the CollapsibleSection, create .env file button, and the input field for the .env name, facilitating better integration with testing frameworks.

* refactor: simplify global environment test setup

- Removed unnecessary timeout setting and afterEach cleanup logic from the global environment process.env resolution test.
- This change streamlines the test structure, focusing on the core functionality being tested.
2026-04-04 14:57:50 +05:30

64 lines
2.2 KiB
TypeScript

import { test, expect } from '../../../playwright';
import {
openCollection,
openEnvironmentSelector,
openRequest,
sendRequest,
expectResponseContains
} from '../../utils/page';
test.describe('Global Environment process.env Resolution', () => {
test('should resolve process.env variables referenced in global environment', async ({
pageWithUserData: page
}) => {
await test.step('Open collection', async () => {
await openCollection(page, 'process-env-global-test');
});
await test.step('Create .env file with variable via UI', async () => {
// Open global environment configuration
await openEnvironmentSelector(page, 'global');
await page.getByTestId('configure-env').click();
// Expand the .env Files section
const dotEnvSection = page.getByTestId('dotenv-files-section');
await dotEnvSection.waitFor({ state: 'visible' });
await dotEnvSection.click();
// Click + to create a new .env file
await page.getByTestId('create-dotenv-file').click();
// Accept the default name (.env) and press Enter
await page.getByTestId('dotenv-name-input').press('Enter');
await expect(page.getByText('.env file created!')).toBeVisible();
// Switch to Raw mode to type the variable
await page.getByTestId('dotenv-view-raw').click();
// Type the variable into the raw editor
const rawEditor = page.getByTestId('dotenv-raw-editor').locator('.CodeMirror');
await rawEditor.click();
await page.keyboard.type('MY_SECRET=hello-from-dotenv');
// Save the .env file
await page.getByTestId('save-dotenv-raw').click();
});
await test.step('Verify global environment is active', async () => {
await expect(page.locator('.current-environment')).toContainText('ProcessEnv Test');
});
await test.step('Open request', async () => {
await openRequest(page, 'process-env-global-test', 'echo-post');
});
await test.step('Send request and verify process.env resolved', async () => {
await sendRequest(page, 200);
});
await test.step('Verify response contains resolved value from .env file', async () => {
await expectResponseContains(page, ['hello-from-dotenv']);
});
});
});