diff --git a/packages/bruno-converters/src/postman/postman-translations.js b/packages/bruno-converters/src/postman/postman-translations.js index 9c60f07e2..2da15b7c0 100644 --- a/packages/bruno-converters/src/postman/postman-translations.js +++ b/packages/bruno-converters/src/postman/postman-translations.js @@ -15,7 +15,9 @@ const replacements = { // 'pm\\.collectionVariables\\.unset\\(': 'bru.deleteCollectionVar(', // 'pm\\.collectionVariables\\.clear\\(': 'bru.deleteAllCollectionVars(', // '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.response.to.have\\.status\\(': 'expect(res.getStatus()).to.equal(', 'pm\\.response\\.to\\.have\\.status\\(': 'expect(res.getStatus()).to.equal(', diff --git a/packages/bruno-converters/src/utils/postman-to-bruno-translator.js b/packages/bruno-converters/src/utils/postman-to-bruno-translator.js index 065ed20d3..3b222bf50 100644 --- a/packages/bruno-converters/src/utils/postman-to-bruno-translator.js +++ b/packages/bruno-converters/src/utils/postman-to-bruno-translator.js @@ -41,9 +41,6 @@ const simpleTranslations = { // 'pm.collectionVariables.clear': 'bru.deleteAllCollectionVars', // 'pm.collectionVariables.toObject': 'bru.getAllCollectionVars', - // Request flow control - 'pm.setNextRequest': 'bru.setNextRequest', - // Testing 'pm.test': 'test', '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) { pattern: 'pm.execution.setNextRequest', diff --git a/packages/bruno-converters/tests/bruno/bruno-to-postman-translations/execution.test.js b/packages/bruno-converters/tests/bruno/bruno-to-postman-translations/execution.test.js index 2171cceb5..0df9edef8 100644 --- a/packages/bruno-converters/tests/bruno/bruno-to-postman-translations/execution.test.js +++ b/packages/bruno-converters/tests/bruno/bruno-to-postman-translations/execution.test.js @@ -79,7 +79,7 @@ const status = res.getStatus(); const data = res.getBody(); if (status === 200 && data.hasMore) { - bru.setNextRequest("Fetch Next Page"); + bru.runner.setNextRequest("Fetch Next Page"); } else if (status === 429) { console.log("Rate limited, skipping"); bru.runner.skipRequest(); diff --git a/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/exec-flow.test.js b/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/exec-flow.test.js index d52f08519..e4185652b 100644 --- a/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/exec-flow.test.js +++ b/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/exec-flow.test.js @@ -5,7 +5,25 @@ describe('Execution Flow Translation', () => { it('should translate pm.setNextRequest', () => { const code = 'pm.setNextRequest("Get User Details");'; 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() as bru.setNextRequest() 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', () => { @@ -59,6 +77,6 @@ describe('Execution Flow Translation', () => { expect(translatedCode).toContain('} else if (res.getStatus() === 500) {'); expect(translatedCode).toContain('bru.runner.stopExecution();'); expect(translatedCode).toContain('} else {'); - expect(translatedCode).toContain('bru.setNextRequest("Get User Details");'); + expect(translatedCode).toContain('bru.runner.setNextRequest("Get User Details");'); }); }); diff --git a/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/postman-references.test.js b/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/postman-references.test.js index a7618561f..c65f6dadd 100644 --- a/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/postman-references.test.js +++ b/packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/postman-references.test.js @@ -71,9 +71,9 @@ describe('Postman to PM References Conversion', () => { const translatedCode = translateCode(code); expect(translatedCode).toContain('if (bru.getEnvVar("isProduction") === "true") {'); 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('bru.setNextRequest("Development Flow");'); + expect(translatedCode).toContain('bru.runner.setNextRequest("Development Flow");'); }); // Legacy response handling