mirror of
https://github.com/usebruno/bruno.git
synced 2025-06-21 12:33:34 +02:00
feat: allow translation of more postman scripts (#2054)
This commit is contained in:
parent
e149c8dc9a
commit
4df78910f5
@ -9,6 +9,8 @@ describe('postmanTranslation function', () => {
|
||||
pm.variables.set('key', 'value');
|
||||
pm.collectionVariables.get('key');
|
||||
pm.collectionVariables.set('key', 'value');
|
||||
const data = pm.response.json();
|
||||
pm.expect(pm.environment.has('key')).to.be.true;
|
||||
`;
|
||||
const expectedOutput = `
|
||||
bru.getEnvVar('key');
|
||||
@ -17,6 +19,8 @@ describe('postmanTranslation function', () => {
|
||||
bru.setVar('key', 'value');
|
||||
bru.getVar('key');
|
||||
bru.setVar('key', 'value');
|
||||
const data = res.getBody();
|
||||
expect(bru.getEnvVar('key') !== undefined && bru.getEnvVar('key') !== null).to.be.true;
|
||||
`;
|
||||
expect(postmanTranslation(inputScript)).toBe(expectedOutput);
|
||||
});
|
||||
@ -36,13 +40,14 @@ describe('postmanTranslation function', () => {
|
||||
});
|
||||
|
||||
test('should comment non-translated pm commands', () => {
|
||||
const inputScript = "pm.test('random test', () => pm.response.json());";
|
||||
const expectedOutput = "// test('random test', () => pm.response.json());";
|
||||
const inputScript = "pm.test('random test', () => pm.variables.replaceIn('{{$guid}}'));";
|
||||
const expectedOutput = "// test('random test', () => pm.variables.replaceIn('{{$guid}}'));";
|
||||
expect(postmanTranslation(inputScript)).toBe(expectedOutput);
|
||||
});
|
||||
test('should handle multiple pm commands on the same line', () => {
|
||||
const inputScript = "pm.environment.get('key'); pm.environment.set('key', 'value');";
|
||||
const expectedOutput = "bru.getEnv(var); bru.setEnvVar(var, 'value');";
|
||||
const expectedOutput = "bru.getEnvVar('key'); bru.setEnvVar('key', 'value');";
|
||||
expect(postmanTranslation(inputScript)).toBe(expectedOutput);
|
||||
});
|
||||
test('should handle comments and other JavaScript code', () => {
|
||||
const inputScript = `
|
||||
|
@ -7,7 +7,11 @@ const replacements = {
|
||||
'pm\\.collectionVariables\\.set\\(': 'bru.setVar(',
|
||||
'pm\\.setNextRequest\\(': 'bru.setNextRequest(',
|
||||
'pm\\.test\\(': 'test(',
|
||||
'pm.response.to.have\\.status\\(': 'expect(res.getStatus()).to.equal('
|
||||
'pm.response.to.have\\.status\\(': 'expect(res.getStatus()).to.equal(',
|
||||
'pm\\.response\\.to\\.have\\.status\\(': 'expect(res.getStatus()).to.equal(',
|
||||
'pm\\.response\\.json\\(': 'res.getBody(',
|
||||
'pm\\.expect\\(': 'expect(',
|
||||
'pm\\.environment\\.has\\(([^)]+)\\)': 'bru.getEnvVar($1) !== undefined && bru.getEnvVar($1) !== null'
|
||||
};
|
||||
|
||||
const compiledReplacements = Object.entries(replacements).map(([pattern, replacement]) => ({
|
||||
|
Loading…
x
Reference in New Issue
Block a user