mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-11 09:51:30 +00:00
Fix/pm.set next request(null) not translating (#8062)
* fix: 3093 - Fix pm.setNextRequest(null) not translating to bru.runner.stopExecution()
* addressed review comments
* addressed review comments
* Behavioral change for null case and added transilation for pm.exicution.setNextRequest("req")
* addressed review comments
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -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();';
|
||||
|
||||
@@ -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(<request name>) as bru.setNextRequest(<request name>) 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', () => {
|
||||
|
||||
Reference in New Issue
Block a user