mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-23 04:35:40 +00:00
feat: implement translation utilities for converting Bruno scripts pm format (#6761)
* 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
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import map from 'lodash/map';
|
||||
import { deleteSecretsInEnvs, deleteUidsInEnvs, deleteUidsInItems, isItemARequest } from '../common';
|
||||
import translateBruToPostman from '../utils/bruno-to-postman-translator';
|
||||
|
||||
/**
|
||||
* Transforms a given URL string into an object representing the protocol, host, path, query, and variables.
|
||||
@@ -167,6 +168,15 @@ export const brunoToPostman = (collection) => {
|
||||
|
||||
return Array.from(finalVarsMap.values());
|
||||
};
|
||||
const translateScriptSafely = (script = '') => {
|
||||
try {
|
||||
return translateBruToPostman(script);
|
||||
} catch (err) {
|
||||
console.warn('Bru→Postman script translation failed, leaving script as-is', err);
|
||||
return script;
|
||||
}
|
||||
};
|
||||
|
||||
const generateEventSection = (item) => {
|
||||
const eventArray = [];
|
||||
// Request: item.script, Folder: item.root.request.script, Collection: item.request.script
|
||||
@@ -175,13 +185,14 @@ export const brunoToPostman = (collection) => {
|
||||
const testsBlock = item?.tests || item?.root?.request?.tests || item?.request?.tests;
|
||||
|
||||
if (scriptBlock.req && typeof scriptBlock.req === 'string') {
|
||||
const translated = translateScriptSafely(scriptBlock.req);
|
||||
eventArray.push({
|
||||
listen: 'prerequest',
|
||||
script: {
|
||||
type: 'text/javascript',
|
||||
packages: {},
|
||||
requests: {},
|
||||
exec: scriptBlock.req.split('\n')
|
||||
exec: translated.split('\n')
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -189,14 +200,16 @@ export const brunoToPostman = (collection) => {
|
||||
if (scriptBlock.res || testsBlock) {
|
||||
const exec = [];
|
||||
if (scriptBlock.res && typeof scriptBlock.res === 'string') {
|
||||
exec.push(...scriptBlock.res.split('\n'));
|
||||
const translated = translateScriptSafely(scriptBlock.res);
|
||||
exec.push(...translated.split('\n'));
|
||||
}
|
||||
if (testsBlock && typeof testsBlock === 'string') {
|
||||
const translatedTests = translateScriptSafely(testsBlock);
|
||||
if (exec.length > 0) {
|
||||
exec.push('');
|
||||
}
|
||||
exec.push('// Tests');
|
||||
exec.push(...testsBlock.split('\n'));
|
||||
exec.push(...translatedTests.split('\n'));
|
||||
}
|
||||
|
||||
// Only push the event if exec has content
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import translateCode from '../utils/jscode-shift-translator';
|
||||
import translateCode from '../utils/postman-to-bruno-translator';
|
||||
|
||||
const replacements = {
|
||||
'pm\\.environment\\.get\\(': 'bru.getEnvVar(',
|
||||
|
||||
93
packages/bruno-converters/src/utils/ast-utils.js
Normal file
93
packages/bruno-converters/src/utils/ast-utils.js
Normal file
@@ -0,0 +1,93 @@
|
||||
const j = require('jscodeshift');
|
||||
|
||||
/**
|
||||
* Efficiently builds a string representation of a member expression
|
||||
* without using toSource() for better performance.
|
||||
*
|
||||
* @param {Object} node - The member expression node from the AST
|
||||
* @returns {string} - String representation of the member expression (e.g., "pm.environment.get")
|
||||
*
|
||||
* @example
|
||||
* // For AST node representing `pm.environment.get`
|
||||
* getMemberExpressionString(node) // returns "pm.environment.get"
|
||||
*
|
||||
* // For AST node representing `obj["prop"]`
|
||||
* getMemberExpressionString(node) // returns "obj.prop"
|
||||
*
|
||||
* // For AST node representing `bru.cookies.jar()`
|
||||
* getMemberExpressionString(node) // returns "bru.cookies.jar()"
|
||||
*/
|
||||
export function getMemberExpressionString(node) {
|
||||
if (node.type === 'Identifier') {
|
||||
return node.name;
|
||||
}
|
||||
|
||||
if (node.type === 'CallExpression') {
|
||||
const calleeStr = getMemberExpressionString(node.callee);
|
||||
return `${calleeStr}()`;
|
||||
}
|
||||
|
||||
if (node.type === 'MemberExpression') {
|
||||
const objectStr = getMemberExpressionString(node.object);
|
||||
|
||||
// For computed properties like obj[prop]
|
||||
if (node.computed) {
|
||||
// For string literals like obj["prop"], include them in the string
|
||||
if (node.property.type === 'Literal' && typeof node.property.value === 'string') {
|
||||
return `${objectStr}.${node.property.value}`;
|
||||
}
|
||||
// For other computed properties, we can't reliably represent them
|
||||
return `${objectStr}.[computed]`;
|
||||
}
|
||||
|
||||
// For regular property access like obj.prop
|
||||
if (node.property.type === 'Identifier') {
|
||||
return `${objectStr}.${node.property.name}`;
|
||||
}
|
||||
}
|
||||
|
||||
return '[unsupported]';
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a member expression AST node from a dotted string path.
|
||||
*
|
||||
* @param {string} str - Dotted path string (e.g., "pm.variables.get")
|
||||
* @returns {Object} - jscodeshift MemberExpression or Identifier node
|
||||
*
|
||||
* @example
|
||||
* buildMemberExpressionFromString("pm.variables.get")
|
||||
* // Returns AST for: pm.variables.get
|
||||
*
|
||||
* buildMemberExpressionFromString("pm")
|
||||
* // Returns AST for: pm (just an Identifier)
|
||||
*/
|
||||
export function buildMemberExpressionFromString(str) {
|
||||
const parts = str.split('.');
|
||||
let expr = j.identifier(parts[0]);
|
||||
for (let i = 1; i < parts.length; i += 1) {
|
||||
expr = j.memberExpression(expr, j.identifier(parts[i]));
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a node is an identifier with a specific name.
|
||||
*
|
||||
* @param {Object} node - The AST node to check
|
||||
* @param {string} name - The expected identifier name
|
||||
* @returns {boolean} - True if node is an identifier with the given name
|
||||
*/
|
||||
export function isIdentifierNamed(node, name) {
|
||||
return node && node.type === 'Identifier' && node.name === name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a node is the null literal.
|
||||
*
|
||||
* @param {Object} node - The AST node to check
|
||||
* @returns {boolean} - True if node is a null literal
|
||||
*/
|
||||
export function isNullLiteral(node) {
|
||||
return node && node.type === 'Literal' && node.value === null;
|
||||
}
|
||||
@@ -0,0 +1,343 @@
|
||||
import {
|
||||
getMemberExpressionString,
|
||||
buildMemberExpressionFromString
|
||||
} from './ast-utils';
|
||||
const j = require('jscodeshift');
|
||||
|
||||
// =============================================================================
|
||||
// SIMPLE TRANSLATIONS
|
||||
// =============================================================================
|
||||
|
||||
/**
|
||||
* Simple 1:1 translations from Bruno helpers to Postman helpers.
|
||||
* These are direct member expression replacements.
|
||||
*/
|
||||
const simpleTranslations = {
|
||||
// Global variables
|
||||
'bru.getGlobalEnvVar': 'pm.globals.get',
|
||||
'bru.setGlobalEnvVar': 'pm.globals.set',
|
||||
|
||||
// Environment variables
|
||||
'bru.getEnvVar': 'pm.environment.get',
|
||||
'bru.setEnvVar': 'pm.environment.set',
|
||||
'bru.hasEnvVar': 'pm.environment.has',
|
||||
'bru.deleteEnvVar': 'pm.environment.unset',
|
||||
// Note: bru.getEnvName() is handled in complexTransformations because it's a function -> property conversion
|
||||
|
||||
// Runtime variables
|
||||
'bru.getVar': 'pm.variables.get',
|
||||
'bru.setVar': 'pm.variables.set',
|
||||
'bru.hasVar': 'pm.variables.has',
|
||||
'bru.deleteVar': 'pm.variables.unset',
|
||||
// 'bru.deleteAllVars': Postman does not have a way to delete all variables
|
||||
|
||||
// Collection variables
|
||||
'bru.getCollectionVar': 'pm.variables.get',
|
||||
/* Bruno does not have a way to set, has or delete collection variables */
|
||||
|
||||
// Folder variables
|
||||
'bru.getFolderVar': 'pm.variables.get',
|
||||
/* Bruno does not have a way to set, has or delete folder variables */
|
||||
|
||||
// Request variables (map to pm.variables.*)
|
||||
'bru.getRequestVar': 'pm.variables.get',
|
||||
/* Bruno does not have a way to set, has or delete request variables */
|
||||
|
||||
// Interpolation
|
||||
'bru.interpolate': 'pm.variables.replaceIn',
|
||||
|
||||
// Execution control
|
||||
'bru.setNextRequest': 'pm.execution.setNextRequest',
|
||||
'bru.runner.skipRequest': 'pm.execution.skipRequest',
|
||||
'bru.runner.setNextRequest': 'pm.execution.setNextRequest',
|
||||
|
||||
// Request helpers
|
||||
// Note: req.getUrl(), req.getMethod(), req.getHeaders(), req.getBody(), req.getName() are handled
|
||||
// in complexTransformations because they're function -> property conversions
|
||||
'req.getHeader': 'pm.request.headers.get',
|
||||
'req.setHeader': 'pm.request.headers.set',
|
||||
|
||||
// Response helpers
|
||||
// Note: res.getStatus(), res.getResponseTime(), res.getHeaders() are handled
|
||||
// in complexTransformations because they're function -> property conversions
|
||||
'res.status': 'pm.response.code',
|
||||
'res.statusText': 'pm.response.status',
|
||||
'res.body': 'pm.response.body',
|
||||
'res.getBody': 'pm.response.json',
|
||||
'res.getHeader': 'pm.response.headers.get',
|
||||
'res.getSize': 'pm.response.size',
|
||||
|
||||
// Cookies jar
|
||||
'bru.cookies.jar': 'pm.cookies.jar',
|
||||
|
||||
// Testing
|
||||
'expect.fail': 'pm.expect.fail'
|
||||
};
|
||||
|
||||
// =============================================================================
|
||||
// COMPLEX TRANSFORMATIONS
|
||||
// =============================================================================
|
||||
|
||||
/**
|
||||
* Complex transformations that require custom handling beyond simple replacements.
|
||||
* Each transformation has a pattern to match and a transform function.
|
||||
*
|
||||
* Note: These are processed in order, so more specific patterns should come first.
|
||||
*/
|
||||
const complexTransformations = [
|
||||
// bru.runner.stopExecution() -> pm.execution.setNextRequest(null)
|
||||
{
|
||||
pattern: 'bru.runner.stopExecution',
|
||||
transform: (path) => {
|
||||
return j.callExpression(
|
||||
buildMemberExpressionFromString('pm.execution.setNextRequest'),
|
||||
[j.literal(null)]
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
// JSON.stringify(res.getBody()) -> pm.response.text()
|
||||
{
|
||||
pattern: 'JSON.stringify',
|
||||
condition: (path) => {
|
||||
const args = path.value.arguments;
|
||||
if (args.length !== 1) return false;
|
||||
|
||||
const arg = args[0];
|
||||
if (arg.type !== 'CallExpression' || arg.callee.type !== 'MemberExpression') return false;
|
||||
|
||||
return getMemberExpressionString(arg.callee) === 'res.getBody';
|
||||
},
|
||||
transform: () => {
|
||||
return j.callExpression(
|
||||
buildMemberExpressionFromString('pm.response.text'),
|
||||
[]
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
// bru.getEnvName() -> pm.environment.name (function to property)
|
||||
{
|
||||
pattern: 'bru.getEnvName',
|
||||
transform: () => {
|
||||
// Replace the entire call expression with just the member expression (property access)
|
||||
return buildMemberExpressionFromString('pm.environment.name');
|
||||
}
|
||||
},
|
||||
|
||||
// Request helpers: function -> property conversions
|
||||
// req.getUrl() -> pm.request.url
|
||||
{
|
||||
pattern: 'req.getUrl',
|
||||
transform: () => buildMemberExpressionFromString('pm.request.url')
|
||||
},
|
||||
// req.getMethod() -> pm.request.method
|
||||
{
|
||||
pattern: 'req.getMethod',
|
||||
transform: () => buildMemberExpressionFromString('pm.request.method')
|
||||
},
|
||||
// req.getHeaders() -> pm.request.headers
|
||||
{
|
||||
pattern: 'req.getHeaders',
|
||||
transform: () => buildMemberExpressionFromString('pm.request.headers')
|
||||
},
|
||||
// req.getBody() -> pm.request.body
|
||||
{
|
||||
pattern: 'req.getBody',
|
||||
transform: () => buildMemberExpressionFromString('pm.request.body')
|
||||
},
|
||||
// req.getName() -> pm.info.requestName
|
||||
{
|
||||
pattern: 'req.getName',
|
||||
transform: () => buildMemberExpressionFromString('pm.info.requestName')
|
||||
},
|
||||
|
||||
// Response helpers: function -> property conversions
|
||||
// res.getStatus() -> pm.response.code
|
||||
{
|
||||
pattern: 'res.getStatus',
|
||||
transform: () => buildMemberExpressionFromString('pm.response.code')
|
||||
},
|
||||
// res.getStatusText() -> pm.response.status
|
||||
{
|
||||
pattern: 'res.getStatusText',
|
||||
transform: () => buildMemberExpressionFromString('pm.response.status')
|
||||
},
|
||||
// res.getResponseTime() -> pm.response.responseTime
|
||||
{
|
||||
pattern: 'res.getResponseTime',
|
||||
transform: () => buildMemberExpressionFromString('pm.response.responseTime')
|
||||
},
|
||||
// res.getHeaders() -> pm.response.headers
|
||||
{
|
||||
pattern: 'res.getHeaders',
|
||||
transform: () => buildMemberExpressionFromString('pm.response.headers')
|
||||
}
|
||||
];
|
||||
|
||||
// Create a map for O(1) lookups of complex transformations
|
||||
const complexTransformationsMap = new Map();
|
||||
complexTransformations.forEach((t) => {
|
||||
complexTransformationsMap.set(t.pattern, t);
|
||||
});
|
||||
|
||||
// Cookie jar method mappings (Bruno -> PM)
|
||||
// Note: Bruno's setCookie with cookie object form is not supported (Postman only accepts url, name, value, callback?)
|
||||
// Note: getCookies(url, callback?) -> getAll(url, options?, callback?)
|
||||
// PM docs treat callback as 2nd arg, likely handled internally to detect function vs options object
|
||||
const cookieMethodMapping = {
|
||||
getCookie: 'get', // (url, name, callback?) -> (url, name, callback?)
|
||||
getCookies: 'getAll', // (url, callback?) -> (url, callback?) - PM handles internally
|
||||
setCookie: 'set', // (url, name, value, callback?) -> (url, name, value?, callback?)
|
||||
deleteCookie: 'unset', // (url, name, callback?) -> (url, name, callback?)
|
||||
deleteCookies: 'clear' // (url, callback?) -> (url, callback?)
|
||||
};
|
||||
|
||||
// =============================================================================
|
||||
// TRANSFORMATION FUNCTIONS
|
||||
// =============================================================================
|
||||
|
||||
/**
|
||||
* Process simple member expression translations (bru.* -> pm.*)
|
||||
* and complex transformations in a single pass.
|
||||
*
|
||||
* @param {Object} ast - jscodeshift AST
|
||||
*/
|
||||
function processAllTransformations(ast) {
|
||||
// First handle CallExpressions for complex transformations
|
||||
ast.find(j.CallExpression).forEach((path) => {
|
||||
const { callee } = path.value;
|
||||
if (callee.type !== 'MemberExpression') return;
|
||||
|
||||
const memberExprStr = getMemberExpressionString(callee);
|
||||
const transform = complexTransformationsMap.get(memberExprStr);
|
||||
|
||||
if (transform) {
|
||||
// Check condition if present
|
||||
if (transform.condition && !transform.condition(path)) return;
|
||||
|
||||
const replacement = transform.transform(path);
|
||||
if (replacement !== null) {
|
||||
j(path).replaceWith(replacement);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Then handle simple member expression translations
|
||||
ast.find(j.MemberExpression).forEach((path) => {
|
||||
const memberExprStr = getMemberExpressionString(path.value);
|
||||
|
||||
if (!Object.prototype.hasOwnProperty.call(simpleTranslations, memberExprStr)) return;
|
||||
|
||||
const replacement = simpleTranslations[memberExprStr];
|
||||
j(path).replaceWith(buildMemberExpressionFromString(replacement));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform cookie jar method calls.
|
||||
* Handles both direct calls and variables assigned to cookie jars.
|
||||
*
|
||||
* @param {Object} ast - jscodeshift AST
|
||||
*/
|
||||
function transformCookieJarMethods(ast) {
|
||||
// Track variables assigned to cookie jar instances
|
||||
const cookieJarVars = new Set();
|
||||
|
||||
// Find variables assigned to cookie jar
|
||||
ast.find(j.VariableDeclarator).forEach((path) => {
|
||||
if (path.value.init?.type === 'CallExpression' && path.value.init.callee.type === 'MemberExpression') {
|
||||
const calleeStr = getMemberExpressionString(path.value.init.callee);
|
||||
if (calleeStr === 'bru.cookies.jar' || calleeStr === 'pm.cookies.jar') {
|
||||
if (path.value.id.type === 'Identifier') {
|
||||
cookieJarVars.add(path.value.id.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Transform method calls on cookie jars
|
||||
ast.find(j.CallExpression).forEach((path) => {
|
||||
const { callee } = path.value;
|
||||
if (callee.type !== 'MemberExpression' || callee.property.type !== 'Identifier') return;
|
||||
|
||||
const methodName = callee.property.name;
|
||||
if (!cookieMethodMapping[methodName]) return;
|
||||
|
||||
// Check if object is a direct jar() call or a jar variable
|
||||
const isDirectJarCall = callee.object.type === 'CallExpression'
|
||||
&& callee.object.callee.type === 'MemberExpression'
|
||||
&& ['bru.cookies.jar', 'pm.cookies.jar'].includes(getMemberExpressionString(callee.object.callee));
|
||||
|
||||
const isJarVariable = callee.object.type === 'Identifier' && cookieJarVars.has(callee.object.name);
|
||||
|
||||
if (isDirectJarCall || isJarVariable) {
|
||||
path.value.callee.property.name = cookieMethodMapping[methodName];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform test() -> pm.test() and expect() -> pm.expect()
|
||||
*
|
||||
* @param {Object} ast - jscodeshift AST
|
||||
*/
|
||||
function transformTestsAndExpect(ast) {
|
||||
// Transform test(...) -> pm.test(...)
|
||||
ast.find(j.CallExpression, { callee: { type: 'Identifier', name: 'test' } })
|
||||
.forEach((path) => {
|
||||
j(path.get('callee')).replaceWith(
|
||||
j.memberExpression(j.identifier('pm'), j.identifier('test'))
|
||||
);
|
||||
});
|
||||
|
||||
// Transform expect(...) -> pm.expect(...)
|
||||
ast.find(j.CallExpression, { callee: { type: 'Identifier', name: 'expect' } })
|
||||
.forEach((path) => {
|
||||
j(path.get('callee')).replaceWith(
|
||||
j.memberExpression(j.identifier('pm'), j.identifier('expect'))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// MAIN EXPORT
|
||||
// =============================================================================
|
||||
|
||||
/**
|
||||
* Translate Bruno scripts back to Postman-compatible scripts.
|
||||
*
|
||||
* This function transforms Bruno API calls (bru.*, req.*, res.*, test(), expect())
|
||||
* back to their Postman equivalents (pm.*, pm.request.*, pm.response.*, pm.test(), pm.expect()).
|
||||
*
|
||||
* @param {string} code - Bruno script string
|
||||
* @returns {string} - Postman-compatible script string
|
||||
*
|
||||
* @example
|
||||
* translateBruToPostman('bru.getEnvVar("test");')
|
||||
* // Returns: 'pm.environment.get("test");'
|
||||
*
|
||||
* @example
|
||||
* translateBruToPostman('const data = res.getBody();')
|
||||
* // Returns: 'const data = pm.response.json();'
|
||||
*/
|
||||
function translateBruToPostman(code) {
|
||||
if (!code || typeof code !== 'string') {
|
||||
return '';
|
||||
}
|
||||
|
||||
try {
|
||||
const ast = j(code);
|
||||
|
||||
processAllTransformations(ast);
|
||||
transformCookieJarMethods(ast);
|
||||
transformTestsAndExpect(ast);
|
||||
|
||||
return ast.toSource();
|
||||
} catch (e) {
|
||||
console.warn('Error in Bruno to Postman translation:', e);
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
export default translateBruToPostman;
|
||||
@@ -1,47 +1,8 @@
|
||||
import sendRequestTransformer from './send-request-transformer';
|
||||
import { getMemberExpressionString } from './ast-utils';
|
||||
const j = require('jscodeshift');
|
||||
const cloneDeep = require('lodash/cloneDeep');
|
||||
|
||||
/**
|
||||
* Efficiently builds a string representation of a member expression without using toSource()
|
||||
*
|
||||
* @param {Object} node - The member expression node from the AST
|
||||
* @return {string} - String representation of the member expression (e.g., "pm.environment.get")
|
||||
*/
|
||||
function getMemberExpressionString(node) {
|
||||
// Handle base case: if this is an Identifier
|
||||
if (node.type === 'Identifier') {
|
||||
return node.name;
|
||||
}
|
||||
|
||||
if (node.type === 'CallExpression') {
|
||||
const calleeStr = getMemberExpressionString(node.callee);
|
||||
return `${calleeStr}()`;
|
||||
}
|
||||
|
||||
// Handle member expressions
|
||||
if (node.type === 'MemberExpression') {
|
||||
const objectStr = getMemberExpressionString(node.object);
|
||||
|
||||
// For computed properties like obj[prop], we need special handling
|
||||
if (node.computed) {
|
||||
// For literals like obj["prop"], we can include them in the string
|
||||
if (node.property.type === 'Literal' && typeof node.property.value === 'string') {
|
||||
return `${objectStr}.${node.property.value}`;
|
||||
}
|
||||
// For other computed properties, we can't reliably represent them as a simple string
|
||||
return `${objectStr}.[computed]`;
|
||||
}
|
||||
|
||||
// For regular property access like obj.prop
|
||||
if (node.property.type === 'Identifier') {
|
||||
return `${objectStr}.${node.property.name}`;
|
||||
}
|
||||
}
|
||||
|
||||
return '[unsupported]';
|
||||
}
|
||||
|
||||
// Simple 1:1 translations for straightforward replacements
|
||||
const simpleTranslations = {
|
||||
// Global Variables
|
||||
@@ -0,0 +1,147 @@
|
||||
import translateBruToPostman from '../../../src/utils/bruno-to-postman-translator';
|
||||
|
||||
describe('Bruno to Postman Cookies Translation', () => {
|
||||
// Cookie jar translation
|
||||
it('should translate bru.cookies.jar to pm.cookies.jar', () => {
|
||||
const code = 'const jar = bru.cookies.jar();';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const jar = pm.cookies.jar();');
|
||||
});
|
||||
|
||||
// Cookie method translations with direct jar call chaining
|
||||
it('should translate getCookie to get (direct chaining)', () => {
|
||||
const code = 'const sessionId = bru.cookies.jar().getCookie("https://example.com", "sessionId");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const sessionId = pm.cookies.jar().get("https://example.com", "sessionId");');
|
||||
});
|
||||
|
||||
it('should translate getCookies to getAll (direct chaining)', () => {
|
||||
const code = 'const allCookies = bru.cookies.jar().getCookies("https://example.com");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const allCookies = pm.cookies.jar().getAll("https://example.com");');
|
||||
});
|
||||
|
||||
it('should translate setCookie to set (direct chaining)', () => {
|
||||
const code = 'bru.cookies.jar().setCookie("https://example.com", "token", "abc123");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.cookies.jar().set("https://example.com", "token", "abc123");');
|
||||
});
|
||||
|
||||
it('should translate deleteCookie to unset (direct chaining)', () => {
|
||||
const code = 'bru.cookies.jar().deleteCookie("https://example.com", "sessionId");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.cookies.jar().unset("https://example.com", "sessionId");');
|
||||
});
|
||||
|
||||
it('should translate deleteCookies to clear (direct chaining)', () => {
|
||||
const code = 'bru.cookies.jar().deleteCookies("https://example.com");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.cookies.jar().clear("https://example.com");');
|
||||
});
|
||||
|
||||
// Cookie method translations with jar variable
|
||||
it('should translate getCookie to get (jar variable)', () => {
|
||||
const code = `
|
||||
const jar = bru.cookies.jar();
|
||||
const sessionId = jar.getCookie("https://example.com", "sessionId");
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('const jar = pm.cookies.jar();');
|
||||
expect(translatedCode).toContain('const sessionId = jar.get("https://example.com", "sessionId");');
|
||||
});
|
||||
|
||||
it('should translate getCookies to getAll (jar variable)', () => {
|
||||
const code = `
|
||||
const jar = bru.cookies.jar();
|
||||
const allCookies = jar.getCookies("https://example.com");
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('const jar = pm.cookies.jar();');
|
||||
expect(translatedCode).toContain('const allCookies = jar.getAll("https://example.com");');
|
||||
});
|
||||
|
||||
it('should translate setCookie to set (jar variable)', () => {
|
||||
const code = `
|
||||
const jar = bru.cookies.jar();
|
||||
jar.setCookie("https://example.com", "token", "abc123");
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('const jar = pm.cookies.jar();');
|
||||
expect(translatedCode).toContain('jar.set("https://example.com", "token", "abc123");');
|
||||
});
|
||||
|
||||
it('should translate deleteCookie to unset (jar variable)', () => {
|
||||
const code = `
|
||||
const jar = bru.cookies.jar();
|
||||
jar.deleteCookie("https://example.com", "sessionId");
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('const jar = pm.cookies.jar();');
|
||||
expect(translatedCode).toContain('jar.unset("https://example.com", "sessionId");');
|
||||
});
|
||||
|
||||
it('should translate deleteCookies to clear (jar variable)', () => {
|
||||
const code = `
|
||||
const jar = bru.cookies.jar();
|
||||
jar.deleteCookies("https://example.com");
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('const jar = pm.cookies.jar();');
|
||||
expect(translatedCode).toContain('jar.clear("https://example.com");');
|
||||
});
|
||||
|
||||
// Complex cookie scenarios
|
||||
it('should handle multiple cookie operations together', () => {
|
||||
const code = `
|
||||
const jar = bru.cookies.jar();
|
||||
const domain = "https://api.example.com";
|
||||
|
||||
// Check existing cookie
|
||||
const existingToken = jar.getCookie(domain, "authToken");
|
||||
|
||||
if (!existingToken) {
|
||||
// Set new cookie
|
||||
jar.setCookie(domain, "authToken", bru.getEnvVar("token"));
|
||||
}
|
||||
|
||||
// Get all cookies for logging
|
||||
const allCookies = jar.getCookies(domain);
|
||||
console.log("Current cookies:", allCookies);
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('const jar = pm.cookies.jar();');
|
||||
expect(translatedCode).toContain('const existingToken = jar.get(domain, "authToken");');
|
||||
expect(translatedCode).toContain('jar.set(domain, "authToken", pm.environment.get("token"));');
|
||||
expect(translatedCode).toContain('const allCookies = jar.getAll(domain);');
|
||||
});
|
||||
|
||||
it('should handle cookie cleanup scenario', () => {
|
||||
const code = `
|
||||
const jar = bru.cookies.jar();
|
||||
const domain = bru.getEnvVar("apiDomain");
|
||||
|
||||
// Clear specific cookies
|
||||
jar.deleteCookie(domain, "session");
|
||||
jar.deleteCookie(domain, "tempToken");
|
||||
|
||||
// Or clear all cookies
|
||||
if (bru.getVar("clearAll") === "true") {
|
||||
jar.deleteCookies(domain);
|
||||
}
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('const jar = pm.cookies.jar();');
|
||||
expect(translatedCode).toContain('const domain = pm.environment.get("apiDomain");');
|
||||
expect(translatedCode).toContain('jar.unset(domain, "session");');
|
||||
expect(translatedCode).toContain('jar.unset(domain, "tempToken");');
|
||||
expect(translatedCode).toContain('if (pm.variables.get("clearAll") === "true") {');
|
||||
expect(translatedCode).toContain('jar.clear(domain);');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,111 @@
|
||||
import translateBruToPostman from '../../../src/utils/bruno-to-postman-translator';
|
||||
|
||||
describe('Bruno to Postman Environment Variable Translation', () => {
|
||||
it('should translate bru.getEnvVar', () => {
|
||||
const code = 'bru.getEnvVar("test");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.environment.get("test");');
|
||||
});
|
||||
|
||||
it('should translate bru.setEnvVar', () => {
|
||||
const code = 'bru.setEnvVar("test", "value");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.environment.set("test", "value");');
|
||||
});
|
||||
|
||||
it('should translate bru.deleteEnvVar', () => {
|
||||
const code = 'bru.deleteEnvVar("test");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.environment.unset("test");');
|
||||
});
|
||||
|
||||
it('should translate bru.hasEnvVar', () => {
|
||||
const code = 'bru.hasEnvVar("apiKey");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.environment.has("apiKey");');
|
||||
});
|
||||
|
||||
it('should translate bru.getEnvName() to pm.environment.name (function to property)', () => {
|
||||
const code = 'const envName = bru.getEnvName();';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const envName = pm.environment.name;');
|
||||
});
|
||||
|
||||
it('should handle nested Postman API calls with environment', () => {
|
||||
const code = 'bru.setEnvVar("computed", bru.getVar("base") + "-suffix");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.environment.set("computed", pm.variables.get("base") + "-suffix");');
|
||||
});
|
||||
|
||||
it('should handle JSON operations with environment variables', () => {
|
||||
const code = 'bru.setEnvVar("user", JSON.stringify({ id: 123, name: "John" }));';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.environment.set("user", JSON.stringify({ id: 123, name: "John" }));');
|
||||
});
|
||||
|
||||
it('should handle JSON.parse with environment variables', () => {
|
||||
const code = 'const userData = JSON.parse(bru.getEnvVar("user"));';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const userData = JSON.parse(pm.environment.get("user"));');
|
||||
});
|
||||
|
||||
it('should handle all environment variable methods together', () => {
|
||||
const code = `
|
||||
// All environment variable methods
|
||||
const token = bru.getEnvVar("token");
|
||||
bru.setEnvVar("timestamp", new Date().toISOString());
|
||||
|
||||
console.log(\`Token: \${token}\`);
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('const token = pm.environment.get("token");');
|
||||
expect(translatedCode).toContain('pm.environment.set("timestamp", new Date().toISOString());');
|
||||
});
|
||||
|
||||
it('should handle environment variables with computed property names', () => {
|
||||
const code = `
|
||||
const prefix = "api";
|
||||
const suffix = "Key";
|
||||
bru.setEnvVar(prefix + "_" + suffix, "abc123");
|
||||
const computedValue = bru.getEnvVar(prefix + "_" + suffix);
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toContain('pm.environment.set(prefix + "_" + suffix, "abc123");');
|
||||
expect(translatedCode).toContain('const computedValue = pm.environment.get(prefix + "_" + suffix);');
|
||||
});
|
||||
|
||||
it('should handle environment variables in complex object structures', () => {
|
||||
const code = `
|
||||
const config = {
|
||||
baseUrl: bru.getEnvVar("apiUrl"),
|
||||
headers: {
|
||||
"Authorization": "Bearer " + bru.getEnvVar("token"),
|
||||
"X-Api-Key": bru.getEnvVar("apiKey") || "default-key"
|
||||
},
|
||||
timeout: parseInt(bru.getEnvVar("timeout") || "5000")
|
||||
};
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toContain('baseUrl: pm.environment.get("apiUrl"),');
|
||||
expect(translatedCode).toContain('"Authorization": "Bearer " + pm.environment.get("token"),');
|
||||
expect(translatedCode).toContain('"X-Api-Key": pm.environment.get("apiKey") || "default-key"');
|
||||
expect(translatedCode).toContain('timeout: parseInt(pm.environment.get("timeout") || "5000")');
|
||||
});
|
||||
|
||||
it('should handle environment variables in try-catch blocks', () => {
|
||||
const code = `
|
||||
try {
|
||||
const configStr = bru.getEnvVar("config");
|
||||
const config = JSON.parse(configStr);
|
||||
console.log("Config loaded:", config.version);
|
||||
} catch (error) {
|
||||
console.error("Failed to parse config");
|
||||
bru.setEnvVar("configError", error.message);
|
||||
}
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toContain('const configStr = pm.environment.get("config");');
|
||||
expect(translatedCode).toContain('pm.environment.set("configError", error.message);');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,109 @@
|
||||
import translateBruToPostman from '../../../src/utils/bruno-to-postman-translator';
|
||||
|
||||
describe('Bruno to Postman Execution Control Translation', () => {
|
||||
// setNextRequest translations
|
||||
it('should translate bru.setNextRequest', () => {
|
||||
const code = 'bru.setNextRequest("Get User Details");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.execution.setNextRequest("Get User Details");');
|
||||
});
|
||||
|
||||
it('should translate bru.runner.setNextRequest', () => {
|
||||
const code = 'bru.runner.setNextRequest("Create Order");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.execution.setNextRequest("Create Order");');
|
||||
});
|
||||
|
||||
// skipRequest translation
|
||||
it('should translate bru.runner.skipRequest', () => {
|
||||
const code = 'bru.runner.skipRequest();';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.execution.skipRequest();');
|
||||
});
|
||||
|
||||
// stopExecution translation
|
||||
it('should translate bru.runner.stopExecution() to pm.execution.setNextRequest(null)', () => {
|
||||
const code = 'bru.runner.stopExecution();';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.execution.setNextRequest(null);');
|
||||
});
|
||||
|
||||
// Conditional execution control
|
||||
it('should handle setNextRequest in conditionals', () => {
|
||||
const code = `
|
||||
if (res.getStatus() === 401) {
|
||||
bru.setNextRequest("Refresh Token");
|
||||
} else if (res.getStatus() === 200) {
|
||||
bru.setNextRequest("Process Data");
|
||||
}
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('if (pm.response.code === 401) {');
|
||||
expect(translatedCode).toContain('pm.execution.setNextRequest("Refresh Token");');
|
||||
expect(translatedCode).toContain('} else if (pm.response.code === 200) {');
|
||||
expect(translatedCode).toContain('pm.execution.setNextRequest("Process Data");');
|
||||
});
|
||||
|
||||
it('should handle stopExecution in error handling', () => {
|
||||
const code = `
|
||||
if (res.getStatus() >= 500) {
|
||||
console.error("Server error, stopping execution");
|
||||
bru.runner.stopExecution();
|
||||
}
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('if (pm.response.code >= 500) {');
|
||||
expect(translatedCode).toContain('console.error("Server error, stopping execution");');
|
||||
expect(translatedCode).toContain('pm.execution.setNextRequest(null);');
|
||||
});
|
||||
|
||||
it('should handle skipRequest with condition', () => {
|
||||
const code = `
|
||||
const shouldSkip = bru.getEnvVar("skipNextRequest") === "true";
|
||||
if (shouldSkip) {
|
||||
bru.runner.skipRequest();
|
||||
}
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('const shouldSkip = pm.environment.get("skipNextRequest") === "true";');
|
||||
expect(translatedCode).toContain('if (shouldSkip) {');
|
||||
expect(translatedCode).toContain('pm.execution.skipRequest();');
|
||||
});
|
||||
|
||||
it('should handle all execution control methods together', () => {
|
||||
const code = `
|
||||
const status = res.getStatus();
|
||||
const data = res.getBody();
|
||||
|
||||
if (status === 200 && data.hasMore) {
|
||||
bru.setNextRequest("Fetch Next Page");
|
||||
} else if (status === 429) {
|
||||
console.log("Rate limited, skipping");
|
||||
bru.runner.skipRequest();
|
||||
} else if (status >= 500) {
|
||||
bru.runner.stopExecution();
|
||||
}
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('const status = pm.response.code;');
|
||||
expect(translatedCode).toContain('const data = pm.response.json();');
|
||||
expect(translatedCode).toContain('pm.execution.setNextRequest("Fetch Next Page");');
|
||||
expect(translatedCode).toContain('pm.execution.skipRequest();');
|
||||
expect(translatedCode).toContain('pm.execution.setNextRequest(null);');
|
||||
});
|
||||
|
||||
it('should handle dynamic request names in setNextRequest', () => {
|
||||
const code = `
|
||||
const nextRequest = bru.getVar("nextRequestName");
|
||||
bru.setNextRequest(nextRequest);
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('const nextRequest = pm.variables.get("nextRequestName");');
|
||||
expect(translatedCode).toContain('pm.execution.setNextRequest(nextRequest);');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,91 @@
|
||||
import translateBruToPostman from '../../../src/utils/bruno-to-postman-translator';
|
||||
|
||||
describe('Bruno to Postman Request Translation', () => {
|
||||
it('should translate req.getUrl() to pm.request.url (function to property)', () => {
|
||||
const code = 'const url = req.getUrl();';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const url = pm.request.url;');
|
||||
});
|
||||
|
||||
it('should translate req.getMethod() to pm.request.method (function to property)', () => {
|
||||
const code = 'const method = req.getMethod();';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const method = pm.request.method;');
|
||||
});
|
||||
|
||||
it('should translate req.getHeaders() to pm.request.headers (function to property)', () => {
|
||||
const code = 'const headers = req.getHeaders();';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const headers = pm.request.headers;');
|
||||
});
|
||||
|
||||
it('should translate req.getBody() to pm.request.body (function to property)', () => {
|
||||
const code = 'const body = req.getBody();';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const body = pm.request.body;');
|
||||
});
|
||||
|
||||
it('should translate req.getName() to pm.info.requestName (function to property)', () => {
|
||||
const code = 'const name = req.getName();';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const name = pm.info.requestName;');
|
||||
});
|
||||
|
||||
it('should translate req.getHeader() to pm.request.headers.get()', () => {
|
||||
const code = 'const contentType = req.getHeader("Content-Type");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const contentType = pm.request.headers.get("Content-Type");');
|
||||
});
|
||||
|
||||
it('should translate req.setHeader() to pm.request.headers.set()', () => {
|
||||
const code = 'req.setHeader("Authorization", "Bearer token123");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.request.headers.set("Authorization", "Bearer token123");');
|
||||
});
|
||||
|
||||
it('should handle all request properties together', () => {
|
||||
const code = `
|
||||
// All request properties
|
||||
const url = req.getUrl();
|
||||
const method = req.getMethod();
|
||||
const headers = req.getHeaders();
|
||||
const body = req.getBody();
|
||||
const name = req.getName();
|
||||
|
||||
console.log(\`Request: \${method} \${url} - \${name}\`);
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('const url = pm.request.url;');
|
||||
expect(translatedCode).toContain('const method = pm.request.method;');
|
||||
expect(translatedCode).toContain('const headers = pm.request.headers;');
|
||||
expect(translatedCode).toContain('const body = pm.request.body;');
|
||||
expect(translatedCode).toContain('const name = pm.info.requestName;');
|
||||
});
|
||||
|
||||
it('should handle request properties in conditionals', () => {
|
||||
const code = `
|
||||
if (req.getMethod() === 'POST' || req.getMethod() === 'PUT') {
|
||||
const body = req.getBody();
|
||||
console.log("Request body:", body);
|
||||
}
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('if (pm.request.method === \'POST\' || pm.request.method === \'PUT\') {');
|
||||
expect(translatedCode).toContain('const body = pm.request.body;');
|
||||
});
|
||||
|
||||
it('should handle request logging', () => {
|
||||
const code = `
|
||||
console.log("Making request to:", req.getUrl());
|
||||
console.log("Method:", req.getMethod());
|
||||
console.log("Headers:", JSON.stringify(req.getHeaders()));
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('console.log("Making request to:", pm.request.url);');
|
||||
expect(translatedCode).toContain('console.log("Method:", pm.request.method);');
|
||||
expect(translatedCode).toContain('console.log("Headers:", JSON.stringify(pm.request.headers));');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,189 @@
|
||||
import translateBruToPostman from '../../../src/utils/bruno-to-postman-translator';
|
||||
|
||||
describe('Bruno to Postman Response Translation', () => {
|
||||
// Basic response property tests
|
||||
it('should translate res.getBody()', () => {
|
||||
const code = 'const jsonData = res.getBody();';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const jsonData = pm.response.json();');
|
||||
});
|
||||
|
||||
it('should translate res.getStatus() to pm.response.code (function to property)', () => {
|
||||
const code = 'if (res.getStatus() === 200) { console.log("Success"); }';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('if (pm.response.code === 200) { console.log("Success"); }');
|
||||
});
|
||||
|
||||
it('should translate JSON.stringify(res.getBody()) to pm.response.text()', () => {
|
||||
const code = 'const responseText = JSON.stringify(res.getBody());';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const responseText = pm.response.text();');
|
||||
});
|
||||
|
||||
it('should translate res.getResponseTime() to pm.response.responseTime (function to property)', () => {
|
||||
const code = 'console.log("Response time:", res.getResponseTime());';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('console.log("Response time:", pm.response.responseTime);');
|
||||
});
|
||||
|
||||
it('should translate res.statusText to pm.response.status (property to property)', () => {
|
||||
const code = 'console.log("Status text:", res.statusText);';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('console.log("Status text:", pm.response.status);');
|
||||
});
|
||||
|
||||
it('should translate res.status to pm.response.code (property to property)', () => {
|
||||
const code = 'const code = res.status;';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const code = pm.response.code;');
|
||||
});
|
||||
|
||||
it('should translate res.getStatusText() to pm.response.status (function to property)', () => {
|
||||
const code = 'const statusText = res.getStatusText();';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const statusText = pm.response.status;');
|
||||
});
|
||||
|
||||
it('should translate res.getHeaders() to pm.response.headers (function to property)', () => {
|
||||
const code = 'console.log("Headers:", res.getHeaders());';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('console.log("Headers:", pm.response.headers);');
|
||||
});
|
||||
|
||||
it('should translate res.getHeader()', () => {
|
||||
const code = 'const contentType = res.getHeader("Content-Type");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const contentType = pm.response.headers.get("Content-Type");');
|
||||
});
|
||||
|
||||
// Response assertions - translated to pm.expect with response properties
|
||||
it('should transform expect(res.getStatus()).to.equal() to pm.expect(pm.response.code).to.equal()', () => {
|
||||
const code = 'expect(res.getStatus()).to.equal(201);';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.expect(pm.response.code).to.equal(201);');
|
||||
});
|
||||
|
||||
it('should transform expect(res.getHeaders()).to.have.property() to pm.expect(pm.response.headers).to.have.property()', () => {
|
||||
const code = 'expect(res.getHeaders()).to.have.property("Content-Type".toLowerCase());';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.expect(pm.response.headers).to.have.property("Content-Type".toLowerCase());');
|
||||
});
|
||||
|
||||
it('should transform expect(res.getBody()).to.equal() to pm.expect(pm.response.json()).to.equal()', () => {
|
||||
const code = 'expect(res.getBody()).to.equal("Expected response body");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.expect(pm.response.json()).to.equal("Expected response body");');
|
||||
});
|
||||
|
||||
// getSize translations
|
||||
it('should translate res.getSize()', () => {
|
||||
const code = 'const size = res.getSize();';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const size = pm.response.size();');
|
||||
});
|
||||
|
||||
it('should translate res.getSize().body', () => {
|
||||
const code = 'const bodySize = res.getSize().body;';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const bodySize = pm.response.size().body;');
|
||||
});
|
||||
|
||||
it('should translate res.getSize().header', () => {
|
||||
const code = 'const headerSize = res.getSize().header;';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const headerSize = pm.response.size().header;');
|
||||
});
|
||||
|
||||
it('should translate res.getSize().total', () => {
|
||||
const code = 'const totalSize = res.getSize().total;';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const totalSize = pm.response.size().total;');
|
||||
});
|
||||
|
||||
// Complex response handling
|
||||
it('should handle response data with destructuring', () => {
|
||||
const code = `
|
||||
const { id, name, items } = res.getBody();
|
||||
const [first, second] = items;
|
||||
bru.setEnvVar("userId", id);
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('const { id, name, items } = pm.response.json();');
|
||||
expect(translatedCode).toContain('const [first, second] = items;');
|
||||
expect(translatedCode).toContain('pm.environment.set("userId", id);');
|
||||
});
|
||||
|
||||
it('should handle response JSON with optional chaining', () => {
|
||||
const code = `
|
||||
const userId = res.getBody()?.user?.id ?? "anonymous";
|
||||
const items = res.getBody()?.data?.items || [];
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('const userId = pm.response.json()?.user?.id ?? "anonymous";');
|
||||
expect(translatedCode).toContain('const items = pm.response.json()?.data?.items || [];');
|
||||
});
|
||||
|
||||
it('should handle response in complex conditionals', () => {
|
||||
const code = `
|
||||
if (res.getStatus() >= 200 && res.getStatus() < 300) {
|
||||
if (res.getHeader('Content-Type').includes('application/json')) {
|
||||
const data = res.getBody();
|
||||
|
||||
if (data.success === true && data.token) {
|
||||
bru.setEnvVar("authToken", data.token);
|
||||
} else if (data.error) {
|
||||
console.error("API error:", data.error);
|
||||
}
|
||||
}
|
||||
} else if (res.getStatus() === 404) {
|
||||
console.log("Resource not found");
|
||||
} else {
|
||||
console.error("Request failed with status:", res.getStatus());
|
||||
}
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('if (pm.response.code >= 200 && pm.response.code < 300) {');
|
||||
expect(translatedCode).toContain('if (pm.response.headers.get(\'Content-Type\').includes(\'application/json\')) {');
|
||||
expect(translatedCode).toContain('const data = pm.response.json();');
|
||||
expect(translatedCode).toContain('pm.environment.set("authToken", data.token);');
|
||||
expect(translatedCode).toContain('} else if (pm.response.code === 404) {');
|
||||
expect(translatedCode).toContain('console.error("Request failed with status:", pm.response.code);');
|
||||
});
|
||||
|
||||
it('should handle all response property methods together', () => {
|
||||
const code = `
|
||||
// All response property methods
|
||||
const statusCode = res.getStatus();
|
||||
const responseBody = res.getBody();
|
||||
const statusText = res.statusText;
|
||||
const responseTime = res.getResponseTime();
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('const statusCode = pm.response.code;');
|
||||
expect(translatedCode).toContain('const responseBody = pm.response.json();');
|
||||
expect(translatedCode).toContain('const statusText = pm.response.status;');
|
||||
expect(translatedCode).toContain('const responseTime = pm.response.responseTime;');
|
||||
});
|
||||
|
||||
it('should handle response processing in arrow functions', () => {
|
||||
const code = `
|
||||
const processItems = () => {
|
||||
const items = res.getBody().items;
|
||||
return items.map(item => item.id);
|
||||
};
|
||||
|
||||
const itemIds = processItems();
|
||||
bru.setEnvVar("itemIds", JSON.stringify(itemIds));
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('const items = pm.response.json().items;');
|
||||
expect(translatedCode).toContain('return items.map(item => item.id);');
|
||||
expect(translatedCode).toContain('const itemIds = processItems();');
|
||||
expect(translatedCode).toContain('pm.environment.set("itemIds", JSON.stringify(itemIds));');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,232 @@
|
||||
import translateBruToPostman from '../../../src/utils/bruno-to-postman-translator';
|
||||
|
||||
describe('Bruno to Postman Testing Framework Translation', () => {
|
||||
// Basic testing framework translations
|
||||
it('should translate test() to pm.test()', () => {
|
||||
const code = 'test("Status code is 200", function() { expect(res.getStatus()).to.equal(200); });';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.test("Status code is 200", function() { pm.expect(pm.response.code).to.equal(200); });');
|
||||
});
|
||||
|
||||
it('should translate expect() to pm.expect()', () => {
|
||||
const code = 'expect(jsonData.success).to.be.true;';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.expect(jsonData.success).to.be.true;');
|
||||
});
|
||||
|
||||
it('should translate expect.fail() to pm.expect.fail()', () => {
|
||||
const code = 'if (!isValid) expect.fail("Data is invalid");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('if (!isValid) pm.expect.fail("Data is invalid");');
|
||||
});
|
||||
|
||||
// Tests with response assertions
|
||||
it('should translate test with status check', () => {
|
||||
const code = `
|
||||
test("Check environment and call successful", function () {
|
||||
expect(bru.getEnvName()).to.equal("ENVIRONMENT_NAME");
|
||||
expect(res.getStatus()).to.equal(200);
|
||||
});`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe(`
|
||||
pm.test("Check environment and call successful", function () {
|
||||
pm.expect(pm.environment.name).to.equal("ENVIRONMENT_NAME");
|
||||
pm.expect(pm.response.code).to.equal(200);
|
||||
});`);
|
||||
});
|
||||
|
||||
// Test with arrow functions
|
||||
it('should translate test with arrow functions', () => {
|
||||
const code = `
|
||||
test("Status code is 200", () => {
|
||||
expect(res.getStatus()).to.equal(200);
|
||||
});
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('pm.test("Status code is 200", () => {');
|
||||
expect(translatedCode).toContain('pm.expect(pm.response.code).to.equal(200);');
|
||||
});
|
||||
|
||||
it('should handle multiple test assertions in one function', () => {
|
||||
const code = `
|
||||
test("The response has all properties", () => {
|
||||
const responseJson = res.getBody();
|
||||
expect(responseJson.type).to.eql('vip');
|
||||
expect(responseJson.name).to.be.a('string');
|
||||
expect(responseJson.id).to.have.lengthOf(1);
|
||||
});
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('pm.test("The response has all properties", () => {');
|
||||
expect(translatedCode).toContain('const responseJson = pm.response.json();');
|
||||
expect(translatedCode).toContain('pm.expect(responseJson.type).to.eql(\'vip\');');
|
||||
expect(translatedCode).toContain('pm.expect(responseJson.name).to.be.a(\'string\');');
|
||||
expect(translatedCode).toContain('pm.expect(responseJson.id).to.have.lengthOf(1);');
|
||||
});
|
||||
|
||||
// Tests inside different code structures
|
||||
it('should translate test commands inside tests with nested functions', () => {
|
||||
const code = `
|
||||
test("Auth flow works", function() {
|
||||
const response = res.getBody();
|
||||
expect(response.authenticated).to.be.true;
|
||||
bru.setEnvVar("userId", response.user.id);
|
||||
bru.setVar("sessionId", response.session.id);
|
||||
});
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('pm.test("Auth flow works", function() {');
|
||||
expect(translatedCode).toContain('const response = pm.response.json();');
|
||||
expect(translatedCode).toContain('pm.expect(response.authenticated).to.be.true;');
|
||||
expect(translatedCode).toContain('pm.environment.set("userId", response.user.id);');
|
||||
expect(translatedCode).toContain('pm.variables.set("sessionId", response.session.id);');
|
||||
});
|
||||
|
||||
it('should handle nested test functions', () => {
|
||||
const code = `
|
||||
test("Main test group", function() {
|
||||
const responseJson = res.getBody();
|
||||
|
||||
test("User data validation", function() {
|
||||
expect(responseJson.user).to.be.an('object');
|
||||
expect(responseJson.user.id).to.be.a('string');
|
||||
});
|
||||
|
||||
test("Settings validation", function() {
|
||||
expect(responseJson.settings).to.be.an('object');
|
||||
expect(responseJson.settings.notifications).to.be.a('boolean');
|
||||
});
|
||||
});
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('pm.test("Main test group", function() {');
|
||||
expect(translatedCode).toContain('const responseJson = pm.response.json();');
|
||||
expect(translatedCode).toContain('pm.test("User data validation", function() {');
|
||||
expect(translatedCode).toContain('pm.expect(responseJson.user).to.be.an(\'object\');');
|
||||
expect(translatedCode).toContain('pm.test("Settings validation", function() {');
|
||||
expect(translatedCode).toContain('pm.expect(responseJson.settings.notifications).to.be.a(\'boolean\');');
|
||||
});
|
||||
|
||||
it('should handle test with dynamic test names', () => {
|
||||
const code = `
|
||||
const endpoint = bru.getVar("currentEndpoint");
|
||||
|
||||
test(\`\${endpoint} returns correct data\`, function() {
|
||||
const responseJson = res.getBody();
|
||||
expect(responseJson).to.be.an('object');
|
||||
});
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('const endpoint = pm.variables.get("currentEndpoint");');
|
||||
expect(translatedCode).toContain('pm.test(`${endpoint} returns correct data`, function() {');
|
||||
expect(translatedCode).toContain('const responseJson = pm.response.json();');
|
||||
expect(translatedCode).toContain('pm.expect(responseJson).to.be.an(\'object\');');
|
||||
});
|
||||
|
||||
it('should handle test with conditional execution', () => {
|
||||
const code = `
|
||||
const responseJson = res.getBody();
|
||||
|
||||
if (responseJson.type === 'user') {
|
||||
test("User validation", function() {
|
||||
expect(responseJson.name).to.be.a('string');
|
||||
expect(responseJson.email).to.be.a('string');
|
||||
});
|
||||
} else if (responseJson.type === 'admin') {
|
||||
test("Admin validation", function() {
|
||||
expect(responseJson.accessLevel).to.be.above(5);
|
||||
expect(responseJson.permissions).to.be.an('array');
|
||||
});
|
||||
}
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('const responseJson = pm.response.json();');
|
||||
expect(translatedCode).toContain('if (responseJson.type === \'user\') {');
|
||||
expect(translatedCode).toContain('pm.test("User validation", function() {');
|
||||
expect(translatedCode).toContain('pm.expect(responseJson.name).to.be.a(\'string\');');
|
||||
expect(translatedCode).toContain('} else if (responseJson.type === \'admin\') {');
|
||||
expect(translatedCode).toContain('pm.test("Admin validation", function() {');
|
||||
expect(translatedCode).toContain('pm.expect(responseJson.accessLevel).to.be.above(5);');
|
||||
});
|
||||
|
||||
it('should handle assertions with logical operators', () => {
|
||||
const code = `
|
||||
test("Response has valid structure", function() {
|
||||
const data = res.getBody();
|
||||
|
||||
expect(data.id && data.name).to.be.ok;
|
||||
expect(data.active || data.pending).to.be.true;
|
||||
expect(!data.deleted).to.be.true;
|
||||
});
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('pm.test("Response has valid structure", function() {');
|
||||
expect(translatedCode).toContain('const data = pm.response.json();');
|
||||
expect(translatedCode).toContain('pm.expect(data.id && data.name).to.be.ok;');
|
||||
expect(translatedCode).toContain('pm.expect(data.active || data.pending).to.be.true;');
|
||||
expect(translatedCode).toContain('pm.expect(!data.deleted).to.be.true;');
|
||||
});
|
||||
|
||||
it('should handle array and object assertions', () => {
|
||||
const code = `
|
||||
test("Array and object validations", function() {
|
||||
const data = res.getBody();
|
||||
|
||||
// Array validations
|
||||
expect(data.items).to.be.an('array');
|
||||
expect(data.items).to.have.lengthOf.at.least(1);
|
||||
expect(data.items[0]).to.have.property('id');
|
||||
|
||||
// Object validations
|
||||
expect(data.user).to.be.an('object');
|
||||
expect(data.user).to.have.all.keys('id', 'name', 'email');
|
||||
expect(data.user).to.include({active: true});
|
||||
});
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('pm.test("Array and object validations", function() {');
|
||||
expect(translatedCode).toContain('const data = pm.response.json();');
|
||||
expect(translatedCode).toContain('pm.expect(data.items).to.be.an(\'array\');');
|
||||
expect(translatedCode).toContain('pm.expect(data.items).to.have.lengthOf.at.least(1);');
|
||||
expect(translatedCode).toContain('pm.expect(data.items[0]).to.have.property(\'id\');');
|
||||
expect(translatedCode).toContain('pm.expect(data.user).to.be.an(\'object\');');
|
||||
expect(translatedCode).toContain('pm.expect(data.user).to.have.all.keys(\'id\', \'name\', \'email\');');
|
||||
expect(translatedCode).toContain('pm.expect(data.user).to.include({active: true});');
|
||||
});
|
||||
|
||||
it('should handle expect.fail with conditions', () => {
|
||||
const code = `
|
||||
test("Validate critical fields", function() {
|
||||
const data = res.getBody();
|
||||
|
||||
if (!data.id) {
|
||||
expect.fail("Missing ID field");
|
||||
}
|
||||
|
||||
if (data.status !== 'active' && data.status !== 'pending') {
|
||||
expect.fail("Invalid status: " + data.status);
|
||||
}
|
||||
|
||||
// Continue with normal assertions
|
||||
expect(data.name).to.be.a('string');
|
||||
});
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('pm.test("Validate critical fields", function() {');
|
||||
expect(translatedCode).toContain('const data = pm.response.json();');
|
||||
expect(translatedCode).toContain('if (!data.id) {');
|
||||
expect(translatedCode).toContain('pm.expect.fail("Missing ID field");');
|
||||
expect(translatedCode).toContain('if (data.status !== \'active\' && data.status !== \'pending\') {');
|
||||
expect(translatedCode).toContain('pm.expect.fail("Invalid status: " + data.status);');
|
||||
expect(translatedCode).toContain('pm.expect(data.name).to.be.a(\'string\');');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,103 @@
|
||||
import translateBruToPostman from '../../../src/utils/bruno-to-postman-translator';
|
||||
|
||||
describe('Bruno to Postman Variables Translation', () => {
|
||||
// Regular variables tests
|
||||
it('should translate bru.getVar', () => {
|
||||
const code = 'bru.getVar("test");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.variables.get("test");');
|
||||
});
|
||||
|
||||
it('should translate bru.setVar', () => {
|
||||
const code = 'bru.setVar("test", "value");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.variables.set("test", "value");');
|
||||
});
|
||||
|
||||
it('should translate bru.hasVar', () => {
|
||||
const code = 'bru.hasVar("userId");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.variables.has("userId");');
|
||||
});
|
||||
|
||||
it('should translate bru.deleteVar', () => {
|
||||
const code = 'bru.deleteVar("tempVar");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.variables.unset("tempVar");');
|
||||
});
|
||||
|
||||
it('should translate bru.interpolate', () => {
|
||||
const code = 'bru.interpolate("Hello {{name}}");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.variables.replaceIn("Hello {{name}}");');
|
||||
});
|
||||
|
||||
it('should translate bru.interpolate with complex template', () => {
|
||||
const code = 'const greeting = bru.interpolate("Hello {{name}}, your user id is {{userId}}");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const greeting = pm.variables.replaceIn("Hello {{name}}, your user id is {{userId}}");');
|
||||
});
|
||||
|
||||
// Global variables tests
|
||||
it('should translate bru.getGlobalEnvVar', () => {
|
||||
const code = 'bru.getGlobalEnvVar("test");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.globals.get("test");');
|
||||
});
|
||||
|
||||
it('should translate bru.setGlobalEnvVar', () => {
|
||||
const code = 'bru.setGlobalEnvVar("test", "value");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.globals.set("test", "value");');
|
||||
});
|
||||
|
||||
// Collection variables tests
|
||||
it('should translate bru.getCollectionVar', () => {
|
||||
const code = 'bru.getCollectionVar("baseUrl");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.variables.get("baseUrl");');
|
||||
});
|
||||
|
||||
// Folder variables tests
|
||||
it('should translate bru.getFolderVar', () => {
|
||||
const code = 'bru.getFolderVar("folderToken");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.variables.get("folderToken");');
|
||||
});
|
||||
|
||||
// Request variables tests
|
||||
it('should translate bru.getRequestVar', () => {
|
||||
const code = 'bru.getRequestVar("requestId");';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.variables.get("requestId");');
|
||||
});
|
||||
|
||||
// Combined tests
|
||||
it('should handle conditional expressions with variable calls', () => {
|
||||
const code = 'const userStatus = bru.hasVar("userId") ? "logged-in" : "guest";';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('const userStatus = pm.variables.has("userId") ? "logged-in" : "guest";');
|
||||
});
|
||||
|
||||
it('should handle all variable methods together', () => {
|
||||
const code = `
|
||||
// All variable methods
|
||||
const hasUserId = bru.hasVar("userId");
|
||||
const userId = bru.getVar("userId");
|
||||
bru.setVar("requestTime", new Date().toISOString());
|
||||
|
||||
console.log(\`Has userId: \${hasUserId}, User ID: \${userId}\`);
|
||||
`;
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
|
||||
expect(translatedCode).toContain('const hasUserId = pm.variables.has("userId");');
|
||||
expect(translatedCode).toContain('const userId = pm.variables.get("userId");');
|
||||
expect(translatedCode).toContain('pm.variables.set("requestTime", new Date().toISOString());');
|
||||
});
|
||||
|
||||
it('should handle nested expressions with variables', () => {
|
||||
const code = 'bru.setVar("fullPath", bru.getEnvVar("baseUrl") + bru.getVar("endpoint"));';
|
||||
const translatedCode = translateBruToPostman(code);
|
||||
expect(translatedCode).toBe('pm.variables.set("fullPath", pm.environment.get("baseUrl") + pm.variables.get("endpoint"));');
|
||||
});
|
||||
});
|
||||
@@ -34,7 +34,7 @@ describe('Bruno to Postman Converter with Tests and Scripts', () => {
|
||||
},
|
||||
vars: {},
|
||||
assertions: [],
|
||||
tests: 'test("Status code is 200", () => {\n expect(res.status).to.eql(200);\n});\ntest("Body is not empty", () => {\n expect(res.text).not.to.eql("");\n});',
|
||||
tests: 'test("Status code is 200", () => {\n expect(res.status).to.eql(200);\n});\ntest("Body is not empty", () => {\n expect(res.body).not.to.eql("");\n});',
|
||||
docs: '',
|
||||
auth: {
|
||||
mode: 'none'
|
||||
@@ -56,7 +56,7 @@ describe('Bruno to Postman Converter with Tests and Scripts', () => {
|
||||
req: 'console.log("scripts-folder script line 1");\nconsole.log("scripts-folder script line 2")',
|
||||
res: 'console.log("scripts-folder script line 1");\nconsole.log("scripts-folder script line 2")'
|
||||
},
|
||||
tests: 'test("Status code is 200", () => {\n expect(res.status).to.eql(200);\n});\ntest("Body is not empty", () => {\n expect(res.text).not.to.eql("");\n});'
|
||||
tests: 'test("Status code is 200", () => {\n expect(res.status).to.eql(200);\n});\ntest("Body is not empty", () => {\n expect(res.body).not.to.eql("");\n});'
|
||||
},
|
||||
meta: {
|
||||
name: 'Scripts Folder',
|
||||
@@ -93,7 +93,7 @@ describe('Bruno to Postman Converter with Tests and Scripts', () => {
|
||||
},
|
||||
vars: {},
|
||||
assertions: [],
|
||||
tests: 'test("Status code is 200", () => {\n expect(res.status).to.eql(200);\n});\ntest("Body is not empty", () => {\n expect(res.text).not.to.eql("");\n});',
|
||||
tests: 'test("Status code is 200", () => {\n expect(res.status).to.eql(200);\n});\ntest("Body is not empty", () => {\n expect(res.body).not.to.eql("");\n});',
|
||||
docs: '',
|
||||
auth: {
|
||||
mode: 'none'
|
||||
@@ -115,7 +115,7 @@ describe('Bruno to Postman Converter with Tests and Scripts', () => {
|
||||
req: 'console.log("scripts-inner-folder script line 1");\nconsole.log("scripts-inner-folder script line 2")',
|
||||
res: 'console.log("scripts-inner-folder script line 1");\nconsole.log("scripts-inner-folder script line 2")'
|
||||
},
|
||||
tests: 'test("Status code is 200", () => {\n expect(res.status).to.eql(200);\n});\ntest("Body is not empty", () => {\n expect(res.text).not.to.eql("");\n});'
|
||||
tests: 'test("Status code is 200", () => {\n expect(res.status).to.eql(200);\n});\ntest("Body is not empty", () => {\n expect(res.body).not.to.eql("");\n});'
|
||||
},
|
||||
meta: {
|
||||
name: 'Scripts Inner Folder',
|
||||
@@ -152,7 +152,7 @@ describe('Bruno to Postman Converter with Tests and Scripts', () => {
|
||||
},
|
||||
vars: {},
|
||||
assertions: [],
|
||||
tests: 'test("Status code is 200", () => {\n expect(res.status).to.eql(200);\n});\ntest("Body is not empty", () => {\n expect(res.text).not.to.eql("");\n});',
|
||||
tests: 'test("Status code is 200", () => {\n expect(res.status).to.eql(200);\n});\ntest("Body is not empty", () => {\n expect(res.body).not.to.eql("");\n});',
|
||||
docs: '',
|
||||
auth: {
|
||||
mode: 'none'
|
||||
@@ -171,7 +171,7 @@ describe('Bruno to Postman Converter with Tests and Scripts', () => {
|
||||
req: 'console.log("root-request script line 1");\nconsole.log("root-request script line 2")',
|
||||
res: 'console.log("root-request script line 1");\nconsole.log("root-request script line 2")'
|
||||
},
|
||||
tests: 'test("Status code is 200", () => {\n expect(res.status).to.eql(200);\n});\ntest("Body is not empty", () => {\n expect(res.text).not.to.eql("");\n});'
|
||||
tests: 'test("Status code is 200", () => {\n expect(res.status).to.eql(200);\n});\ntest("Body is not empty", () => {\n expect(res.body).not.to.eql("");\n});'
|
||||
}
|
||||
},
|
||||
brunoConfig: {
|
||||
@@ -204,11 +204,11 @@ describe('Bruno to Postman Converter with Tests and Scripts', () => {
|
||||
'console.log("root-request script line 2")',
|
||||
'',
|
||||
'// Tests',
|
||||
'test("Status code is 200", () => {',
|
||||
' expect(res.status).to.eql(200);',
|
||||
'pm.test("Status code is 200", () => {',
|
||||
' pm.expect(pm.response.code).to.eql(200);',
|
||||
'});',
|
||||
'test("Body is not empty", () => {',
|
||||
' expect(res.text).not.to.eql("");',
|
||||
'pm.test("Body is not empty", () => {',
|
||||
' pm.expect(pm.response.body).not.to.eql("");',
|
||||
'});'
|
||||
]);
|
||||
});
|
||||
@@ -230,11 +230,11 @@ describe('Bruno to Postman Converter with Tests and Scripts', () => {
|
||||
'console.log("scripts-folder script line 2")',
|
||||
'',
|
||||
'// Tests',
|
||||
'test("Status code is 200", () => {',
|
||||
' expect(res.status).to.eql(200);',
|
||||
'pm.test("Status code is 200", () => {',
|
||||
' pm.expect(pm.response.code).to.eql(200);',
|
||||
'});',
|
||||
'test("Body is not empty", () => {',
|
||||
' expect(res.text).not.to.eql("");',
|
||||
'pm.test("Body is not empty", () => {',
|
||||
' pm.expect(pm.response.body).not.to.eql("");',
|
||||
'});'
|
||||
]);
|
||||
});
|
||||
@@ -257,11 +257,11 @@ describe('Bruno to Postman Converter with Tests and Scripts', () => {
|
||||
'console.log("scripts-inner-folder script line 2")',
|
||||
'',
|
||||
'// Tests',
|
||||
'test("Status code is 200", () => {',
|
||||
' expect(res.status).to.eql(200);',
|
||||
'pm.test("Status code is 200", () => {',
|
||||
' pm.expect(pm.response.code).to.eql(200);',
|
||||
'});',
|
||||
'test("Body is not empty", () => {',
|
||||
' expect(res.text).not.to.eql("");',
|
||||
'pm.test("Body is not empty", () => {',
|
||||
' pm.expect(pm.response.body).not.to.eql("");',
|
||||
'});'
|
||||
]);
|
||||
});
|
||||
@@ -282,11 +282,11 @@ describe('Bruno to Postman Converter with Tests and Scripts', () => {
|
||||
'console.log("root-request script line 2")',
|
||||
'',
|
||||
'// Tests',
|
||||
'test("Status code is 200", () => {',
|
||||
' expect(res.status).to.eql(200);',
|
||||
'pm.test("Status code is 200", () => {',
|
||||
' pm.expect(pm.response.code).to.eql(200);',
|
||||
'});',
|
||||
'test("Body is not empty", () => {',
|
||||
' expect(res.text).not.to.eql("");',
|
||||
'pm.test("Body is not empty", () => {',
|
||||
' pm.expect(pm.response.body).not.to.eql("");',
|
||||
'});'
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { default: postmanTranslation } = require('../../../src/postman/postman-translations');
|
||||
import postmanTranslation from '../../../src/postman/postman-translations';
|
||||
|
||||
describe('postmanTranslations - comment handling', () => {
|
||||
test('should not translate non-pm commands', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { default: postmanTranslation } = require('../../../src/postman/postman-translations');
|
||||
import postmanTranslation from '../../../src/postman/postman-translations';
|
||||
|
||||
describe('postmanTranslations - cookie API conversions', () => {
|
||||
test('should convert pm.cookies.jar().get to bru.cookies.jar().getCookie', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { default: postmanTranslation } = require('../../../src/postman/postman-translations');
|
||||
import postmanTranslation from '../../../src/postman/postman-translations';
|
||||
|
||||
describe('postmanTranslations - edge cases', () => {
|
||||
test('should handle nested commands and edge cases', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { default: postmanTranslation } = require('../../../src/postman/postman-translations');
|
||||
import postmanTranslation from '../../../src/postman/postman-translations';
|
||||
|
||||
describe('postmanTranslations - test commands', () => {
|
||||
test('should handle test commands', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { default: postmanTranslation } = require('../../../src/postman/postman-translations');
|
||||
import postmanTranslation from '../../../src/postman/postman-translations';
|
||||
|
||||
describe('postmanTranslations - variables commands', () => {
|
||||
test('should translate variable commands correctly', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import translateCode from '../../../../src/utils/jscode-shift-translator';
|
||||
import translateCode from '../../../../src/utils/postman-to-bruno-translator';
|
||||
|
||||
describe('Combined API Features Translation', () => {
|
||||
// Basic translation test
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import translateCode from '../../../../src/utils/jscode-shift-translator';
|
||||
import translateCode from '../../../../src/utils/postman-to-bruno-translator';
|
||||
|
||||
describe('Environment Variable Translation', () => {
|
||||
it('should translate pm.environment.get', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import translateCode from '../../../../src/utils/jscode-shift-translator';
|
||||
import translateCode from '../../../../src/utils/postman-to-bruno-translator';
|
||||
|
||||
describe('Execution Flow Translation', () => {
|
||||
// Request flow control
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import translateCode from '../../../../src/utils/jscode-shift-translator.js';
|
||||
import translateCode from '../../../../src/utils/postman-to-bruno-translator';
|
||||
|
||||
describe('Legacy Postman API Translation', () => {
|
||||
describe('handleLegacyGlobalAPIs - No Conflicts', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import translateCode from '../../../../src/utils/jscode-shift-translator';
|
||||
import translateCode from '../../../../src/utils/postman-to-bruno-translator';
|
||||
|
||||
describe('Legacy Tests[] Syntax Translation', () => {
|
||||
it('should handle tests[] commands', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import translateCode from '../../../../src/utils/jscode-shift-translator';
|
||||
import translateCode from '../../../../src/utils/postman-to-bruno-translator';
|
||||
|
||||
describe('Multiline Syntax Handling', () => {
|
||||
it('should handle basic multiline variable syntax with indentation', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import translateCode from '../../../../src/utils/jscode-shift-translator';
|
||||
import translateCode from '../../../../src/utils/postman-to-bruno-translator';
|
||||
|
||||
describe('Postman to PM References Conversion', () => {
|
||||
// Basic conversions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import translateCode from '../../../../src/utils/jscode-shift-translator';
|
||||
import translateCode from '../../../../src/utils/postman-to-bruno-translator';
|
||||
|
||||
describe('Request Translation', () => {
|
||||
it('should translate pm.request.url', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import translateCode from '../../../../src/utils/jscode-shift-translator';
|
||||
import translateCode from '../../../../src/utils/postman-to-bruno-translator';
|
||||
|
||||
describe('Response Translation', () => {
|
||||
// Basic response property tests
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import translateCode from '../../../../src/utils/jscode-shift-translator';
|
||||
import translateCode from '../../../../src/utils/postman-to-bruno-translator';
|
||||
|
||||
describe('Scoped Variables', () => {
|
||||
it.skip('should handle scoped variables correctly', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import translateCode from '../../../../src/utils/jscode-shift-translator';
|
||||
import translateCode from '../../../../src/utils/postman-to-bruno-translator';
|
||||
|
||||
describe('Testing Framework Translation', () => {
|
||||
// Basic testing framework translations
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import translateCode from '../../../../../src/utils/jscode-shift-translator';
|
||||
import translateCode from '../../../../../src/utils/postman-to-bruno-translator';
|
||||
|
||||
describe('Send Request Translation', () => {
|
||||
describe('Raw Body Mode', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import translateCode from '../../../../src/utils/jscode-shift-translator';
|
||||
import translateCode from '../../../../src/utils/postman-to-bruno-translator';
|
||||
|
||||
describe('Variable Chaining Resolution', () => {
|
||||
test('should resolve a simple variable chain (variable pointing to another variable)', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import translateCode from '../../../../src/utils/jscode-shift-translator';
|
||||
import translateCode from '../../../../src/utils/postman-to-bruno-translator';
|
||||
|
||||
describe('Variables Translation', () => {
|
||||
// Regular variables tests
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from '@jest/globals';
|
||||
import { getMemberExpressionString } from '../../src/utils/jscode-shift-translator';
|
||||
const { describe, it, expect } = require('@jest/globals');
|
||||
const { getMemberExpressionString } = require('../../src/utils/ast-utils');
|
||||
const j = require('jscodeshift');
|
||||
|
||||
describe('getMemberExpressionString', () => {
|
||||
|
||||
Reference in New Issue
Block a user