refactor: comment out unused APIs (#7323)

* refactor: comment out unused API hints in autocomplete.js

* refactor: comment out unused API translations in postman and bruno translators

Temporarily disable certain API translations due to UI update issues affecting their functionality. A note has been added to restore these translations once the UI fixes are implemented.

* refactor: temporarily skip tests for collection variable translations due to UI update issues

Commented out tests related to `setCollectionVar`, `deleteCollectionVar`, and related functionalities until the necessary UI updates are implemented. A note has been added to restore these tests once the fixes are live.

* refactor: comment out variable deletion and retrieval methods due to UI sync issues

* revert: ping.bru

* refactor: update postman translation tests to enable previously skipped cases
This commit is contained in:
sanish chirayath
2026-03-04 18:00:10 +05:30
committed by GitHub
parent 75c3ab8032
commit 17c3dc0e2b
21 changed files with 270 additions and 149 deletions

View File

@@ -3,6 +3,9 @@ import { mockDataFunctions } from '@usebruno/common';
const CodeMirror = require('codemirror');
// Static API hints - Bruno JavaScript API (subgrouped by category)
// TODO: Restore the commented-out APIs once the UI update fixes are live.
// Currently these APIs only work within the request lifecycle but fail to update the UI tables.
// e.g., setCollectionVar only sets the variable in the request lifecycle, fails to update the table in the UI.
const STATIC_API_HINTS = {
req: [
'req',
@@ -67,11 +70,11 @@ const STATIC_API_HINTS = {
'bru.getEnvVar(key)',
'bru.getFolderVar(key)',
'bru.getCollectionVar(key)',
'bru.setCollectionVar(key, value)',
// 'bru.setCollectionVar(key, value)',
'bru.hasCollectionVar(key)',
'bru.deleteCollectionVar(key)',
'bru.deleteAllCollectionVars()',
'bru.getAllCollectionVars()',
// 'bru.deleteCollectionVar(key)',
// 'bru.deleteAllCollectionVars()',
// 'bru.getAllCollectionVars()',
'bru.setEnvVar(key, value)',
'bru.setEnvVar(key, value, options)',
'bru.deleteEnvVar(key)',
@@ -96,9 +99,9 @@ const STATIC_API_HINTS = {
'bru.getOauth2CredentialVar(key)',
'bru.getGlobalEnvVar(key)',
'bru.setGlobalEnvVar(key, value)',
'bru.deleteGlobalEnvVar(key)',
// 'bru.deleteGlobalEnvVar(key)',
'bru.getAllGlobalEnvVars()',
'bru.deleteAllGlobalEnvVars()',
// 'bru.deleteAllGlobalEnvVars()',
'bru.runner',
'bru.runner.setNextRequest(requestName)',
'bru.runner.skipRequest()',

View File

@@ -1,5 +1,8 @@
import translateCode from '../utils/postman-to-bruno-translator';
// TODO: Restore the commented-out translations once the UI update fixes are live.
// Currently these APIs only work within the request lifecycle but fail to update the UI tables.
// e.g., setCollectionVar only sets the variable in the request lifecycle, fails to update the table in the UI.
const replacements = {
'pm\\.environment\\.get\\(': 'bru.getEnvVar(',
'pm\\.environment\\.set\\(': 'bru.setEnvVar(',
@@ -7,11 +10,11 @@ const replacements = {
'pm\\.variables\\.set\\(': 'bru.setVar(',
'pm\\.variables\\.replaceIn\\(': 'bru.interpolate(',
'pm\\.collectionVariables\\.get\\(': 'bru.getCollectionVar(',
'pm\\.collectionVariables\\.set\\(': 'bru.setCollectionVar(',
// 'pm\\.collectionVariables\\.set\\(': 'bru.setCollectionVar(',
'pm\\.collectionVariables\\.has\\(': 'bru.hasCollectionVar(',
'pm\\.collectionVariables\\.unset\\(': 'bru.deleteCollectionVar(',
'pm\\.collectionVariables\\.clear\\(': 'bru.deleteAllCollectionVars(',
'pm\\.collectionVariables\\.toObject\\(': 'bru.getAllCollectionVars(',
// 'pm\\.collectionVariables\\.unset\\(': 'bru.deleteCollectionVar(',
// 'pm\\.collectionVariables\\.clear\\(': 'bru.deleteAllCollectionVars(',
// 'pm\\.collectionVariables\\.toObject\\(': 'bru.getAllCollectionVars(',
'pm\\.setNextRequest\\(': 'bru.setNextRequest(',
'pm\\.test\\(': 'test(',
'pm.response.to.have\\.status\\(': 'expect(res.getStatus()).to.equal(',
@@ -25,9 +28,9 @@ const replacements = {
'pm\\.response\\.responseTime': 'res.getResponseTime()',
'pm\\.globals\\.set\\(': 'bru.setGlobalEnvVar(',
'pm\\.globals\\.get\\(': 'bru.getGlobalEnvVar(',
'pm\\.globals\\.unset\\(': 'bru.deleteGlobalEnvVar(',
// 'pm\\.globals\\.unset\\(': 'bru.deleteGlobalEnvVar(',
'pm\\.globals\\.toObject\\(': 'bru.getAllGlobalEnvVars(',
'pm\\.globals\\.clear\\(': 'bru.deleteAllGlobalEnvVars(',
// 'pm\\.globals\\.clear\\(': 'bru.deleteAllGlobalEnvVars(',
'pm\\.environment\\.toObject\\(': 'bru.getAllEnvVars(',
'pm\\.environment\\.clear\\(': 'bru.deleteAllEnvVars(',
'pm\\.variables\\.toObject\\(': 'bru.getAllVars(',

View File

@@ -13,13 +13,16 @@ const j = require('jscodeshift');
* Simple 1:1 translations from Bruno helpers to Postman helpers.
* These are direct member expression replacements.
*/
// TODO: Restore the commented-out translations once the UI update fixes are live.
// Currently these APIs only work within the request lifecycle but fail to update the UI tables.
// e.g., setCollectionVar only sets the variable in the request lifecycle, fails to update the table in the UI.
const simpleTranslations = {
// Global variables
'bru.getGlobalEnvVar': 'pm.globals.get',
'bru.setGlobalEnvVar': 'pm.globals.set',
'bru.deleteGlobalEnvVar': 'pm.globals.unset',
// 'bru.deleteGlobalEnvVar': 'pm.globals.unset',
'bru.getAllGlobalEnvVars': 'pm.globals.toObject',
'bru.deleteAllGlobalEnvVars': 'pm.globals.clear',
// 'bru.deleteAllGlobalEnvVars': 'pm.globals.clear',
// Environment variables
'bru.getEnvVar': 'pm.environment.get',
@@ -40,11 +43,11 @@ const simpleTranslations = {
// Collection variables
'bru.getCollectionVar': 'pm.collectionVariables.get',
'bru.setCollectionVar': 'pm.collectionVariables.set',
// 'bru.setCollectionVar': 'pm.collectionVariables.set',
'bru.hasCollectionVar': 'pm.collectionVariables.has',
'bru.deleteCollectionVar': 'pm.collectionVariables.unset',
'bru.getAllCollectionVars': 'pm.collectionVariables.toObject',
'bru.deleteAllCollectionVars': 'pm.collectionVariables.clear',
// 'bru.deleteCollectionVar': 'pm.collectionVariables.unset',
// 'bru.getAllCollectionVars': 'pm.collectionVariables.toObject',
// 'bru.deleteAllCollectionVars': 'pm.collectionVariables.clear',
// Folder variables
'bru.getFolderVar': 'pm.variables.get',

View File

@@ -4,14 +4,17 @@ const j = require('jscodeshift');
const cloneDeep = require('lodash/cloneDeep');
// Simple 1:1 translations for straightforward replacements
// TODO: Restore the commented-out translations once the UI update fixes are live.
// Currently these APIs only work within the request lifecycle but fail to update the UI tables.
// e.g., setCollectionVar only sets the variable in the request lifecycle, fails to update the table in the UI.
const simpleTranslations = {
// Global Variables
'pm.globals.get': 'bru.getGlobalEnvVar',
'pm.globals.set': 'bru.setGlobalEnvVar',
'pm.globals.replaceIn': 'bru.interpolate',
'pm.globals.unset': 'bru.deleteGlobalEnvVar',
// 'pm.globals.unset': 'bru.deleteGlobalEnvVar',
'pm.globals.toObject': 'bru.getAllGlobalEnvVars',
'pm.globals.clear': 'bru.deleteAllGlobalEnvVars',
// 'pm.globals.clear': 'bru.deleteAllGlobalEnvVars',
// Environment variables
'pm.environment.get': 'bru.getEnvVar',
@@ -30,12 +33,12 @@ const simpleTranslations = {
'pm.variables.replaceIn': 'bru.interpolate',
// Collection variables
'pm.collectionVariables.get': 'bru.getCollectionVar',
'pm.collectionVariables.set': 'bru.setCollectionVar',
// 'pm.collectionVariables.set': 'bru.setCollectionVar',
'pm.collectionVariables.has': 'bru.hasCollectionVar',
'pm.collectionVariables.unset': 'bru.deleteCollectionVar',
// 'pm.collectionVariables.unset': 'bru.deleteCollectionVar',
'pm.collectionVariables.replaceIn': 'bru.interpolate',
'pm.collectionVariables.clear': 'bru.deleteAllCollectionVars',
'pm.collectionVariables.toObject': 'bru.getAllCollectionVars',
// 'pm.collectionVariables.clear': 'bru.deleteAllCollectionVars',
// 'pm.collectionVariables.toObject': 'bru.getAllCollectionVars',
// Request flow control
'pm.setNextRequest': 'bru.setNextRequest',

View File

@@ -58,7 +58,8 @@ describe('Bruno to Postman Variables Translation', () => {
expect(translatedCode).toBe('pm.collectionVariables.get("baseUrl");');
});
it('should translate bru.setCollectionVar', () => {
// TODO: Restore once UI update fixes are live for setCollectionVar
it.skip('should translate bru.setCollectionVar', () => {
const code = 'bru.setCollectionVar("baseUrl", "https://api.example.com");';
const translatedCode = translateBruToPostman(code);
expect(translatedCode).toBe('pm.collectionVariables.set("baseUrl", "https://api.example.com");');
@@ -70,19 +71,22 @@ describe('Bruno to Postman Variables Translation', () => {
expect(translatedCode).toBe('pm.collectionVariables.has("baseUrl");');
});
it('should translate bru.deleteCollectionVar', () => {
// TODO: Restore once UI update fixes are live for deleteCollectionVar
it.skip('should translate bru.deleteCollectionVar', () => {
const code = 'bru.deleteCollectionVar("baseUrl");';
const translatedCode = translateBruToPostman(code);
expect(translatedCode).toBe('pm.collectionVariables.unset("baseUrl");');
});
it('should translate bru.getAllCollectionVars', () => {
// TODO: Restore once UI update fixes are live for getAllCollectionVars
it.skip('should translate bru.getAllCollectionVars', () => {
const code = 'const vars = bru.getAllCollectionVars();';
const translatedCode = translateBruToPostman(code);
expect(translatedCode).toBe('const vars = pm.collectionVariables.toObject();');
});
it('should translate bru.deleteAllCollectionVars', () => {
// TODO: Restore once UI update fixes are live for deleteAllCollectionVars
it.skip('should translate bru.deleteAllCollectionVars', () => {
const code = 'bru.deleteAllCollectionVars();';
const translatedCode = translateBruToPostman(code);
expect(translatedCode).toBe('pm.collectionVariables.clear();');

View File

@@ -7,11 +7,15 @@ describe('postmanTranslations - comment handling', () => {
const data = pm.environment.get('key');
pm.collectionVariables.set('key', data);
`;
const expectedOutput = `
console.log('This script does not contain pm commands.');
const data = bru.getEnvVar('key');
bru.setCollectionVar('key', data);
`;
const result = postmanTranslation(inputScript);
expect(result).toContain('console.log(\'This script does not contain pm commands.\');');
expect(result).toContain('const data = bru.getEnvVar(\'key\');');
});
// TODO: Restore once UI update fixes are live for setCollectionVar
test.skip('should translate pm.collectionVariables.set to bru.setCollectionVar', () => {
const inputScript = 'pm.collectionVariables.set(\'key\', data);';
const expectedOutput = 'bru.setCollectionVar(\'key\', data);';
expect(postmanTranslation(inputScript)).toBe(expectedOutput);
});

View File

@@ -1,25 +1,42 @@
import postmanTranslation from '../../../src/postman/postman-translations';
describe('postmanTranslations - variables commands', () => {
test('should translate variable commands correctly', () => {
test('should translate environment variable commands', () => {
const inputScript = `
pm.environment.get('key');
pm.environment.set('key', 'value');
`;
const result = postmanTranslation(inputScript);
expect(result).toContain('bru.getEnvVar(\'key\')');
expect(result).toContain('bru.setEnvVar(\'key\', \'value\')');
});
test('should translate runtime variable commands', () => {
const inputScript = `
pm.variables.get('key');
pm.variables.set('key', 'value');
pm.collectionVariables.get('key');
pm.collectionVariables.set('key', 'value');
pm.expect(pm.environment.has('key')).to.be.true;
`;
const expectedOutput = `
bru.getEnvVar('key');
bru.setEnvVar('key', 'value');
bru.getVar('key');
bru.setVar('key', 'value');
bru.getCollectionVar('key');
bru.setCollectionVar('key', 'value');
expect(bru.getEnvVar('key') !== undefined && bru.getEnvVar('key') !== null).to.be.true;
`;
expect(postmanTranslation(inputScript)).toBe(expectedOutput);
const result = postmanTranslation(inputScript);
expect(result).toContain('bru.getVar(\'key\')');
expect(result).toContain('bru.setVar(\'key\', \'value\')');
});
test('should translate pm.collectionVariables.get', () => {
const inputScript = 'pm.collectionVariables.get(\'key\');';
const result = postmanTranslation(inputScript);
expect(result).toContain('bru.getCollectionVar(\'key\')');
});
test('should translate pm.expect with pm.environment.has', () => {
const inputScript = 'pm.expect(pm.environment.has(\'key\')).to.be.true;';
const result = postmanTranslation(inputScript);
expect(result).toContain('bru.getEnvVar(\'key\') !== undefined && bru.getEnvVar(\'key\') !== null');
expect(result).toContain('.to.be.true');
});
// TODO: Restore once UI update fixes are live for setCollectionVar
test.skip('should translate pm.collectionVariables.set to bru.setCollectionVar', () => {
const inputScript = 'pm.collectionVariables.set(\'key\', \'value\');';
expect(postmanTranslation(inputScript)).toBe('bru.setCollectionVar(\'key\', \'value\');');
});
});

View File

@@ -93,13 +93,18 @@ describe('Combined API Features Translation', () => {
expect(translatedCode).not.toContain('pm.test("Auth flow works", function() {');
expect(translatedCode).not.toContain('pm.expect(response.authenticated).to.be.true;');
expect(translatedCode).not.toContain('pm.environment.set("userId", response.user.id);');
expect(translatedCode).not.toContain('pm.collectionVariables.set("sessionId", response.session.id);');
expect(translatedCode).toContain('const token = bru.getEnvVar("authToken");');
expect(translatedCode).toContain('test("Auth flow works", function() {');
expect(translatedCode).toContain('const response = res.getBody();');
expect(translatedCode).toContain('expect(response.authenticated).to.be.true;');
expect(translatedCode).toContain('bru.setEnvVar("userId", response.user.id);');
expect(translatedCode).toContain('bru.setCollectionVar("sessionId", response.session.id);');
});
// TODO: Restore once UI update fixes are live for setCollectionVar
it.skip('should translate pm.collectionVariables.set in a combined code block', () => {
const code = 'pm.collectionVariables.set("sessionId", response.session.id);';
const translatedCode = translateCode(code);
expect(translatedCode).toBe('bru.setCollectionVar("sessionId", response.session.id);');
});
// Nested expressions
@@ -109,7 +114,8 @@ describe('Combined API Features Translation', () => {
expect(translatedCode).toBe('bru.setEnvVar("computed", bru.getVar("base") + "-suffix");');
});
it('should handle more complex nested expressions', () => {
// TODO: Restore once UI update fixes are live for setCollectionVar
it.skip('should handle more complex nested expressions', () => {
const code = 'pm.collectionVariables.set("fullPath", pm.environment.get("baseUrl") + pm.variables.get("endpoint"));';
const translatedCode = translateCode(code);
expect(translatedCode).toBe('bru.setCollectionVar("fullPath", bru.getEnvVar("baseUrl") + bru.getVar("endpoint"));');
@@ -347,14 +353,19 @@ describe('Combined API Features Translation', () => {
const translatedCode = translateCode(code);
expect(translatedCode).toBe(`
function processResponse() {
test("Status code is 200", function() { expect(res.getStatus()).to.equal(200); });
bru.setEnvVar("userId", res.getBody().userId);
bru.setVar("token", res.getBody().token);
bru.setCollectionVar("sessionId", res.getBody().sessionId);
}
`);
expect(translatedCode).toContain('test("Status code is 200", function() { expect(res.getStatus()).to.equal(200); });');
expect(translatedCode).toContain('bru.setEnvVar("userId", res.getBody().userId);');
expect(translatedCode).toContain('bru.setVar("token", res.getBody().token);');
});
// TODO: Restore once UI update fixes are live for setCollectionVar
it.skip('should translate pm.collectionVariables alias set inside functions', () => {
const code = `
const tempCollVars = pm.collectionVariables;
tempCollVars.set("sessionId", "value");
`;
const translatedCode = translateCode(code);
expect(translatedCode).toContain('bru.setCollectionVar("sessionId", "value");');
});
it('should nested pm commands', () => {

View File

@@ -34,18 +34,23 @@ describe('Multiline Syntax Handling', () => {
`);
});
it('should handle multiline collection variable syntax', () => {
it('should handle multiline collection variable get syntax', () => {
const code = `
const apiKey = pm.collectionVariables
.get("apiKey");
`;
const translatedCode = translateCode(code);
expect(translatedCode).toContain('const apiKey = bru.getCollectionVar("apiKey")');
});
// TODO: Restore once UI update fixes are live for setCollectionVar
it.skip('should handle multiline collection variable set syntax', () => {
const code = `
pm.collectionVariables
.set("lastRun", new Date().toISOString());
`;
const translatedCode = translateCode(code);
expect(translatedCode).toBe(`
const apiKey = bru.getCollectionVar("apiKey");
bru.setCollectionVar("lastRun", new Date().toISOString());
`);
expect(translatedCode).toContain('bru.setCollectionVar("lastRun", new Date().toISOString())');
});
it('should handle complex environment.has transformation with multiline syntax', () => {
@@ -193,7 +198,7 @@ describe('Multiline Syntax Handling', () => {
it('should handle a comprehensive script with various multiline formats', () => {
const code = `
// This comprehensive script tests different multiline styles and whitespace variations
// Environment variables with different formatting styles
const baseUrl = pm.environment.get("baseUrl");
const apiKey = pm
@@ -201,39 +206,39 @@ describe('Multiline Syntax Handling', () => {
.get("apiKey");
const userId = pm.environment
.get("userId");
// Mix of variable styles
pm.variables.set("testId", "test-" + Date.now());
pm
.variables
.set("timestamp", new Date().toISOString());
// Collection variables with inconsistent spacing
pm.collectionVariables
.set("lastRun", new Date());
// Complex conditionals with multiline expressions
if (pm
.environment
.has("apiKey") &&
.has("apiKey") &&
pm.variables.has("testId")) {
// Testing response with mixed syntax styles
pm.test("Response validation", function() {
// Normal style
pm.response.to.have.status(200);
// Multiline with different indentation
pm
.response
.to
.have
.header("content-type");
pm.response
.to.have
.jsonBody("success", true);
// Extreme indentation
pm
.response
@@ -242,7 +247,7 @@ describe('Multiline Syntax Handling', () => {
.have
.jsonBody("error");
});
// Flow control with mixed styles
if (pm.response.code === 401) {
pm.execution.setNextRequest(null);
@@ -264,9 +269,6 @@ describe('Multiline Syntax Handling', () => {
expect(translatedCode).toContain('bru.setVar("testId", "test-" + Date.now())');
expect(translatedCode).toContain('bru.setVar("timestamp", new Date().toISOString())');
// Check collection variables
expect(translatedCode).toContain('bru.setCollectionVar("lastRun", new Date())');
// Check complex conditionals
expect(translatedCode).toContain('if (bru.getEnvVar("apiKey") !== undefined && bru.getEnvVar("apiKey") !== null &&');
expect(translatedCode).toContain('bru.hasVar("testId"))');
@@ -280,4 +282,14 @@ describe('Multiline Syntax Handling', () => {
expect(translatedCode).toContain('bru.runner.stopExecution()');
expect(translatedCode).toContain('bru.runner.setNextRequest("Next API Call")');
});
// TODO: Restore once UI update fixes are live for setCollectionVar
it.skip('should translate multiline pm.collectionVariables.set in comprehensive script', () => {
const code = `
pm.collectionVariables
.set("lastRun", new Date());
`;
const translatedCode = translateCode(code);
expect(translatedCode).toContain('bru.setCollectionVar("lastRun", new Date())');
});
});

View File

@@ -281,6 +281,12 @@ describe('Response Translation', () => {
const translatedCode = translateCode(code);
expect(translatedCode).toContain('const items = res.getBody().items;');
});
// TODO: Restore once UI update fixes are live for setCollectionVar
it.skip('should translate pm.collectionVariables.set with array access pattern', () => {
const code = 'pm.collectionVariables.set("item_" + i, items[i].id);';
const translatedCode = translateCode(code);
expect(translatedCode).toContain('bru.setCollectionVar("item_" + i, items[i].id);');
});

View File

@@ -67,6 +67,12 @@ describe('Testing Framework Translation', () => {
expect(translatedCode).toContain('const response = res.getBody();');
expect(translatedCode).toContain('expect(response.authenticated).to.be.true;');
expect(translatedCode).toContain('bru.setEnvVar("userId", response.user.id);');
});
// TODO: Restore once UI update fixes are live for setCollectionVar
it.skip('should translate pm.collectionVariables.set inside test functions', () => {
const code = 'pm.collectionVariables.set("sessionId", response.session.id);';
const translatedCode = translateCode(code);
expect(translatedCode).toContain('bru.setCollectionVar("sessionId", response.session.id);');
});

View File

@@ -71,7 +71,8 @@ describe('Variables Translation', () => {
expect(translatedCode).toBe('bru.getCollectionVar("apiUrl");');
});
it('should translate pm.collectionVariables.set', () => {
// TODO: Restore once UI update fixes are live for setCollectionVar
it.skip('should translate pm.collectionVariables.set', () => {
const code = 'pm.collectionVariables.set("token", jsonData.token);';
const translatedCode = translateCode(code);
@@ -85,7 +86,8 @@ describe('Variables Translation', () => {
expect(translatedCode).toBe('bru.hasCollectionVar("authToken");');
});
it('should translate pm.collectionVariables.unset', () => {
// TODO: Restore once UI update fixes are live for deleteCollectionVar
it.skip('should translate pm.collectionVariables.unset', () => {
const code = 'pm.collectionVariables.unset("tempVar");';
const translatedCode = translateCode(code);
@@ -124,7 +126,8 @@ describe('Variables Translation', () => {
});
// Alias tests for collection variables
it('should handle collection variables aliases', () => {
// TODO: Restore once UI update fixes are live for setCollectionVar/deleteCollectionVar
it.skip('should handle collection variables aliases', () => {
const code = `
const collVars = pm.collectionVariables;
const has = collVars.has("test");
@@ -180,7 +183,8 @@ describe('Variables Translation', () => {
expect(translatedCode).toContain('bru.setVar("requestTime", new Date().toISOString());');
});
it('should handle all collection variable methods together', () => {
// TODO: Restore once UI update fixes are live for setCollectionVar/deleteCollectionVar
it.skip('should handle all collection variable methods together', () => {
const code = `
// All collection variable methods
const hasApiUrl = pm.collectionVariables.has("apiUrl");
@@ -198,7 +202,8 @@ describe('Variables Translation', () => {
expect(translatedCode).toContain('bru.deleteCollectionVar("tempVar");');
});
it('should handle more complex nested expressions with variables', () => {
// TODO: Restore once UI update fixes are live for setCollectionVar
it.skip('should handle more complex nested expressions with variables', () => {
const code = 'pm.collectionVariables.set("fullPath", pm.environment.get("baseUrl") + pm.variables.get("endpoint"));';
const translatedCode = translateCode(code);

View File

@@ -257,21 +257,25 @@ class Bru {
this.globalEnvironmentVariables[key] = value;
}
deleteGlobalEnvVar(key) {
delete this.globalEnvironmentVariables[key];
}
// TODO: deleteGlobalEnvVar works in the request lifecycle but does not update the UI.
// Re-enable once the UI sync issue is resolved.
// deleteGlobalEnvVar(key) {
// delete this.globalEnvironmentVariables[key];
// }
getAllGlobalEnvVars() {
return Object.assign({}, this.globalEnvironmentVariables);
}
deleteAllGlobalEnvVars() {
for (let key in this.globalEnvironmentVariables) {
if (this.globalEnvironmentVariables.hasOwnProperty(key)) {
delete this.globalEnvironmentVariables[key];
}
}
}
// TODO: deleteAllGlobalEnvVars works in the request lifecycle but does not update the UI.
// Re-enable once the UI sync issue is resolved.
// deleteAllGlobalEnvVars() {
// for (let key in this.globalEnvironmentVariables) {
// if (this.globalEnvironmentVariables.hasOwnProperty(key)) {
// delete this.globalEnvironmentVariables[key];
// }
// }
// }
getOauth2CredentialVar(key) {
return this.interpolate(this.oauth2CredentialVariables[key]);
@@ -345,40 +349,48 @@ class Bru {
return this.interpolate(this.collectionVariables[key]);
}
setCollectionVar(key, value) {
if (!key) {
throw new Error('Creating a variable without specifying a name is not allowed.');
}
if (variableNameRegex.test(key) === false) {
throw new Error(
`Variable name: "${key}" contains invalid characters!`
+ ' Names must only contain alpha-numeric characters, "-", "_", "."'
);
}
this.collectionVariables[key] = value;
}
// TODO: setCollectionVar works in the request lifecycle but does not update the UI.
// Re-enable once the UI sync issue is resolved.
// setCollectionVar(key, value) {
// if (!key) {
// throw new Error('Creating a variable without specifying a name is not allowed.');
// }
//
// if (variableNameRegex.test(key) === false) {
// throw new Error(
// `Variable name: "${key}" contains invalid characters!`
// + ' Names must only contain alpha-numeric characters, "-", "_", "."'
// );
// }
//
// this.collectionVariables[key] = value;
// }
hasCollectionVar(key) {
return Object.hasOwn(this.collectionVariables, key);
}
deleteCollectionVar(key) {
delete this.collectionVariables[key];
}
// TODO: deleteCollectionVar works in the request lifecycle but does not update the UI.
// Re-enable once the UI sync issue is resolved.
// deleteCollectionVar(key) {
// delete this.collectionVariables[key];
// }
deleteAllCollectionVars() {
for (let key in this.collectionVariables) {
if (this.collectionVariables.hasOwnProperty(key)) {
delete this.collectionVariables[key];
}
}
}
// TODO: deleteAllCollectionVars works in the request lifecycle but does not update the UI.
// Re-enable once the UI sync issue is resolved.
// deleteAllCollectionVars() {
// for (let key in this.collectionVariables) {
// if (this.collectionVariables.hasOwnProperty(key)) {
// delete this.collectionVariables[key];
// }
// }
// }
getAllCollectionVars() {
return Object.assign({}, this.collectionVariables);
}
// TODO: getAllCollectionVars works in the request lifecycle but does not update the UI.
// Re-enable once the UI sync issue is resolved.
// getAllCollectionVars() {
// return Object.assign({}, this.collectionVariables);
// }
getFolderVar(key) {
return this.interpolate(this.folderVariables[key]);

View File

@@ -101,11 +101,13 @@ const addBruShimToContext = (vm, bru) => {
vm.setProp(bruObject, 'setGlobalEnvVar', setGlobalEnvVar);
setGlobalEnvVar.dispose();
let deleteGlobalEnvVar = vm.newFunction('deleteGlobalEnvVar', function (key) {
bru.deleteGlobalEnvVar(vm.dump(key));
});
vm.setProp(bruObject, 'deleteGlobalEnvVar', deleteGlobalEnvVar);
deleteGlobalEnvVar.dispose();
// TODO: deleteGlobalEnvVar works in the request lifecycle but does not update the UI.
// Re-enable once the UI sync issue is resolved.
// let deleteGlobalEnvVar = vm.newFunction('deleteGlobalEnvVar', function (key) {
// bru.deleteGlobalEnvVar(vm.dump(key));
// });
// vm.setProp(bruObject, 'deleteGlobalEnvVar', deleteGlobalEnvVar);
// deleteGlobalEnvVar.dispose();
let getAllGlobalEnvVars = vm.newFunction('getAllGlobalEnvVars', function () {
return marshallToVm(bru.getAllGlobalEnvVars(), vm);
@@ -113,11 +115,13 @@ const addBruShimToContext = (vm, bru) => {
vm.setProp(bruObject, 'getAllGlobalEnvVars', getAllGlobalEnvVars);
getAllGlobalEnvVars.dispose();
let deleteAllGlobalEnvVars = vm.newFunction('deleteAllGlobalEnvVars', function () {
bru.deleteAllGlobalEnvVars();
});
vm.setProp(bruObject, 'deleteAllGlobalEnvVars', deleteAllGlobalEnvVars);
deleteAllGlobalEnvVars.dispose();
// TODO: deleteAllGlobalEnvVars works in the request lifecycle but does not update the UI.
// Re-enable once the UI sync issue is resolved.
// let deleteAllGlobalEnvVars = vm.newFunction('deleteAllGlobalEnvVars', function () {
// bru.deleteAllGlobalEnvVars();
// });
// vm.setProp(bruObject, 'deleteAllGlobalEnvVars', deleteAllGlobalEnvVars);
// deleteAllGlobalEnvVars.dispose();
let hasVar = vm.newFunction('hasVar', function (key) {
return marshallToVm(bru.hasVar(vm.dump(key)), vm);
@@ -209,11 +213,13 @@ const addBruShimToContext = (vm, bru) => {
vm.setProp(bruObject, 'getCollectionVar', getCollectionVar);
getCollectionVar.dispose();
let setCollectionVar = vm.newFunction('setCollectionVar', function (key, value) {
bru.setCollectionVar(vm.dump(key), vm.dump(value));
});
vm.setProp(bruObject, 'setCollectionVar', setCollectionVar);
setCollectionVar.dispose();
// TODO: setCollectionVar works in the request lifecycle but does not update the UI.
// Re-enable once the UI sync issue is resolved.
// let setCollectionVar = vm.newFunction('setCollectionVar', function (key, value) {
// bru.setCollectionVar(vm.dump(key), vm.dump(value));
// });
// vm.setProp(bruObject, 'setCollectionVar', setCollectionVar);
// setCollectionVar.dispose();
let hasCollectionVar = vm.newFunction('hasCollectionVar', function (key) {
return marshallToVm(bru.hasCollectionVar(vm.dump(key)), vm);
@@ -221,23 +227,29 @@ const addBruShimToContext = (vm, bru) => {
vm.setProp(bruObject, 'hasCollectionVar', hasCollectionVar);
hasCollectionVar.dispose();
let deleteCollectionVar = vm.newFunction('deleteCollectionVar', function (key) {
bru.deleteCollectionVar(vm.dump(key));
});
vm.setProp(bruObject, 'deleteCollectionVar', deleteCollectionVar);
deleteCollectionVar.dispose();
// TODO: deleteCollectionVar works in the request lifecycle but does not update the UI.
// Re-enable once the UI sync issue is resolved.
// let deleteCollectionVar = vm.newFunction('deleteCollectionVar', function (key) {
// bru.deleteCollectionVar(vm.dump(key));
// });
// vm.setProp(bruObject, 'deleteCollectionVar', deleteCollectionVar);
// deleteCollectionVar.dispose();
let deleteAllCollectionVars = vm.newFunction('deleteAllCollectionVars', function () {
bru.deleteAllCollectionVars();
});
vm.setProp(bruObject, 'deleteAllCollectionVars', deleteAllCollectionVars);
deleteAllCollectionVars.dispose();
// TODO: deleteAllCollectionVars works in the request lifecycle but does not update the UI.
// Re-enable once the UI sync issue is resolved.
// let deleteAllCollectionVars = vm.newFunction('deleteAllCollectionVars', function () {
// bru.deleteAllCollectionVars();
// });
// vm.setProp(bruObject, 'deleteAllCollectionVars', deleteAllCollectionVars);
// deleteAllCollectionVars.dispose();
let getAllCollectionVars = vm.newFunction('getAllCollectionVars', function () {
return marshallToVm(bru.getAllCollectionVars(), vm);
});
vm.setProp(bruObject, 'getAllCollectionVars', getAllCollectionVars);
getAllCollectionVars.dispose();
// TODO: getAllCollectionVars works in the request lifecycle but does not update the UI.
// Re-enable once the UI sync issue is resolved.
// let getAllCollectionVars = vm.newFunction('getAllCollectionVars', function () {
// return marshallToVm(bru.getAllCollectionVars(), vm);
// });
// vm.setProp(bruObject, 'getAllCollectionVars', getAllCollectionVars);
// getAllCollectionVars.dispose();
let getTestResults = vm.newFunction('getTestResults', () => {
const promise = vm.newPromise();

View File

@@ -12,4 +12,4 @@ get {
script:pre-request {
bru.runner.stopExecution();
}
}

View File

@@ -11,6 +11,9 @@ get {
}
script:pre-request {
// TODO: skipped because deleteAllCollectionVars does not update the UI
bru.runner.skipRequest();
return;
bru.setCollectionVar("testDelAllCollectionA", "a");
bru.setCollectionVar("testDelAllCollectionB", "b");
}

View File

@@ -11,6 +11,9 @@ get {
}
script:pre-request {
// TODO: skipped because deleteAllGlobalEnvVars does not update the UI
bru.runner.skipRequest();
return;
bru.setGlobalEnvVar("testDelAllGlobalA", "a");
bru.setGlobalEnvVar("testDelAllGlobalB", "b");
}

View File

@@ -11,6 +11,9 @@ get {
}
script:pre-request {
// TODO: skipped because deleteCollectionVar does not update the UI
bru.runner.skipRequest();
return;
bru.setCollectionVar("testDeleteCollectionVar", "to-be-deleted");
bru.deleteCollectionVar("testDeleteCollectionVar");
}

View File

@@ -11,6 +11,9 @@ get {
}
script:pre-request {
// TODO: skipped because deleteGlobalEnvVar does not update the UI
bru.runner.skipRequest();
return;
bru.setGlobalEnvVar("testDeleteGlobalEnvVar", "to-be-deleted");
bru.deleteGlobalEnvVar("testDeleteGlobalEnvVar");
}

View File

@@ -11,6 +11,9 @@ get {
}
script:pre-request {
// TODO: skipped because getAllCollectionVars does not update the UI
bru.runner.skipRequest();
return;
bru.setCollectionVar("testCollectionA", "valueA");
bru.setCollectionVar("testCollectionB", "valueB");
}

View File

@@ -10,6 +10,11 @@ get {
auth: none
}
script:pre-request {
// TODO: skipped because setCollectionVar does not update the UI
bru.runner.skipRequest();
}
script:post-response {
bru.setCollectionVar("testSetCollectionVar", "collection-test-value")
}