mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-11 09:51:30 +00:00
fix: 3093 - Fix pm.setNextRequest(null) not translating to bru.runner.stopExecution() (#8049)
* fix: 3093 - Fix pm.setNextRequest(null) not translating to bru.runner.stopExecution() * addressed review comments * addressed review comments
This commit is contained in:
@@ -15,7 +15,9 @@ const replacements = {
|
|||||||
// 'pm\\.collectionVariables\\.unset\\(': 'bru.deleteCollectionVar(',
|
// 'pm\\.collectionVariables\\.unset\\(': 'bru.deleteCollectionVar(',
|
||||||
// 'pm\\.collectionVariables\\.clear\\(': 'bru.deleteAllCollectionVars(',
|
// 'pm\\.collectionVariables\\.clear\\(': 'bru.deleteAllCollectionVars(',
|
||||||
// 'pm\\.collectionVariables\\.toObject\\(': 'bru.getAllCollectionVars(',
|
// 'pm\\.collectionVariables\\.toObject\\(': 'bru.getAllCollectionVars(',
|
||||||
'pm\\.setNextRequest\\(': 'bru.setNextRequest(',
|
'pm\\.setNextRequest\\(null\\)': 'bru.runner.stopExecution()',
|
||||||
|
'pm\\.setNextRequest\\([\'\"]null[\'\"]\\)': 'bru.runner.stopExecution()',
|
||||||
|
'pm\\.setNextRequest\\(': 'bru.runner.setNextRequest(',
|
||||||
'pm\\.test\\(': 'test(',
|
'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\\.to\\.have\\.status\\(': 'expect(res.getStatus()).to.equal(',
|
||||||
|
|||||||
@@ -41,9 +41,6 @@ const simpleTranslations = {
|
|||||||
// 'pm.collectionVariables.clear': 'bru.deleteAllCollectionVars',
|
// 'pm.collectionVariables.clear': 'bru.deleteAllCollectionVars',
|
||||||
// 'pm.collectionVariables.toObject': 'bru.getAllCollectionVars',
|
// 'pm.collectionVariables.toObject': 'bru.getAllCollectionVars',
|
||||||
|
|
||||||
// Request flow control
|
|
||||||
'pm.setNextRequest': 'bru.setNextRequest',
|
|
||||||
|
|
||||||
// Testing
|
// Testing
|
||||||
'pm.test': 'test',
|
'pm.test': 'test',
|
||||||
'pm.expect': 'expect',
|
'pm.expect': 'expect',
|
||||||
@@ -267,6 +264,29 @@ const complexTransformations = [
|
|||||||
}
|
}
|
||||||
})),
|
})),
|
||||||
|
|
||||||
|
// Handle pm.setNextRequest(null) / pm.setNextRequest('null') — stop the runner
|
||||||
|
{
|
||||||
|
pattern: 'pm.setNextRequest',
|
||||||
|
transform: (path, j) => {
|
||||||
|
const callExpr = path.parent.value;
|
||||||
|
const args = callExpr.arguments;
|
||||||
|
|
||||||
|
if (
|
||||||
|
args[0] && args[0].type === 'Literal' && (args[0].value === null || args[0].value === 'null')
|
||||||
|
) {
|
||||||
|
return j.callExpression(
|
||||||
|
j.identifier('bru.runner.stopExecution'),
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return j.callExpression(
|
||||||
|
j.identifier('bru.runner.setNextRequest'),
|
||||||
|
args
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// Handle pm.execution.setNextRequest(null)
|
// Handle pm.execution.setNextRequest(null)
|
||||||
{
|
{
|
||||||
pattern: 'pm.execution.setNextRequest',
|
pattern: 'pm.execution.setNextRequest',
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ const status = res.getStatus();
|
|||||||
const data = res.getBody();
|
const data = res.getBody();
|
||||||
|
|
||||||
if (status === 200 && data.hasMore) {
|
if (status === 200 && data.hasMore) {
|
||||||
bru.setNextRequest("Fetch Next Page");
|
bru.runner.setNextRequest("Fetch Next Page");
|
||||||
} else if (status === 429) {
|
} else if (status === 429) {
|
||||||
console.log("Rate limited, skipping");
|
console.log("Rate limited, skipping");
|
||||||
bru.runner.skipRequest();
|
bru.runner.skipRequest();
|
||||||
|
|||||||
@@ -5,7 +5,25 @@ describe('Execution Flow Translation', () => {
|
|||||||
it('should translate pm.setNextRequest', () => {
|
it('should translate pm.setNextRequest', () => {
|
||||||
const code = 'pm.setNextRequest("Get User Details");';
|
const code = 'pm.setNextRequest("Get User Details");';
|
||||||
const translatedCode = translateCode(code);
|
const translatedCode = translateCode(code);
|
||||||
expect(translatedCode).toBe('bru.setNextRequest("Get User Details");');
|
expect(translatedCode).toBe('bru.runner.setNextRequest("Get User Details");');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should translate pm.setNextRequest(null) to bru.runner.stopExecution()', () => {
|
||||||
|
const code = 'pm.setNextRequest(null);';
|
||||||
|
const translatedCode = translateCode(code);
|
||||||
|
expect(translatedCode).toBe('bru.runner.stopExecution();');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should translate pm.setNextRequest("null") to bru.runner.stopExecution()', () => {
|
||||||
|
const code = 'pm.setNextRequest("null");';
|
||||||
|
const translatedCode = translateCode(code);
|
||||||
|
expect(translatedCode).toBe('bru.runner.stopExecution();');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should keep pm.setNextRequest(<request name>) as bru.setNextRequest(<request name>) for non-null arguments', () => {
|
||||||
|
const code = 'pm.setNextRequest("Get User Details");';
|
||||||
|
const translatedCode = translateCode(code);
|
||||||
|
expect(translatedCode).toBe('bru.runner.setNextRequest("Get User Details");');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should translate pm.execution.skipRequest', () => {
|
it('should translate pm.execution.skipRequest', () => {
|
||||||
@@ -59,6 +77,6 @@ describe('Execution Flow Translation', () => {
|
|||||||
expect(translatedCode).toContain('} else if (res.getStatus() === 500) {');
|
expect(translatedCode).toContain('} else if (res.getStatus() === 500) {');
|
||||||
expect(translatedCode).toContain('bru.runner.stopExecution();');
|
expect(translatedCode).toContain('bru.runner.stopExecution();');
|
||||||
expect(translatedCode).toContain('} else {');
|
expect(translatedCode).toContain('} else {');
|
||||||
expect(translatedCode).toContain('bru.setNextRequest("Get User Details");');
|
expect(translatedCode).toContain('bru.runner.setNextRequest("Get User Details");');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -71,9 +71,9 @@ describe('Postman to PM References Conversion', () => {
|
|||||||
const translatedCode = translateCode(code);
|
const translatedCode = translateCode(code);
|
||||||
expect(translatedCode).toContain('if (bru.getEnvVar("isProduction") === "true") {');
|
expect(translatedCode).toContain('if (bru.getEnvVar("isProduction") === "true") {');
|
||||||
expect(translatedCode).toContain('const apiUrl = bru.getEnvVar("prodUrl");');
|
expect(translatedCode).toContain('const apiUrl = bru.getEnvVar("prodUrl");');
|
||||||
expect(translatedCode).toContain('bru.setNextRequest("Production Flow");');
|
expect(translatedCode).toContain('bru.runner.setNextRequest("Production Flow");');
|
||||||
expect(translatedCode).toContain('const apiUrl = bru.getEnvVar("devUrl");');
|
expect(translatedCode).toContain('const apiUrl = bru.getEnvVar("devUrl");');
|
||||||
expect(translatedCode).toContain('bru.setNextRequest("Development Flow");');
|
expect(translatedCode).toContain('bru.runner.setNextRequest("Development Flow");');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Legacy response handling
|
// Legacy response handling
|
||||||
|
|||||||
Reference in New Issue
Block a user