From 23531ec7af9837b8d5ea9d564cfd8c483b31df5c Mon Sep 17 00:00:00 2001 From: lohxt1 Date: Tue, 22 Oct 2024 16:32:49 +0530 Subject: [PATCH 1/3] feat: updates --- .../components/ResponsePane/TestResults/index.js | 7 ++++++- .../ReduxStore/slices/collections/actions.js | 13 ++++++++++++- .../ReduxStore/slices/collections/index.js | 2 ++ .../importers/translators/postman_translation.js | 3 +++ packages/bruno-js/src/test.js | 10 ++++++++-- 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/packages/bruno-app/src/components/ResponsePane/TestResults/index.js b/packages/bruno-app/src/components/ResponsePane/TestResults/index.js index 074fac9e1d..67462e72d7 100644 --- a/packages/bruno-app/src/components/ResponsePane/TestResults/index.js +++ b/packages/bruno-app/src/components/ResponsePane/TestResults/index.js @@ -28,7 +28,12 @@ const TestResults = ({ results, assertionResults }) => { <> ✘  {result.description}
- {result.error} + { + Array.isArray(result?.error)? + result?.error?.map(error=><>{error}
) + : + {result.error} + } )} diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js index 066889d682..f4eddd8088 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js @@ -34,7 +34,8 @@ import { resetRunResults, responseReceived, updateLastAction, - setCollectionSecurityConfig + setCollectionSecurityConfig, + responseCleared } from './index'; import { each } from 'lodash'; @@ -235,6 +236,16 @@ export const sendRequest = (item, collectionUid) => (dispatch, getState) => { collectionCopy.globalEnvironmentVariables = globalEnvironmentVariables; const environment = findEnvironmentInCollection(collectionCopy, collectionCopy.activeEnvironmentUid); + + // clear the old response + dispatch( + responseCleared({ + itemUid: item.uid, + collectionUid: collectionUid, + response: null + }) + ); + sendNetworkRequest(itemCopy, collectionCopy, environment, collectionCopy.runtimeVariables) .then((response) => { return dispatch( diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js index b7ef2f86e5..f5014e0ac9 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js @@ -277,6 +277,8 @@ export const collectionsSlice = createSlice({ const item = findItemInCollection(collection, action.payload.itemUid); if (item) { item.response = null; + item.assertionResults = null; + item.testResults = null; } } }, diff --git a/packages/bruno-app/src/utils/importers/translators/postman_translation.js b/packages/bruno-app/src/utils/importers/translators/postman_translation.js index bd60fbcac9..e1c518bbd6 100644 --- a/packages/bruno-app/src/utils/importers/translators/postman_translation.js +++ b/packages/bruno-app/src/utils/importers/translators/postman_translation.js @@ -7,8 +7,11 @@ const replacements = { 'pm\\.collectionVariables\\.set\\(': 'bru.setVar(', 'pm\\.setNextRequest\\(': 'bru.setNextRequest(', 'pm\\.test\\(': 'test(', + 'pm\\.response\\.headers\\.get\\(': 'res.getHeader(', 'pm.response.to.have\\.status\\(': 'expect(res.getStatus()).to.equal(', 'pm\\.response\\.to\\.have\\.status\\(': 'expect(res.getStatus()).to.equal(', + 'pm\\.response\\.to\\.have\\.body\\(': 'expect(res.getBody()).to.equal(', + 'pm\\.response\\.to\\.have\\.header\\(': 'expect(res.getHeader()).to.equal(', 'pm\\.response\\.json\\(': 'res.getBody(', 'pm\\.expect\\(': 'expect(', 'pm\\.environment\\.has\\(([^)]+)\\)': 'bru.getEnvVar($1) !== undefined && bru.getEnvVar($1) !== null', diff --git a/packages/bruno-js/src/test.js b/packages/bruno-js/src/test.js index dd449e740e..e4fe65b698 100644 --- a/packages/bruno-js/src/test.js +++ b/packages/bruno-js/src/test.js @@ -3,7 +3,6 @@ const Test = (__brunoTestResults, chai) => async (description, callback) => { await callback(); __brunoTestResults.addResult({ description, status: 'pass' }); } catch (error) { - console.log(chai.AssertionError); if (error instanceof chai.AssertionError) { const { message, actual, expected } = error; __brunoTestResults.addResult({ @@ -14,10 +13,17 @@ const Test = (__brunoTestResults, chai) => async (description, callback) => { expected }); } else { + const errorStackLines = error.stack.split("\n"); + const lineInfo = errorStackLines[1]; + const lineNumber = lineInfo?.split(':')?.at?.(-2); + const columnNumber = lineInfo?.split(':')?.at?.(-1); __brunoTestResults.addResult({ description, status: 'fail', - error: error.message || 'An unexpected error occurred.' + error: [ + `Error occurred at line ${lineNumber} and character ${columnNumber}`, + `${error.message || 'An unexpected error occurred.'}` + ] }); } console.log(error); From a6b54d8d9cefda5fc89fdc4b6d8c71f9934e28aa Mon Sep 17 00:00:00 2001 From: lohxt1 Date: Fri, 25 Oct 2024 15:12:39 +0530 Subject: [PATCH 2/3] feat: updates --- packages/bruno-js/src/runtime/test-runtime.js | 37 ++++++++++++++++--- packages/bruno-js/src/test.js | 4 +- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/packages/bruno-js/src/runtime/test-runtime.js b/packages/bruno-js/src/runtime/test-runtime.js index 5391f7e108..9dd23b03b8 100644 --- a/packages/bruno-js/src/runtime/test-runtime.js +++ b/packages/bruno-js/src/runtime/test-runtime.js @@ -114,10 +114,21 @@ class TestRuntime { } if (this.runtime === 'quickjs') { - await executeQuickJsVmAsync({ - script: testsFile, - context: context - }); + try { + await executeQuickJsVmAsync({ + script: testsFile, + context: context + }); + } + catch(error) { + __brunoTestResults.addResult({ + description: 'Invalid test script', + status: 'fail', + error: [ + `${error.message || 'An unexpected error occurred.'}` + ] + }); + } } else { // default runtime is vm2 const vm = new NodeVM({ @@ -156,7 +167,23 @@ class TestRuntime { } }); const asyncVM = vm.run(`module.exports = async () => { ${testsFile}}`, path.join(collectionPath, 'vm.js')); - await asyncVM(); + try { + await asyncVM(); + } + catch(error) { + const errorStackLines = error?.stack?.split?.("\n"); + const lineInfo = errorStackLines?.[1]; + const lineNumber = lineInfo?.split(':')?.at?.(-2); + const columnNumber = lineInfo?.split(':')?.at?.(-1); + __brunoTestResults.addResult({ + description: 'Invalid test script', + status: 'fail', + error: [ + `Error occurred at line ${lineNumber} and character ${columnNumber}`, + `${error.message || 'An unexpected error occurred.'}` + ] + }); + } } return { diff --git a/packages/bruno-js/src/test.js b/packages/bruno-js/src/test.js index e4fe65b698..bc7ef375c4 100644 --- a/packages/bruno-js/src/test.js +++ b/packages/bruno-js/src/test.js @@ -13,8 +13,8 @@ const Test = (__brunoTestResults, chai) => async (description, callback) => { expected }); } else { - const errorStackLines = error.stack.split("\n"); - const lineInfo = errorStackLines[1]; + const errorStackLines = error?.stack?.split?.("\n"); + const lineInfo = errorStackLines?.[1]; const lineNumber = lineInfo?.split(':')?.at?.(-2); const columnNumber = lineInfo?.split(':')?.at?.(-1); __brunoTestResults.addResult({ From 16bf5245ab088d59a2717474f60c691f54398bd5 Mon Sep 17 00:00:00 2001 From: lohxt1 Date: Fri, 25 Oct 2024 15:14:26 +0530 Subject: [PATCH 3/3] feat: revert changes --- .../src/utils/importers/translators/postman_translation.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/bruno-app/src/utils/importers/translators/postman_translation.js b/packages/bruno-app/src/utils/importers/translators/postman_translation.js index e1c518bbd6..bd60fbcac9 100644 --- a/packages/bruno-app/src/utils/importers/translators/postman_translation.js +++ b/packages/bruno-app/src/utils/importers/translators/postman_translation.js @@ -7,11 +7,8 @@ const replacements = { 'pm\\.collectionVariables\\.set\\(': 'bru.setVar(', 'pm\\.setNextRequest\\(': 'bru.setNextRequest(', 'pm\\.test\\(': 'test(', - 'pm\\.response\\.headers\\.get\\(': 'res.getHeader(', 'pm.response.to.have\\.status\\(': 'expect(res.getStatus()).to.equal(', 'pm\\.response\\.to\\.have\\.status\\(': 'expect(res.getStatus()).to.equal(', - 'pm\\.response\\.to\\.have\\.body\\(': 'expect(res.getBody()).to.equal(', - 'pm\\.response\\.to\\.have\\.header\\(': 'expect(res.getHeader()).to.equal(', 'pm\\.response\\.json\\(': 'res.getBody(', 'pm\\.expect\\(': 'expect(', 'pm\\.environment\\.has\\(([^)]+)\\)': 'bru.getEnvVar($1) !== undefined && bru.getEnvVar($1) !== null',