Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions packages/bruno-converters/src/postman/postman-translations.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
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(',
'pm\\.variables\\.get\\(': 'bru.getVar(',
'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()',
Expand All @@ -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(',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,26 @@ 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");';
const translatedCode = translateBruToPostman(code);
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");');
Expand All @@ -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();');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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);');
Expand All @@ -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"));');
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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();');
});

Comment on lines +109 to +136

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add the missing pm.globals.toObject regression test.

Line 15 in packages/bruno-converters/src/utils/postman-to-bruno-translator.js now restores pm.globals.toObject, but this new block only covers unset and clear for globals. That leaves one newly re-enabled mapping unguarded.

🧪 Suggested test
+  it('should translate pm.globals.toObject', () => {
+    const code = 'const globals = pm.globals.toObject();';
+    const translatedCode = translateCode(code);
+
+    expect(translatedCode).toBe('const globals = bru.getAllGlobalEnvVars();');
+  });

As per coding guidelines, "Add tests for any new functionality or meaningful changes. If code is added, removed, or significantly modified, corresponding tests should be updated or created."

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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();');
});
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.globals.toObject', () => {
const code = 'const globals = pm.globals.toObject();';
const translatedCode = translateCode(code);
expect(translatedCode).toBe('const globals = bru.getAllGlobalEnvVars();');
});
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();');
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/variables.test.js`
around lines 109 - 136, Add a regression test for the newly restored
pm.globals.toObject mapping in the variables translation suite. In
variables.test.js, extend the existing translateCode coverage alongside
pm.globals.unset, pm.globals.clear, and pm.collectionVariables.toObject to
assert that pm.globals.toObject() translates to bru.getAllGlobalEnvVars(). This
should exercise the postman-to-bruno-translator.js behavior so the restored
global toObject mapping stays covered.

Source: Coding guidelines

// Alias tests for variables
it('should handle variables aliases', () => {
const code = `
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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);

Expand Down
Loading