From 62ee62e12edee87c66b8c6a128894b5c3e503fa5 Mon Sep 17 00:00:00 2001 From: sanish-bruno Date: Mon, 22 Jun 2026 20:08:11 +0530 Subject: [PATCH] feat(translations): restore commented-out collection and global variable methods - Reintroduced translations for `setCollectionVar`, `deleteCollectionVar`, `deleteAllCollectionVars`, and their global counterparts in the Postman to Bruno and Bruno to Postman translators. - Updated tests to validate the translations for these methods, ensuring accurate functionality and consistency across variable management. - Removed outdated comments regarding UI updates, reflecting the current state of the implementation. --- .../src/postman/postman-translations.js | 15 +++---- .../src/utils/bruno-to-postman-translator.js | 15 +++---- .../src/utils/postman-to-bruno-translator.js | 15 +++---- .../variables.test.js | 24 +++++++---- .../postman-comments.spec.js | 3 +- .../postman-variables.spec.js | 28 +++++++++++- .../transpiler-tests/combined.test.js | 9 ++-- .../transpiler-tests/multiline-syntax.test.js | 6 +-- .../transpiler-tests/response.test.js | 3 +- .../testing-framework.test.js | 3 +- .../transpiler-tests/variables.test.js | 43 ++++++++++++++----- 11 files changed, 101 insertions(+), 63 deletions(-) diff --git a/packages/bruno-converters/src/postman/postman-translations.js b/packages/bruno-converters/src/postman/postman-translations.js index 540e8eaa75f..602441e5a22 100644 --- a/packages/bruno-converters/src/postman/postman-translations.js +++ b/packages/bruno-converters/src/postman/postman-translations.js @@ -1,8 +1,5 @@ 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(', @@ -10,11 +7,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(', // Only the actual null literal stops the runner; the string 'null' is a valid // request name and falls through to setNextRequest. 'pm\\.setNextRequest\\(null\\)': 'bru.runner.stopExecution()', @@ -32,9 +29,9 @@ const replacements = { 'pm\\.globals\\.set\\(': 'bru.setGlobalEnvVar(', 'pm\\.globals\\.get\\(': 'bru.getGlobalEnvVar(', 'pm\\.globals\\.has\\(': 'bru.hasGlobalEnvVar(', - // '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(', diff --git a/packages/bruno-converters/src/utils/bruno-to-postman-translator.js b/packages/bruno-converters/src/utils/bruno-to-postman-translator.js index 29555f7cc88..616bcbb55c7 100644 --- a/packages/bruno-converters/src/utils/bruno-to-postman-translator.js +++ b/packages/bruno-converters/src/utils/bruno-to-postman-translator.js @@ -13,17 +13,14 @@ 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.hasGlobalEnvVar': 'pm.globals.has', - // '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', @@ -44,11 +41,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', diff --git a/packages/bruno-converters/src/utils/postman-to-bruno-translator.js b/packages/bruno-converters/src/utils/postman-to-bruno-translator.js index a70c2a83117..6b82bd19629 100644 --- a/packages/bruno-converters/src/utils/postman-to-bruno-translator.js +++ b/packages/bruno-converters/src/utils/postman-to-bruno-translator.js @@ -5,18 +5,15 @@ const cloneDeep = require('lodash/cloneDeep'); import { buildStatusAssertionEntries } from './postman-status-assertions'; // 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.has': 'bru.hasGlobalEnvVar', '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', @@ -35,12 +32,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', // Testing 'pm.test': 'test', diff --git a/packages/bruno-converters/tests/bruno/bruno-to-postman-translations/variables.test.js b/packages/bruno-converters/tests/bruno/bruno-to-postman-translations/variables.test.js index bf4dae6cf51..1c9666d7a5e 100644 --- a/packages/bruno-converters/tests/bruno/bruno-to-postman-translations/variables.test.js +++ b/packages/bruno-converters/tests/bruno/bruno-to-postman-translations/variables.test.js @@ -57,6 +57,18 @@ describe('Bruno to Postman Variables Translation', () => { expect(translatedCode).toBe('pm.globals.has("token");'); }); + it('should translate bru.deleteGlobalEnvVar', () => { + const code = 'bru.deleteGlobalEnvVar("token");'; + const translatedCode = translateBruToPostman(code); + expect(translatedCode).toBe('pm.globals.unset("token");'); + }); + + it('should translate bru.deleteAllGlobalEnvVars', () => { + const code = 'bru.deleteAllGlobalEnvVars();'; + const translatedCode = translateBruToPostman(code); + expect(translatedCode).toBe('pm.globals.clear();'); + }); + // Collection variables tests it('should translate bru.getCollectionVar', () => { const code = 'bru.getCollectionVar("baseUrl");'; @@ -64,8 +76,7 @@ describe('Bruno to Postman Variables Translation', () => { expect(translatedCode).toBe('pm.collectionVariables.get("baseUrl");'); }); - // TODO: Restore once UI update fixes are live for setCollectionVar - it.skip('should translate bru.setCollectionVar', () => { + it('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");'); @@ -77,22 +88,19 @@ describe('Bruno to Postman Variables Translation', () => { expect(translatedCode).toBe('pm.collectionVariables.has("baseUrl");'); }); - // TODO: Restore once UI update fixes are live for deleteCollectionVar - it.skip('should translate bru.deleteCollectionVar', () => { + it('should translate bru.deleteCollectionVar', () => { const code = 'bru.deleteCollectionVar("baseUrl");'; const translatedCode = translateBruToPostman(code); expect(translatedCode).toBe('pm.collectionVariables.unset("baseUrl");'); }); - // TODO: Restore once UI update fixes are live for getAllCollectionVars - it.skip('should translate bru.getAllCollectionVars', () => { + it('should translate bru.getAllCollectionVars', () => { const code = 'const vars = bru.getAllCollectionVars();'; const translatedCode = translateBruToPostman(code); expect(translatedCode).toBe('const vars = pm.collectionVariables.toObject();'); }); - // TODO: Restore once UI update fixes are live for deleteAllCollectionVars - it.skip('should translate bru.deleteAllCollectionVars', () => { + it('should translate bru.deleteAllCollectionVars', () => { const code = 'bru.deleteAllCollectionVars();'; const translatedCode = translateBruToPostman(code); expect(translatedCode).toBe('pm.collectionVariables.clear();'); diff --git a/packages/bruno-converters/tests/postman/postman-translations/postman-comments.spec.js b/packages/bruno-converters/tests/postman/postman-translations/postman-comments.spec.js index e65075c27ce..7f3c7f82963 100644 --- a/packages/bruno-converters/tests/postman/postman-translations/postman-comments.spec.js +++ b/packages/bruno-converters/tests/postman/postman-translations/postman-comments.spec.js @@ -12,8 +12,7 @@ describe('postmanTranslations - comment handling', () => { 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', () => { + test('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); diff --git a/packages/bruno-converters/tests/postman/postman-translations/postman-variables.spec.js b/packages/bruno-converters/tests/postman/postman-translations/postman-variables.spec.js index a178d422dee..9defb0e6be2 100644 --- a/packages/bruno-converters/tests/postman/postman-translations/postman-variables.spec.js +++ b/packages/bruno-converters/tests/postman/postman-translations/postman-variables.spec.js @@ -34,9 +34,33 @@ describe('postmanTranslations - variables commands', () => { 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', () => { + test('should translate pm.collectionVariables.set to bru.setCollectionVar', () => { const inputScript = 'pm.collectionVariables.set(\'key\', \'value\');'; expect(postmanTranslation(inputScript)).toBe('bru.setCollectionVar(\'key\', \'value\');'); }); + + test('should translate pm.collectionVariables.unset to bru.deleteCollectionVar', () => { + const inputScript = 'pm.collectionVariables.unset(\'key\');'; + expect(postmanTranslation(inputScript)).toBe('bru.deleteCollectionVar(\'key\');'); + }); + + test('should translate pm.collectionVariables.clear to bru.deleteAllCollectionVars', () => { + const inputScript = 'pm.collectionVariables.clear();'; + expect(postmanTranslation(inputScript)).toBe('bru.deleteAllCollectionVars();'); + }); + + test('should translate pm.collectionVariables.toObject to bru.getAllCollectionVars', () => { + const inputScript = 'const vars = pm.collectionVariables.toObject();'; + expect(postmanTranslation(inputScript)).toBe('const vars = bru.getAllCollectionVars();'); + }); + + test('should translate pm.globals.unset to bru.deleteGlobalEnvVar', () => { + const inputScript = 'pm.globals.unset(\'token\');'; + expect(postmanTranslation(inputScript)).toBe('bru.deleteGlobalEnvVar(\'token\');'); + }); + + test('should translate pm.globals.clear to bru.deleteAllGlobalEnvVars', () => { + const inputScript = 'pm.globals.clear();'; + expect(postmanTranslation(inputScript)).toBe('bru.deleteAllGlobalEnvVars();'); + }); }); diff --git a/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/combined.test.js b/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/combined.test.js index 82cafe46fdf..4e6f46eed5b 100644 --- a/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/combined.test.js +++ b/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/combined.test.js @@ -100,8 +100,7 @@ describe('Combined API Features Translation', () => { 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 in a combined code block', () => { + it('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);'); @@ -114,8 +113,7 @@ describe('Combined API Features Translation', () => { expect(translatedCode).toBe('bru.setEnvVar("computed", bru.getVar("base") + "-suffix");'); }); - // TODO: Restore once UI update fixes are live for setCollectionVar - it.skip('should handle more complex nested expressions', () => { + it('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"));'); @@ -358,8 +356,7 @@ describe('Combined API Features Translation', () => { 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', () => { + it('should translate pm.collectionVariables alias set inside functions', () => { const code = ` const tempCollVars = pm.collectionVariables; tempCollVars.set("sessionId", "value"); diff --git a/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/multiline-syntax.test.js b/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/multiline-syntax.test.js index 88a3b9db92a..9d3936464be 100644 --- a/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/multiline-syntax.test.js +++ b/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/multiline-syntax.test.js @@ -43,8 +43,7 @@ describe('Multiline Syntax Handling', () => { 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', () => { + it('should handle multiline collection variable set syntax', () => { const code = ` pm.collectionVariables .set("lastRun", new Date().toISOString()); @@ -287,8 +286,7 @@ describe('Multiline Syntax Handling', () => { 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', () => { + it('should translate multiline pm.collectionVariables.set in comprehensive script', () => { const code = ` pm.collectionVariables .set("lastRun", new Date()); diff --git a/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/response.test.js b/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/response.test.js index f57000d3d5b..a0e41ea2c17 100644 --- a/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/response.test.js +++ b/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/response.test.js @@ -283,8 +283,7 @@ describe('Response Translation', () => { 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', () => { + it('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);'); diff --git a/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/testing-framework.test.js b/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/testing-framework.test.js index a1f189b6f94..4f56a38292c 100644 --- a/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/testing-framework.test.js +++ b/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/testing-framework.test.js @@ -69,8 +69,7 @@ describe('Testing Framework Translation', () => { 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', () => { + it('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);'); diff --git a/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/variables.test.js b/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/variables.test.js index 4832f13f83f..a84b948d354 100644 --- a/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/variables.test.js +++ b/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/variables.test.js @@ -71,8 +71,7 @@ describe('Variables Translation', () => { expect(translatedCode).toBe('bru.getCollectionVar("apiUrl");'); }); - // TODO: Restore once UI update fixes are live for setCollectionVar - it.skip('should translate pm.collectionVariables.set', () => { + it('should translate pm.collectionVariables.set', () => { const code = 'pm.collectionVariables.set("token", jsonData.token);'; const translatedCode = translateCode(code); @@ -86,8 +85,7 @@ describe('Variables Translation', () => { expect(translatedCode).toBe('bru.hasCollectionVar("authToken");'); }); - // TODO: Restore once UI update fixes are live for deleteCollectionVar - it.skip('should translate pm.collectionVariables.unset', () => { + it('should translate pm.collectionVariables.unset', () => { const code = 'pm.collectionVariables.unset("tempVar");'; const translatedCode = translateCode(code); @@ -108,6 +106,34 @@ describe('Variables Translation', () => { expect(translatedCode).toBe('bru.setGlobalEnvVar("test", "value");'); }); + it('should translate pm.globals.unset', () => { + const code = 'pm.globals.unset("token");'; + const translatedCode = translateCode(code); + + expect(translatedCode).toBe('bru.deleteGlobalEnvVar("token");'); + }); + + it('should translate pm.globals.clear', () => { + const code = 'pm.globals.clear();'; + const translatedCode = translateCode(code); + + expect(translatedCode).toBe('bru.deleteAllGlobalEnvVars();'); + }); + + it('should translate pm.collectionVariables.clear', () => { + const code = 'pm.collectionVariables.clear();'; + const translatedCode = translateCode(code); + + expect(translatedCode).toBe('bru.deleteAllCollectionVars();'); + }); + + it('should translate pm.collectionVariables.toObject', () => { + const code = 'const vars = pm.collectionVariables.toObject();'; + const translatedCode = translateCode(code); + + expect(translatedCode).toBe('const vars = bru.getAllCollectionVars();'); + }); + // Alias tests for variables it('should handle variables aliases', () => { const code = ` @@ -126,8 +152,7 @@ describe('Variables Translation', () => { }); // Alias tests for collection variables - // TODO: Restore once UI update fixes are live for setCollectionVar/deleteCollectionVar - it.skip('should handle collection variables aliases', () => { + it('should handle collection variables aliases', () => { const code = ` const collVars = pm.collectionVariables; const has = collVars.has("test"); @@ -183,8 +208,7 @@ describe('Variables Translation', () => { expect(translatedCode).toContain('bru.setVar("requestTime", new Date().toISOString());'); }); - // TODO: Restore once UI update fixes are live for setCollectionVar/deleteCollectionVar - it.skip('should handle all collection variable methods together', () => { + it('should handle all collection variable methods together', () => { const code = ` // All collection variable methods const hasApiUrl = pm.collectionVariables.has("apiUrl"); @@ -202,8 +226,7 @@ describe('Variables Translation', () => { expect(translatedCode).toContain('bru.deleteCollectionVar("tempVar");'); }); - // TODO: Restore once UI update fixes are live for setCollectionVar - it.skip('should handle more complex nested expressions with variables', () => { + it('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);