mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-27 22:54:07 +00:00
feat(variables): persist scripted variable changes by default + re-enable disabled scripting APIs (#8315)
* feat(variables): add variable persistence with scripting feat(collections): implement script-driven update for collection variables, ensuring direct root modification and draft synchronization feat(collections): enhance script variable management with baseline tracking and draft preservation * feat(variables): add runtime variable updates and optimize disk writes by implementing dirty flags fix(collections): handle errors during environment persistence in script execution feat(collections): implement baseline clearing for script execution and optimize variable update handling feat(tests): add default persistence tests for environment variables and update runtime variable handling refactor(collections): streamline variable update handling and improve draft management by removing redundant comments and optimizing code clarity test(collection-vars): add verification for draft edits and script variable visibility in collection settings UI refactor(collection-vars): update header value selection logic for improved clarity and accuracy in draft isolation tests * feat(global-environments): enhance global environment updates to resolve stale active UIDs and improve persistence logic - Updated the `updateGlobalEnvironments` reducer to handle stale active UIDs by matching against environment names. - Improved the logic for setting global environments and active UIDs to ensure consistency after disk reloads. - Removed outdated tests related to persisted values in favor of more relevant assertions for environment variable handling. * feat(variables): enhance typed value handling and persistence in global and collection environments - Added tests to infer data types (number, boolean, object) when setting environment and collection variables. - Updated the logic to preserve existing data types when variables are not modified by scripts. - Implemented dirty flags to track changes in typed variables, ensuring accurate persistence across sessions. - Refactored related tests to verify the correct behavior of typed variables in various scenarios. * refactor(variables): streamline data type inference and enhance deletion methods - Removed redundant data type inference logic from global and collection variable updates to simplify the codebase. - Updated deletion methods in the Bru class to use Object.keys for improved resilience against user-defined properties. - Added tests to ensure deletion methods function correctly even when properties are shadowed. - Enhanced clarity in draft merge tests by standardizing keyboard shortcuts for selecting all text. * fix(tests): correct variable naming and improve environment panel interactions - Updated test cases to reflect the correct variable name 'wasSaved' instead of 'was-saved'. - Modified environment panel interaction to remove forced click, enhancing test reliability. - Added a utility function to close the environment panel in safe mode tests for better readability and maintainability. * feat(runtime): enhance variable management and cleanup logic - Introduced a new method to clear script-driven variable baselines for collections, ensuring no stale data leaks into new requests. - Updated the handling of runtime variables in the Bru class to track changes with a new dirty flag, improving state management. - Refactored the application of script environment variables to prevent direct mutations, ensuring immutability and cleaner state updates. - Enhanced the response handling in the script runtime to conditionally include runtime variables based on their dirty state. * feat(variables): improve request handling and state management for collections and environments - Enhanced event listeners to clear global environment baselines on both 'testrun-started' and 'request-queued' events, preventing stale data issues. - Updated global environment and collection variable update events to ignore stale updates from superseded requests, ensuring accurate state management. - Refactored the Bru class to optimize variable management, including checks for existing keys before updates and deletions, improving performance and reliability. - Introduced request UID tracking to maintain consistency across variable updates during concurrent requests. * refactor(collections): update action to clear script variable baselines - Replaced the dispatch of `_clearScriptGlobalEnvBaseline` with `clearScriptVariableBaselines` to improve clarity and maintainability in the Redux action handling for collections. * feat(environments): introduce getScriptModifiedKeys utility for improved variable management - Added a new utility function, `getScriptModifiedKeys`, to identify keys modified by scripts relative to a baseline, enhancing the handling of data types during variable updates. - Updated the application of script environment variables to prevent overwriting user-defined draft changes during no-op writes. - Refactored related logic in collections and global environments to utilize the new utility, ensuring accurate state management and improved clarity in the Redux slices. * refactor(global-environments): simplify active UID resolution logic in updateGlobalEnvironments reducer - Streamlined the logic for resolving the active global environment UID by consolidating conditions into a more concise format. - Removed outdated comments to enhance code clarity and maintainability. - Updated tests to ensure accurate resolution of active UIDs based on incoming environment data. * refactor(tests): remove outdated comments and streamline environment variable row expectations - Eliminated comments related to state sync and inference issues to enhance code clarity. - Adjusted expectations for environment variable row rendering in tests, focusing on relevant assertions. * feat(tests): add comprehensive tests for secret variable persistence in environments - Introduced new test cases to validate the preservation of secret variables when updated via scripts in both collection and global environments. - Implemented tests to ensure that secret values are encrypted before storage and can be correctly decrypted for subsequent requests. - Added fixtures and environment configurations for testing secret variable behavior in both bru and yml formats. - Enhanced utility functions for managing environment configurations and interactions within the test suite. * feat(tests): enhance environment variable tests and add global variable persistence - Updated MultiLineEditor and SingleLineEditor components to include data-testid for secret reveal toggle buttons, improving testability. - Introduced new tests for global environment variable persistence, ensuring non-secret variables survive app restarts and are correctly interpolated. - Added fixtures for workspace and collections to support the new global variable tests, enhancing the overall test coverage for environment management. - Refactored utility functions to streamline interactions with environment variables in tests. * refactor(collections): optimize environment and collection saving logic - Simplified the persistence logic for active environments by directly constructing the environment copy, reducing unnecessary cloning. - Updated the collection saving process to utilize the fresh collection state, ensuring accurate data is saved without drafts. - Enhanced error handling during the save operations to improve reliability and maintainability. * feat(tests): implement collection variable persistence tests - Added multiple test cases to validate the persistence of collection variables across app restarts, including typed values and multiple variable settings. - Created new fixtures for collection variables to support the tests, ensuring accurate simulation of variable management scenarios. - Enhanced the existing collection management logic to ensure that variables are correctly set and deleted as per the test requirements. * feat(tests): add tests for typed global environment variable persistence - Introduced a new test suite to validate the persistence of typed global environment variables across app restarts, ensuring correct data types are maintained. - Created a fixture for the test collection to simulate setting global variables with various data types, including number, boolean, object, and string. - Enhanced the test logic to verify that the environment file reflects the correct state before and after application restarts. * fix(tests): update request tab close interaction in variable persistence tests * fix(tests): improve hover interaction for collection actions in runner tests - Updated the hover logic for revealing collection actions to handle sidebar re-renders more reliably. - Replaced one-shot hover with a polling mechanism to ensure visibility of actions, enhancing test stability. * refactor(environments): streamline environment variable handling and remove ephemeral metadata logic - Simplified the comparison logic for environment variables by removing unnecessary ephemeral metadata handling. - Updated the saving process to directly use the environment variables without stripping metadata, enhancing clarity and maintainability. - Removed outdated comments and unused utility functions related to ephemeral variables, improving code cleanliness. * fix(ipc): update persistActiveEnvironment to handle requestUid for stale updates - Modified the persistActiveEnvironment function to accept a requestUid parameter, allowing for better management of stale updates. - Enhanced the logic to prevent disk writes for superseded requests, improving data integrity during environment persistence. * refactor(bru): remove unused envName variable in deleteAllEnvVars method - Eliminated the envName variable from the deleteAllEnvVars method, simplifying the logic for deleting environment variables. - Cleaned up the method by removing unnecessary checks related to the envName, enhancing code clarity and maintainability. * fix(bru): prevent deletion of internal __name__ variable in deleteEnvVar method - Added a check in the deleteEnvVar method to silently ignore attempts to delete the internal __name__ variable, preserving its integrity. - Updated tests to verify that the __name__ variable remains unchanged when deleteEnvVar is called with this key. - Enhanced runtime tests to ensure compatibility with QuickJS by confirming that environment variables set with persist options are handled correctly. * feat(tests): add legacy support test for environment variable persistence - Introduced a new test suite to validate that the legacy argument for setting environment variables with persistence is still functional in version 4. - Created a fixture to simulate the legacy syntax, ensuring that the variable is correctly persisted on disk without errors. - Enhanced integration testing to confirm that the legacy behavior aligns with the current implementation, maintaining backward compatibility. * test(tests): enhance legacy environment variable persistence tests for safe and developer modes - Updated the test suite for `bru.setEnvVar` to verify that the legacy persist flag is correctly handled in both safe and developer modes. - Introduced a helper function to streamline the verification process and ensure consistent behavior across different execution contexts. - Adjusted the test logic to reset the environment state between mode switches, maintaining test integrity. - Improved hover interaction in multiple persistent variable tests to ensure reliable visibility of actions during execution. * fix(EnvironmentVariablesTable): correct change detection logic for environment variables - Updated the logic for determining changes in environment variables to compare active current and saved values instead of previously used variablesToSave and savedValues. - This change ensures accurate detection of modifications before saving, improving user feedback when no changes are present. * test(tests): enhance secret variable persistence tests for environment configurations - Updated the test suites for `bru.setEnvVar` and `bru.setGlobalEnvVar` to include interactions with the secrets tab, ensuring visibility of secret variables during various states of the environment. - Added checks to confirm that the eye toggle functionality correctly reveals the values of secret variables after setting and overwriting them. - Improved test coverage for secret variable persistence, validating that the expected values are displayed in both collection and global environment contexts.
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import { test, expect } from '../../../../playwright';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { openCollection, selectEnvironment, sendRequest } from '../../../utils/page';
|
||||
import { buildCommonLocators } from '../../../utils/page/locators';
|
||||
|
||||
const PERSISTENCE_TIMEOUT = 10000;
|
||||
const selectAllShortcut = process.platform === 'darwin' ? 'Meta+a' : 'Control+a';
|
||||
|
||||
test.describe('Collection vars script persistence does not leak draft headers', () => {
|
||||
test('draft header edits are not persisted when script sets a collection variable', async ({
|
||||
pageWithUserData: page,
|
||||
collectionFixturePath
|
||||
}) => {
|
||||
const locators = buildCommonLocators(page);
|
||||
const collectionBruPath = path.join(collectionFixturePath!, 'draft-isolation-test', 'collection.bru');
|
||||
|
||||
await openCollection(page, 'draft-isolation-test');
|
||||
await selectEnvironment(page, 'Test');
|
||||
|
||||
// Read the original file to confirm the initial header value
|
||||
const originalContent = fs.readFileSync(collectionBruPath, 'utf8');
|
||||
expect(originalContent).toContain('X-Custom-Header: original-value');
|
||||
|
||||
await test.step('Open collection settings and edit header (create draft)', async () => {
|
||||
await locators.sidebar.collection('draft-isolation-test').click();
|
||||
await locators.paneTabs.collectionSettingsTab('headers').click();
|
||||
|
||||
const headerRow = page.locator('tbody tr').filter({
|
||||
hasText: 'X-Custom-Header'
|
||||
});
|
||||
await expect(headerRow).toBeVisible();
|
||||
|
||||
const valueCellEditor = headerRow.locator('.CodeMirror').nth(1);
|
||||
await valueCellEditor.click();
|
||||
await page.keyboard.press(selectAllShortcut);
|
||||
await page.keyboard.type('draft-edited-value');
|
||||
|
||||
await expect(locators.tabs.collectionSettingsTab().locator('.close-gradient'))
|
||||
.toHaveClass(/has-changes/);
|
||||
});
|
||||
|
||||
await test.step('Open request and send it (script sets a collection var)', async () => {
|
||||
await locators.sidebar.request('set-collection-var').click();
|
||||
await expect(locators.tabs.requestTab('set-collection-var')).toBeVisible();
|
||||
await sendRequest(page, 200);
|
||||
});
|
||||
|
||||
await test.step('Verify script collection var persisted to collection.bru', async () => {
|
||||
await expect.poll(() => {
|
||||
const content = fs.readFileSync(collectionBruPath, 'utf8');
|
||||
return content.includes('scriptVar') && content.includes('from-script');
|
||||
}, { timeout: PERSISTENCE_TIMEOUT }).toBe(true);
|
||||
});
|
||||
|
||||
await test.step('Verify draft header edit was NOT persisted to collection.bru', async () => {
|
||||
const content = fs.readFileSync(collectionBruPath, 'utf8');
|
||||
// The original header value should still be on disk
|
||||
expect(content).toContain('X-Custom-Header: original-value');
|
||||
// The draft edit should NOT be on disk
|
||||
expect(content).not.toContain('draft-edited-value');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"version": "1",
|
||||
"name": "draft-isolation-test",
|
||||
"type": "collection",
|
||||
"ignore": [
|
||||
"node_modules",
|
||||
".git"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
headers {
|
||||
X-Custom-Header: original-value
|
||||
}
|
||||
|
||||
vars:pre-request {
|
||||
host: https://testbench-sanity.usebruno.com
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
vars {
|
||||
host: https://testbench-sanity.usebruno.com
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
meta {
|
||||
name: set-collection-var
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{host}}/ping
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setCollectionVar("scriptVar", "from-script");
|
||||
}
|
||||
|
||||
tests {
|
||||
test("should set collection var", function() {
|
||||
const val = bru.getCollectionVar("scriptVar");
|
||||
expect(val).to.equal("from-script");
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"collections": [
|
||||
{
|
||||
"path": "{{collectionPath}}/draft-isolation-test",
|
||||
"securityConfig": {
|
||||
"jsSandboxMode": "safe"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"lastOpenedCollections": [
|
||||
"{{collectionPath}}/draft-isolation-test"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"version": "1",
|
||||
"name": "global-env-var-persistence-typed-test",
|
||||
"type": "collection",
|
||||
"ignore": [
|
||||
"node_modules",
|
||||
".git"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
meta {
|
||||
name: set-typed-global-env-vars
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
get {
|
||||
url: https://testbench-sanity.usebruno.com/ping
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setGlobalEnvVar("globalNum", 99);
|
||||
bru.setGlobalEnvVar("globalBool", false);
|
||||
bru.setGlobalEnvVar("globalObj", { tier: "premium", limit: 1000 });
|
||||
}
|
||||
|
||||
tests {
|
||||
test("typed global env vars are readable as their original types", function() {
|
||||
expect(bru.getGlobalEnvVar("globalNum")).to.equal(99);
|
||||
expect(bru.getGlobalEnvVar("globalBool")).to.equal(false);
|
||||
expect(bru.getGlobalEnvVar("globalObj")).to.deep.equal({ tier: "premium", limit: 1000 });
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { test, expect } from '../../../../playwright';
|
||||
import { openCollection, sendRequest, openEnvironmentSelector } from '../../../utils/page';
|
||||
import { buildCommonLocators } from '../../../utils/page/locators';
|
||||
|
||||
test.describe('Script-driven typed global env variable persistence', () => {
|
||||
test('bru.setGlobalEnvVar() persists number/boolean/object with correct type labels', async ({
|
||||
pageWithUserData: page
|
||||
}) => {
|
||||
const locators = buildCommonLocators(page);
|
||||
|
||||
await openCollection(page, 'global-env-var-persistence-typed-test');
|
||||
await locators.sidebar.request('set-typed-global-env-vars').click();
|
||||
await sendRequest(page, 200);
|
||||
|
||||
await test.step('Open global environment config', async () => {
|
||||
await openEnvironmentSelector(page, 'global');
|
||||
await locators.environment.configureButton().click();
|
||||
await expect(locators.environment.globalEnvTab()).toBeVisible();
|
||||
});
|
||||
|
||||
await test.step('Verify globalNum has dataType=number and value 99', async () => {
|
||||
const row = locators.environment.variableRowByName('globalNum');
|
||||
await expect(row).toBeVisible();
|
||||
await expect(locators.dataTypeSelector.typeLabel(row)).toHaveText('number');
|
||||
await expect(locators.environment.variableValue('globalNum')).toContainText('99');
|
||||
});
|
||||
|
||||
await test.step('Verify globalBool has dataType=boolean and value false', async () => {
|
||||
const row = locators.environment.variableRowByName('globalBool');
|
||||
await expect(row).toBeVisible();
|
||||
await expect(locators.dataTypeSelector.typeLabel(row)).toHaveText('boolean');
|
||||
await expect(locators.environment.variableValue('globalBool')).toContainText('false');
|
||||
});
|
||||
|
||||
await test.step('Verify globalObj has dataType=object containing the serialized JSON', async () => {
|
||||
const row = locators.environment.variableRowByName('globalObj');
|
||||
await expect(row).toBeVisible();
|
||||
await expect(locators.dataTypeSelector.typeLabel(row)).toHaveText('object');
|
||||
await expect(locators.environment.variableValue('globalObj')).toContainText('tier');
|
||||
await expect(locators.environment.variableValue('globalObj')).toContainText('premium');
|
||||
});
|
||||
|
||||
await test.step('Verify baseUrl (string, untouched) still has no special type label', async () => {
|
||||
const row = locators.environment.variableRowByName('baseUrl');
|
||||
await expect(row).toBeVisible();
|
||||
await expect(locators.dataTypeSelector.typeLabel(row)).toHaveText('string');
|
||||
});
|
||||
|
||||
await test.step('Close global environment config', async () => {
|
||||
await locators.environment.globalEnvTab().hover();
|
||||
await locators.environment.globalEnvTab().getByTestId('request-tab-close-icon').click({ force: true });
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"collections": [
|
||||
{
|
||||
"path": "{{collectionPath}}/global-env-var-persistence-typed-test",
|
||||
"securityConfig": {
|
||||
"jsSandboxMode": "developer"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"environments": [
|
||||
{
|
||||
"uid": "GlobEnvTypedUid000001",
|
||||
"name": "global",
|
||||
"variables": [
|
||||
{
|
||||
"uid": "GlobEnvTypedVar000001",
|
||||
"name": "baseUrl",
|
||||
"value": "https://testbench-sanity.usebruno.com",
|
||||
"type": "text",
|
||||
"secret": false,
|
||||
"enabled": true
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"activeGlobalEnvironmentUid": "GlobEnvTypedUid000001"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"lastOpenedCollections": [
|
||||
"{{collectionPath}}/global-env-var-persistence-typed-test"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"version": "1",
|
||||
"name": "global-env-var-persistence-test",
|
||||
"type": "collection",
|
||||
"ignore": [
|
||||
"node_modules",
|
||||
".git"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
meta {
|
||||
name: delete-global-env-var
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{baseUrl}}/ping
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.deleteGlobalEnvVar("toBeDeleted");
|
||||
}
|
||||
|
||||
tests {
|
||||
test("should have deleted global env var", function() {
|
||||
const val = bru.getGlobalEnvVar("toBeDeleted");
|
||||
expect(val).to.be.undefined;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
meta {
|
||||
name: set-global-env-var
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{baseUrl}}/ping
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setGlobalEnvVar("newGlobalVar", "new-global-value");
|
||||
}
|
||||
|
||||
tests {
|
||||
test("should have set new global env var", function() {
|
||||
const val = bru.getGlobalEnvVar("newGlobalVar");
|
||||
expect(val).to.equal("new-global-value");
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import { test, expect } from '../../../../playwright';
|
||||
import { openCollection, sendRequest, openEnvironmentSelector } from '../../../utils/page';
|
||||
import { buildCommonLocators } from '../../../utils/page/locators';
|
||||
|
||||
test.describe('Global environment variable persistence via script', () => {
|
||||
test('bru.deleteGlobalEnvVar() removes variable from global environment', async ({
|
||||
pageWithUserData: page
|
||||
}) => {
|
||||
const locators = buildCommonLocators(page);
|
||||
|
||||
await openCollection(page, 'global-env-var-persistence-test');
|
||||
await locators.sidebar.request('delete-global-env-var').click();
|
||||
await sendRequest(page, 200);
|
||||
|
||||
await test.step('Open global environment config', async () => {
|
||||
await openEnvironmentSelector(page, 'global');
|
||||
await locators.environment.configureButton().click();
|
||||
await expect(locators.environment.globalEnvTab()).toBeVisible();
|
||||
});
|
||||
|
||||
await test.step('Verify "toBeDeleted" is removed', async () => {
|
||||
await expect(locators.environment.variableRowByName('toBeDeleted')).not.toBeVisible();
|
||||
});
|
||||
|
||||
await test.step('Verify "baseUrl" still exists with original value', async () => {
|
||||
await expect(locators.environment.variableRowByName('baseUrl')).toBeVisible();
|
||||
await expect(locators.environment.variableValue('baseUrl')).toContainText('https://testbench-sanity.usebruno.com');
|
||||
});
|
||||
|
||||
await test.step('Close global environment config', async () => {
|
||||
await locators.environment.globalEnvTab().hover();
|
||||
await locators.environment.globalEnvTab().getByTestId('request-tab-close-icon').click({ force: true });
|
||||
});
|
||||
});
|
||||
|
||||
test('bru.setGlobalEnvVar() adds new variable to global environment', async ({
|
||||
pageWithUserData: page
|
||||
}) => {
|
||||
const locators = buildCommonLocators(page);
|
||||
|
||||
await openCollection(page, 'global-env-var-persistence-test');
|
||||
await locators.sidebar.request('set-global-env-var').click();
|
||||
await sendRequest(page, 200);
|
||||
|
||||
await test.step('Open global environment config', async () => {
|
||||
await openEnvironmentSelector(page, 'global');
|
||||
await locators.environment.configureButton().click();
|
||||
await expect(locators.environment.globalEnvTab()).toBeVisible();
|
||||
});
|
||||
|
||||
await test.step('Verify "newGlobalVar" is added with correct value', async () => {
|
||||
await expect(locators.environment.variableRowByName('newGlobalVar')).toBeVisible();
|
||||
await expect(locators.environment.variableValue('newGlobalVar')).toContainText('new-global-value');
|
||||
});
|
||||
|
||||
await test.step('Verify "baseUrl" still exists with original value', async () => {
|
||||
await expect(locators.environment.variableRowByName('baseUrl')).toBeVisible();
|
||||
await expect(locators.environment.variableValue('baseUrl')).toContainText('https://testbench-sanity.usebruno.com');
|
||||
});
|
||||
|
||||
await test.step('Close global environment config', async () => {
|
||||
await locators.environment.globalEnvTab().hover();
|
||||
await locators.environment.globalEnvTab().getByTestId('request-tab-close-icon').click({ force: true });
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"collections": [
|
||||
{
|
||||
"path": "{{collectionPath}}/global-env-var-persistence-test",
|
||||
"securityConfig": {
|
||||
"jsSandboxMode": "safe"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"environments": [
|
||||
{
|
||||
"uid": "RrPsTcwRnHMv3yljQO3ex",
|
||||
"name": "global",
|
||||
"variables": [
|
||||
{
|
||||
"uid": "VXKOZdkYw0DyI4mlhn6Wr",
|
||||
"name": "baseUrl",
|
||||
"value": "https://testbench-sanity.usebruno.com",
|
||||
"type": "text",
|
||||
"secret": false,
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"uid": "NTwrSscXsaeh4uee6ocJN",
|
||||
"name": "toBeDeleted",
|
||||
"value": "this-should-be-removed",
|
||||
"type": "text",
|
||||
"secret": false,
|
||||
"enabled": true
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"activeGlobalEnvironmentUid": "RrPsTcwRnHMv3yljQO3ex"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"lastOpenedCollections": [
|
||||
"{{collectionPath}}/global-env-var-persistence-test"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"version": "1",
|
||||
"name": "variable-persistence-multi-request-test",
|
||||
"type": "collection",
|
||||
"ignore": [
|
||||
"node_modules",
|
||||
".git"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
vars {
|
||||
host: https://testbench-sanity.usebruno.com
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
meta {
|
||||
name: req-1-write
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{host}}/ping
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setEnvVar("counter", "1");
|
||||
}
|
||||
|
||||
tests {
|
||||
test("request 1 wrote counter=1", function() {
|
||||
expect(bru.getEnvVar("counter")).to.equal("1");
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
meta {
|
||||
name: req-2-read-and-write
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{host}}/ping
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
// Request 2 must observe request 1's persistence — proves the baseline cleared between requests
|
||||
// (otherwise this read would see undefined, the request-1-era pre-write snapshot).
|
||||
const prev = bru.getEnvVar("counter");
|
||||
bru.setEnvVar("seenInReq2", prev);
|
||||
bru.setEnvVar("counter", "2");
|
||||
}
|
||||
|
||||
tests {
|
||||
test("request 2 observed request 1's write", function() {
|
||||
expect(bru.getEnvVar("seenInReq2")).to.equal("1");
|
||||
});
|
||||
|
||||
test("request 2 wrote counter=2", function() {
|
||||
expect(bru.getEnvVar("counter")).to.equal("2");
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"collections": [
|
||||
{
|
||||
"path": "{{collectionPath}}/variable-persistence-multi-request-test",
|
||||
"securityConfig": {
|
||||
"jsSandboxMode": "developer"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"lastOpenedCollections": [
|
||||
"{{collectionPath}}/variable-persistence-multi-request-test"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { test, expect } from '../../../../playwright';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { openCollection, selectEnvironment } from '../../../utils/page';
|
||||
import { runCollection, validateRunnerResults } from '../../../utils/page/runner';
|
||||
|
||||
const PERSISTENCE_TIMEOUT = 10000;
|
||||
|
||||
test.describe('Script variable persistence across requests (baseline-clear between requests)', () => {
|
||||
test('request 2 observes request 1\'s write; final disk state reflects last write', async ({
|
||||
pageWithUserData: page,
|
||||
collectionFixturePath
|
||||
}) => {
|
||||
await openCollection(page, 'variable-persistence-multi-request-test');
|
||||
await selectEnvironment(page, 'Test');
|
||||
await runCollection(page, 'variable-persistence-multi-request-test');
|
||||
|
||||
// Both requests should pass: req-1 sets counter=1, req-2 reads counter (must see "1"),
|
||||
// then sets counter=2. If the baseline didn't clear between requests, req-2's read
|
||||
// would see undefined / wrong value and one of its tests would fail.
|
||||
await validateRunnerResults(page, {
|
||||
totalRequests: 2,
|
||||
passed: 2,
|
||||
failed: 0
|
||||
});
|
||||
|
||||
await test.step('final disk state reflects the last write (counter=2)', async () => {
|
||||
const envFilePath = path.join(
|
||||
collectionFixturePath!,
|
||||
'variable-persistence-multi-request-test',
|
||||
'environments',
|
||||
'Test.bru'
|
||||
);
|
||||
await expect.poll(() => {
|
||||
const content = fs.readFileSync(envFilePath, 'utf8');
|
||||
// Must contain counter=2 (the last write wins) and seenInReq2=1 (request 2 observed request 1).
|
||||
return content.includes('counter:') && content.includes('2')
|
||||
&& content.includes('seenInReq2:') && content.includes('1');
|
||||
}, { timeout: PERSISTENCE_TIMEOUT }).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"version": "1",
|
||||
"name": "variable-persistence-safe-test",
|
||||
"type": "collection",
|
||||
"ignore": [
|
||||
"node_modules",
|
||||
".git"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
vars {
|
||||
host: https://testbench-sanity.usebruno.com
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
meta {
|
||||
name: set-collection-var
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{host}}/ping
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setCollectionVar("persistedCollectionToken", "collection-value-456");
|
||||
}
|
||||
|
||||
tests {
|
||||
test("should set collection var", function() {
|
||||
const val = bru.getCollectionVar("persistedCollectionToken");
|
||||
expect(val).to.equal("collection-value-456");
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
meta {
|
||||
name: set-env-var
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{host}}/ping
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setEnvVar("persistedToken", "test-value-123");
|
||||
}
|
||||
|
||||
tests {
|
||||
test("should set env var", function() {
|
||||
const val = bru.getEnvVar("persistedToken");
|
||||
expect(val).to.equal("test-value-123");
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"collections": [
|
||||
{
|
||||
"path": "{{collectionPath}}/variable-persistence-safe-test",
|
||||
"securityConfig": {
|
||||
"jsSandboxMode": "safe"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"lastOpenedCollections": [
|
||||
"{{collectionPath}}/variable-persistence-safe-test"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import { test, expect } from '../../../../playwright';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { openCollection, selectEnvironment, openEnvironmentSelector } from '../../../utils/page';
|
||||
import { buildCommonLocators } from '../../../utils/page/locators';
|
||||
import { runCollection, validateRunnerResults } from '../../../utils/page/runner';
|
||||
|
||||
const PERSISTENCE_TIMEOUT = 10000;
|
||||
|
||||
test.describe('Script variable persistence to disk (safe mode)', () => {
|
||||
test('persists env var and collection var in safe mode', async ({ pageWithUserData: page, collectionFixturePath }) => {
|
||||
const locators = buildCommonLocators(page);
|
||||
|
||||
await openCollection(page, 'variable-persistence-safe-test');
|
||||
await selectEnvironment(page, 'Test');
|
||||
await runCollection(page, 'variable-persistence-safe-test');
|
||||
|
||||
await validateRunnerResults(page, {
|
||||
totalRequests: 2,
|
||||
passed: 2,
|
||||
failed: 0
|
||||
});
|
||||
|
||||
await test.step('Verify env var visible in environment UI', async () => {
|
||||
await openEnvironmentSelector(page, 'collection');
|
||||
await locators.environment.configureButton().click();
|
||||
await expect(locators.environment.collectionEnvTab()).toBeVisible();
|
||||
|
||||
await expect(locators.environment.variableRowByName('persistedToken')).toBeVisible();
|
||||
await expect(locators.environment.variableValue('persistedToken')).toContainText('test-value-123');
|
||||
|
||||
await locators.environment.collectionEnvTab().hover();
|
||||
await locators.environment.collectionEnvTab().getByTestId('request-tab-close-icon').click({ force: true });
|
||||
});
|
||||
|
||||
await test.step('Verify env var persisted to environments/Test.bru', async () => {
|
||||
const envFilePath = path.join(collectionFixturePath!, 'variable-persistence-safe-test', 'environments', 'Test.bru');
|
||||
await expect.poll(() => {
|
||||
const content = fs.readFileSync(envFilePath, 'utf8');
|
||||
return content.includes('persistedToken') && content.includes('test-value-123');
|
||||
}, { timeout: PERSISTENCE_TIMEOUT }).toBe(true);
|
||||
});
|
||||
|
||||
await test.step('Verify collection var persisted to collection.bru', async () => {
|
||||
const collectionBruPath = path.join(collectionFixturePath!, 'variable-persistence-safe-test', 'collection.bru');
|
||||
await expect.poll(() => {
|
||||
const content = fs.readFileSync(collectionBruPath, 'utf8');
|
||||
return content.includes('persistedCollectionToken') && content.includes('collection-value-456');
|
||||
}, { timeout: PERSISTENCE_TIMEOUT }).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"version": "1",
|
||||
"name": "variable-persistence-typed-safe-test",
|
||||
"type": "collection",
|
||||
"ignore": [
|
||||
"node_modules",
|
||||
".git"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
vars {
|
||||
host: https://testbench-sanity.usebruno.com
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
meta {
|
||||
name: set-typed-collection-vars
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
get {
|
||||
url: https://testbench-sanity.usebruno.com/ping
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setCollectionVar("collNum", 7);
|
||||
bru.setCollectionVar("collBool", false);
|
||||
bru.setCollectionVar("collObj", { region: "eu", retries: 3 });
|
||||
}
|
||||
|
||||
tests {
|
||||
test("typed collection vars are readable as their original types", function() {
|
||||
expect(bru.getCollectionVar("collNum")).to.equal(7);
|
||||
expect(bru.getCollectionVar("collBool")).to.equal(false);
|
||||
expect(bru.getCollectionVar("collObj")).to.deep.equal({ region: "eu", retries: 3 });
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
meta {
|
||||
name: set-typed-env-vars
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
get {
|
||||
url: https://testbench-sanity.usebruno.com/ping
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setEnvVar("envNum", 42);
|
||||
bru.setEnvVar("envBool", true);
|
||||
bru.setEnvVar("envObj", { port: 3000, ssl: true });
|
||||
}
|
||||
|
||||
tests {
|
||||
test("typed env vars are readable as their original types", function() {
|
||||
expect(bru.getEnvVar("envNum")).to.equal(42);
|
||||
expect(bru.getEnvVar("envBool")).to.equal(true);
|
||||
expect(bru.getEnvVar("envObj")).to.deep.equal({ port: 3000, ssl: true });
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"collections": [
|
||||
{
|
||||
"path": "{{collectionPath}}/variable-persistence-typed-safe-test",
|
||||
"securityConfig": {
|
||||
"jsSandboxMode": "safe"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"lastOpenedCollections": [
|
||||
"{{collectionPath}}/variable-persistence-typed-safe-test"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import { test, expect } from '../../../../playwright';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { openCollection, selectEnvironment, openEnvironmentSelector, closeEnvironmentPanel } from '../../../utils/page';
|
||||
import { buildCommonLocators } from '../../../utils/page/locators';
|
||||
import { runCollection, validateRunnerResults } from '../../../utils/page/runner';
|
||||
|
||||
const PERSISTENCE_TIMEOUT = 10000;
|
||||
|
||||
test.describe('Script-driven typed variable persistence to disk (safe mode / QuickJS)', () => {
|
||||
test('QuickJS shim preserves number/boolean/object across the host boundary and to disk', async ({
|
||||
pageWithUserData: page,
|
||||
collectionFixturePath
|
||||
}) => {
|
||||
const locators = buildCommonLocators(page);
|
||||
const COLLECTION_NAME = 'variable-persistence-typed-safe-test';
|
||||
|
||||
await openCollection(page, COLLECTION_NAME);
|
||||
await selectEnvironment(page, 'Test');
|
||||
await runCollection(page, COLLECTION_NAME);
|
||||
|
||||
await validateRunnerResults(page, {
|
||||
totalRequests: 2,
|
||||
passed: 2,
|
||||
failed: 0
|
||||
});
|
||||
|
||||
const envFilePath = path.join(collectionFixturePath!, COLLECTION_NAME, 'environments', 'Test.bru');
|
||||
const collectionBruPath = path.join(collectionFixturePath!, COLLECTION_NAME, 'collection.bru');
|
||||
|
||||
await test.step('environments/Test.bru contains @number/@boolean/@object annotations for env vars', async () => {
|
||||
await expect.poll(() => {
|
||||
const content = fs.readFileSync(envFilePath, 'utf8');
|
||||
return (
|
||||
/@number\s+envNum:\s*42/.test(content)
|
||||
&& /@boolean\s+envBool:\s*true/.test(content)
|
||||
&& /@object\s+envObj:/.test(content)
|
||||
&& content.includes('"port"')
|
||||
&& content.includes('3000')
|
||||
);
|
||||
}, { timeout: PERSISTENCE_TIMEOUT }).toBe(true);
|
||||
});
|
||||
|
||||
await test.step('collection.bru contains @number/@boolean/@object annotations for collection vars', async () => {
|
||||
await expect.poll(() => {
|
||||
const content = fs.readFileSync(collectionBruPath, 'utf8');
|
||||
return (
|
||||
/@number\s+collNum:\s*7/.test(content)
|
||||
&& /@boolean\s+collBool:\s*false/.test(content)
|
||||
&& /@object\s+collObj:/.test(content)
|
||||
&& content.includes('"region"')
|
||||
&& content.includes('"eu"')
|
||||
);
|
||||
}, { timeout: PERSISTENCE_TIMEOUT }).toBe(true);
|
||||
});
|
||||
|
||||
await test.step('env editor shows the correct type label per row', async () => {
|
||||
await openEnvironmentSelector(page, 'collection');
|
||||
await locators.environment.configureButton().click();
|
||||
await expect(locators.environment.collectionEnvTab()).toBeVisible();
|
||||
|
||||
const numRow = locators.environment.variableRowByName('envNum');
|
||||
const boolRow = locators.environment.variableRowByName('envBool');
|
||||
const objRow = locators.environment.variableRowByName('envObj');
|
||||
|
||||
await expect(numRow).toBeVisible();
|
||||
await expect(locators.dataTypeSelector.typeLabel(numRow)).toHaveText('number');
|
||||
await expect(locators.dataTypeSelector.typeLabel(boolRow)).toHaveText('boolean');
|
||||
await expect(locators.dataTypeSelector.typeLabel(objRow)).toHaveText('object');
|
||||
|
||||
await closeEnvironmentPanel(page, 'collection');
|
||||
await expect(locators.environment.collectionEnvTab()).not.toBeVisible();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"version": "1",
|
||||
"name": "variable-persistence-typed-test",
|
||||
"type": "collection",
|
||||
"ignore": [
|
||||
"node_modules",
|
||||
".git"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
vars {
|
||||
host: https://testbench-sanity.usebruno.com
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
meta {
|
||||
name: set-typed-collection-vars
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
get {
|
||||
url: https://testbench-sanity.usebruno.com/ping
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setCollectionVar("collNum", 7);
|
||||
bru.setCollectionVar("collBool", false);
|
||||
bru.setCollectionVar("collObj", { region: "eu", retries: 3 });
|
||||
}
|
||||
|
||||
tests {
|
||||
test("typed collection vars are readable as their original types", function() {
|
||||
expect(bru.getCollectionVar("collNum")).to.equal(7);
|
||||
expect(bru.getCollectionVar("collBool")).to.equal(false);
|
||||
expect(bru.getCollectionVar("collObj")).to.deep.equal({ region: "eu", retries: 3 });
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
meta {
|
||||
name: set-typed-env-vars
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
get {
|
||||
url: https://testbench-sanity.usebruno.com/ping
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setEnvVar("envNum", 42);
|
||||
bru.setEnvVar("envBool", true);
|
||||
bru.setEnvVar("envObj", { port: 3000, ssl: true });
|
||||
}
|
||||
|
||||
tests {
|
||||
test("typed env vars are readable as their original types", function() {
|
||||
expect(bru.getEnvVar("envNum")).to.equal(42);
|
||||
expect(bru.getEnvVar("envBool")).to.equal(true);
|
||||
expect(bru.getEnvVar("envObj")).to.deep.equal({ port: 3000, ssl: true });
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"collections": [
|
||||
{
|
||||
"path": "{{collectionPath}}/variable-persistence-typed-test",
|
||||
"securityConfig": {
|
||||
"jsSandboxMode": "developer"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"lastOpenedCollections": [
|
||||
"{{collectionPath}}/variable-persistence-typed-test"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import { test, expect } from '../../../../playwright';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { openCollection, selectEnvironment, openEnvironmentSelector } from '../../../utils/page';
|
||||
import { buildCommonLocators } from '../../../utils/page/locators';
|
||||
import { runCollection, validateRunnerResults } from '../../../utils/page/runner';
|
||||
|
||||
const PERSISTENCE_TIMEOUT = 10000;
|
||||
|
||||
test.describe('Script-driven typed variable persistence to disk (developer mode)', () => {
|
||||
test('persists number/boolean/object env + collection vars with dataType annotations', async ({
|
||||
pageWithUserData: page,
|
||||
collectionFixturePath
|
||||
}) => {
|
||||
const locators = buildCommonLocators(page);
|
||||
const COLLECTION_NAME = 'variable-persistence-typed-test';
|
||||
|
||||
await openCollection(page, COLLECTION_NAME);
|
||||
await selectEnvironment(page, 'Test');
|
||||
await runCollection(page, COLLECTION_NAME);
|
||||
|
||||
await validateRunnerResults(page, {
|
||||
totalRequests: 2,
|
||||
passed: 2,
|
||||
failed: 0
|
||||
});
|
||||
|
||||
const envFilePath = path.join(collectionFixturePath!, COLLECTION_NAME, 'environments', 'Test.bru');
|
||||
const collectionBruPath = path.join(collectionFixturePath!, COLLECTION_NAME, 'collection.bru');
|
||||
|
||||
await test.step('environments/Test.bru contains @number/@boolean/@object annotations for env vars', async () => {
|
||||
await expect.poll(() => {
|
||||
const content = fs.readFileSync(envFilePath, 'utf8');
|
||||
return (
|
||||
/@number\s+envNum:\s*42/.test(content)
|
||||
&& /@boolean\s+envBool:\s*true/.test(content)
|
||||
&& /@object\s+envObj:/.test(content)
|
||||
&& content.includes('"port"')
|
||||
&& content.includes('3000')
|
||||
);
|
||||
}, { timeout: PERSISTENCE_TIMEOUT }).toBe(true);
|
||||
});
|
||||
|
||||
await test.step('collection.bru contains @number/@boolean/@object annotations for collection vars', async () => {
|
||||
await expect.poll(() => {
|
||||
const content = fs.readFileSync(collectionBruPath, 'utf8');
|
||||
return (
|
||||
/@number\s+collNum:\s*7/.test(content)
|
||||
&& /@boolean\s+collBool:\s*false/.test(content)
|
||||
&& /@object\s+collObj:/.test(content)
|
||||
&& content.includes('"region"')
|
||||
&& content.includes('"eu"')
|
||||
);
|
||||
}, { timeout: PERSISTENCE_TIMEOUT }).toBe(true);
|
||||
});
|
||||
|
||||
await test.step('env editor shows the correct type label per row', async () => {
|
||||
await openEnvironmentSelector(page, 'collection');
|
||||
await locators.environment.configureButton().click();
|
||||
await expect(locators.environment.collectionEnvTab()).toBeVisible();
|
||||
|
||||
const numRow = locators.environment.variableRowByName('envNum');
|
||||
const boolRow = locators.environment.variableRowByName('envBool');
|
||||
const objRow = locators.environment.variableRowByName('envObj');
|
||||
|
||||
await expect(numRow).toBeVisible();
|
||||
await expect(locators.dataTypeSelector.typeLabel(numRow)).toHaveText('number');
|
||||
await expect(locators.dataTypeSelector.typeLabel(boolRow)).toHaveText('boolean');
|
||||
await expect(locators.dataTypeSelector.typeLabel(objRow)).toHaveText('object');
|
||||
|
||||
await locators.environment.collectionEnvTab().getByTestId('request-tab-close-icon').click({ force: true });
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"version": "1",
|
||||
"name": "variable-persistence-test",
|
||||
"type": "collection",
|
||||
"ignore": [
|
||||
"node_modules",
|
||||
".git"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
vars {
|
||||
host: https://testbench-sanity.usebruno.com
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
meta {
|
||||
name: set-collection-var
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{host}}/ping
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setCollectionVar("persistedCollectionToken", "collection-value-456");
|
||||
}
|
||||
|
||||
tests {
|
||||
test("should set collection var", function() {
|
||||
const val = bru.getCollectionVar("persistedCollectionToken");
|
||||
expect(val).to.equal("collection-value-456");
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
meta {
|
||||
name: set-env-var
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{host}}/ping
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setEnvVar("persistedToken", "test-value-123");
|
||||
}
|
||||
|
||||
tests {
|
||||
test("should set env var", function() {
|
||||
const val = bru.getEnvVar("persistedToken");
|
||||
expect(val).to.equal("test-value-123");
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"collections": [
|
||||
{
|
||||
"path": "{{collectionPath}}/variable-persistence-test",
|
||||
"securityConfig": {
|
||||
"jsSandboxMode": "developer"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"lastOpenedCollections": [
|
||||
"{{collectionPath}}/variable-persistence-test"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import { test, expect } from '../../../../playwright';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { openCollection, selectEnvironment, openEnvironmentSelector } from '../../../utils/page';
|
||||
import { buildCommonLocators } from '../../../utils/page/locators';
|
||||
import { runCollection, validateRunnerResults } from '../../../utils/page/runner';
|
||||
|
||||
const PERSISTENCE_TIMEOUT = 10000;
|
||||
|
||||
test.describe('Script variable persistence to disk (developer mode)', () => {
|
||||
test('persists env var and collection var', async ({ pageWithUserData: page, collectionFixturePath }) => {
|
||||
const locators = buildCommonLocators(page);
|
||||
|
||||
await openCollection(page, 'variable-persistence-test');
|
||||
await selectEnvironment(page, 'Test');
|
||||
await runCollection(page, 'variable-persistence-test');
|
||||
|
||||
await validateRunnerResults(page, {
|
||||
totalRequests: 2,
|
||||
passed: 2,
|
||||
failed: 0
|
||||
});
|
||||
|
||||
await test.step('Verify env var visible in environment UI', async () => {
|
||||
await openEnvironmentSelector(page, 'collection');
|
||||
await locators.environment.configureButton().click();
|
||||
await expect(locators.environment.collectionEnvTab()).toBeVisible();
|
||||
|
||||
await expect(locators.environment.variableRowByName('persistedToken')).toBeVisible();
|
||||
await expect(locators.environment.variableValue('persistedToken')).toContainText('test-value-123');
|
||||
|
||||
await locators.environment.collectionEnvTab().hover();
|
||||
await locators.environment.collectionEnvTab().getByTestId('request-tab-close-icon').click({ force: true });
|
||||
});
|
||||
|
||||
await test.step('Verify env var persisted to environments/Test.bru', async () => {
|
||||
const envFilePath = path.join(collectionFixturePath!, 'variable-persistence-test', 'environments', 'Test.bru');
|
||||
await expect.poll(() => {
|
||||
const content = fs.readFileSync(envFilePath, 'utf8');
|
||||
return content.includes('persistedToken') && content.includes('test-value-123');
|
||||
}, { timeout: PERSISTENCE_TIMEOUT }).toBe(true);
|
||||
});
|
||||
|
||||
await test.step('Verify collection var persisted to collection.bru', async () => {
|
||||
const collectionBruPath = path.join(collectionFixturePath!, 'variable-persistence-test', 'collection.bru');
|
||||
await expect.poll(() => {
|
||||
const content = fs.readFileSync(collectionBruPath, 'utf8');
|
||||
return content.includes('persistedCollectionToken') && content.includes('collection-value-456');
|
||||
}, { timeout: PERSISTENCE_TIMEOUT }).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user