From d34697024167d6a4f9da0a4003ecfd33cab2c08d Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Wed, 29 Mar 2023 12:43:47 +0530 Subject: [PATCH] fix: fixed issue where unsaved changes where not being picked up while running tests (#125) --- .../bruno-electron/src/ipc/network/index.js | 36 +++++++++---------- packages/bruno-js/src/runtime/test-runtime.js | 9 +++++ 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/packages/bruno-electron/src/ipc/network/index.js b/packages/bruno-electron/src/ipc/network/index.js index de3d2d3b..f8d6cec3 100644 --- a/packages/bruno-electron/src/ipc/network/index.js +++ b/packages/bruno-electron/src/ipc/network/index.js @@ -179,17 +179,15 @@ const registerNetworkIpc = (mainWindow, watcher, lastOpenedCollections) => { }); // run tests - const testFile = get(item, 'request.tests'); - if(testFile && testFile.length) { - const testRuntime = new TestRuntime(); - const result = testRuntime.runTests(testFile, request, response, envVars, collectionVariables, collectionPath); + const testFile = item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests'); + const testRuntime = new TestRuntime(); + const testResults = testRuntime.runTests(testFile, request, response, envVars, collectionVariables, collectionPath); - mainWindow.webContents.send('main:test-results', { - results: result.results, - itemUid: item.uid, - collectionUid - }); - } + mainWindow.webContents.send('main:test-results', { + results: testResults.results, + itemUid: item.uid, + collectionUid + }); deleteCancelToken(cancelTokenUid); @@ -407,17 +405,15 @@ const registerNetworkIpc = (mainWindow, watcher, lastOpenedCollections) => { } // run tests - const testFile = get(item, 'request.tests'); - if(testFile && testFile.length) { - const testRuntime = new TestRuntime(); - const result = testRuntime.runTests(testFile, request, response, envVars, collectionVariables, collectionPath); + const testFile = item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests'); + const testRuntime = new TestRuntime(); + const testResults = testRuntime.runTests(testFile, request, response, envVars, collectionVariables, collectionPath); - mainWindow.webContents.send('main:run-folder-event', { - type: 'test-results', - testResults: result.results, - ...eventData - }); - } + mainWindow.webContents.send('main:run-folder-event', { + type: 'test-results', + testResults: testResults.results, + ...eventData + }); mainWindow.webContents.send('main:run-folder-event', { type: 'response-received', diff --git a/packages/bruno-js/src/runtime/test-runtime.js b/packages/bruno-js/src/runtime/test-runtime.js index 8ad12603..1fe9f202 100644 --- a/packages/bruno-js/src/runtime/test-runtime.js +++ b/packages/bruno-js/src/runtime/test-runtime.js @@ -28,6 +28,15 @@ class TestRuntime { const __brunoTestResults = new TestResults(); const test = Test(__brunoTestResults, chai); + if(!testsFile || !testsFile.length) { + return { + request, + envVariables, + collectionVariables, + results: __brunoTestResults.getResults() + }; + } + const context = { test, bru,