mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-22 12:15:38 +00:00
* feat: implement translation utilities for converting Bruno scripts to Postman format - Added `bru-to-pm-translator` for translating Bruno API calls to Postman equivalents. - Introduced `pm-to-bru-translator` for reverse translations from Postman to Bruno. - Created utility functions in `ast-utils` for efficient AST manipulations. - Enhanced `bruno-to-postman.js` to utilize the new translation functions for script handling. - Updated tests to cover various translation scenarios, ensuring accuracy and reliability. * empry commint * refactor: migrate utility functions to ES module syntax - Converted utility functions in `ast-utils.js` to named exports for better modularity. - Updated import statements in `bru-to-pm-translator.js` and `pm-to-bru-translator.js` to use ES module syntax. - Refactored test files to align with the new import structure, enhancing consistency across the codebase. * fix: translations * fix: add info regarding cookie apis * simplify translations removing legacy inverse translation * fix: add translation for getFolderVAr * refactor: simplify transformation functions by removing change tracker * fix: renamed files and folders * fix: import statements * rm : file * simplify getSize translation
54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
const { describe, it, expect } = require('@jest/globals');
|
|
const { getMemberExpressionString } = require('../../src/utils/ast-utils');
|
|
const j = require('jscodeshift');
|
|
|
|
describe('getMemberExpressionString', () => {
|
|
it('should correctly convert simple member expressions to strings', () => {
|
|
// Create a simple member expression: pm.environment.get
|
|
const memberExpr = j.memberExpression(
|
|
j.memberExpression(
|
|
j.identifier('pm'),
|
|
j.identifier('environment')
|
|
),
|
|
j.identifier('get')
|
|
);
|
|
|
|
const result = getMemberExpressionString(memberExpr);
|
|
expect(result).toBe('pm.environment.get');
|
|
});
|
|
|
|
it('should handle computed properties with string literals', () => {
|
|
// Create a computed member expression: pm["environment"]["get"]
|
|
const memberExpr = j.memberExpression(
|
|
j.memberExpression(
|
|
j.identifier('pm'),
|
|
j.literal('environment'),
|
|
true // computed
|
|
),
|
|
j.literal('get'),
|
|
true // computed
|
|
);
|
|
|
|
const result = getMemberExpressionString(memberExpr);
|
|
expect(result).toBe('pm.environment.get');
|
|
});
|
|
|
|
it('should mark non-string computed properties as [computed]', () => {
|
|
// Create a computed member expression with variable: obj[varName]
|
|
const memberExpr = j.memberExpression(
|
|
j.identifier('obj'),
|
|
j.identifier('varName'),
|
|
true // computed
|
|
);
|
|
|
|
const result = getMemberExpressionString(memberExpr);
|
|
expect(result).toBe('obj.[computed]');
|
|
});
|
|
|
|
it('should handle basic identifiers', () => {
|
|
const identifier = j.identifier('pm');
|
|
const result = getMemberExpressionString(identifier);
|
|
expect(result).toBe('pm');
|
|
});
|
|
});
|