diff --git a/packages/bruno-converters/src/postman/postman-translations.js b/packages/bruno-converters/src/postman/postman-translations.js index 28df382f4..540e8eaa7 100644 --- a/packages/bruno-converters/src/postman/postman-translations.js +++ b/packages/bruno-converters/src/postman/postman-translations.js @@ -15,8 +15,9 @@ const replacements = { // 'pm\\.collectionVariables\\.unset\\(': 'bru.deleteCollectionVar(', // 'pm\\.collectionVariables\\.clear\\(': 'bru.deleteAllCollectionVars(', // 'pm\\.collectionVariables\\.toObject\\(': 'bru.getAllCollectionVars(', + // Only the actual null literal stops the runner; the string 'null' is a valid + // request name and falls through to 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(', @@ -129,8 +130,9 @@ const replacements = { 'postman\\.clearEnvironmentVariable\\(': 'bru.deleteEnvVar(', 'pm\\.execution\\.skipRequest\\(\\)': 'bru.runner.skipRequest()', 'pm\\.execution\\.skipRequest': 'bru.runner.skipRequest', + // Only the actual null literal stops the runner; the string 'null' falls through to setNextRequest. 'pm\\.execution\\.setNextRequest\\(null\\)': 'bru.runner.stopExecution()', - 'pm\\.execution\\.setNextRequest\\(\'null\'\\)': 'bru.runner.stopExecution()', + 'pm\\.execution\\.setNextRequest\\(': 'bru.runner.setNextRequest(', // Cookie jar translations — order matters: // 1. Specific jar method patterns must come before the general jar() pattern, // otherwise jar() consumes the prefix and the method patterns never match. 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 10cfeea99..a70c2a831 100644 --- a/packages/bruno-converters/src/utils/postman-to-bruno-translator.js +++ b/packages/bruno-converters/src/utils/postman-to-bruno-translator.js @@ -265,16 +265,16 @@ const complexTransformations = [ } })), - // Handle pm.setNextRequest(null) / pm.setNextRequest('null') — stop the runner + // Handle pm.setNextRequest(null) — stop the runner. + // Note: the string 'null' is a valid request name in Postman, so only the + // actual null literal triggers stopExecution(); 'null' falls through to setNextRequest. { 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') - ) { + if (args[0] && args[0].type === 'Literal' && args[0].value === null) { return j.callExpression( j.identifier('bru.runner.stopExecution'), [] @@ -298,7 +298,7 @@ const complexTransformations = [ // If argument is null or 'null', transform to bru.runner.stopExecution() if ( - args[0].type === 'Literal' && (args[0].value === null || args[0].value === 'null') + args[0] && args[0].type === 'Literal' && (args[0].value === null) ) { return j.callExpression( j.identifier('bru.runner.stopExecution'), 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 0df9edef8..a2f7c29c1 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 @@ -14,6 +14,12 @@ describe('Bruno to Postman Execution Control Translation', () => { expect(translatedCode).toBe('pm.execution.setNextRequest("Create Order");'); }); + it('should preserve the string "null" as a request name when translating bru.runner.setNextRequest("null")', () => { + const code = 'bru.runner.setNextRequest("null");'; + const translatedCode = translateBruToPostman(code); + expect(translatedCode).toBe('pm.execution.setNextRequest("null");'); + }); + // skipRequest translation it('should translate bru.runner.skipRequest', () => { const code = '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 e4185652b..e67649346 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 @@ -14,10 +14,10 @@ describe('Execution Flow Translation', () => { expect(translatedCode).toBe('bru.runner.stopExecution();'); }); - it('should translate pm.setNextRequest("null") to bru.runner.stopExecution()', () => { + it('should translate pm.setNextRequest("null") to bru.runner.setNextRequest("null") (string is a valid request name)', () => { const code = 'pm.setNextRequest("null");'; const translatedCode = translateCode(code); - expect(translatedCode).toBe('bru.runner.stopExecution();'); + expect(translatedCode).toBe('bru.runner.setNextRequest("null");'); }); it('should keep pm.setNextRequest() as bru.setNextRequest() for non-null arguments', () => { @@ -38,10 +38,22 @@ describe('Execution Flow Translation', () => { expect(translatedCode).toBe('bru.runner.stopExecution();'); }); - it('should translate pm.execution.setNextRequest("null")', () => { + it('should translate pm.execution.setNextRequest("null") to bru.runner.setNextRequest("null") (string is a valid request name)', () => { const code = 'pm.execution.setNextRequest("null");'; const translatedCode = translateCode(code); - expect(translatedCode).toBe('bru.runner.stopExecution();'); + expect(translatedCode).toBe('bru.runner.setNextRequest("null");'); + }); + + it('should translate pm.execution.setNextRequest("req1") to bru.runner.setNextRequest("req1")', () => { + const code = 'pm.execution.setNextRequest("req1");'; + const translatedCode = translateCode(code); + expect(translatedCode).toBe('bru.runner.setNextRequest("req1");'); + }); + + it('should translate pm.execution.setNextRequest() with no arguments to bru.runner.setNextRequest()', () => { + const code = 'pm.execution.setNextRequest();'; + const translatedCode = translateCode(code); + expect(translatedCode).toBe('bru.runner.setNextRequest();'); }); it('should handle pm.execution.setNextRequest with non-null parameters', () => {