From 49b0f3a3223ad899c84a1e01cf983e7e3400eb29 Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Thu, 27 Apr 2023 19:25:52 +0530 Subject: [PATCH 1/6] fix(#148) : fixed issue where form url encoded params were not being interpolated --- packages/bruno-cli/src/runner/interpolate-vars.js | 9 +++++++++ packages/bruno-cli/src/runner/prepare-request.js | 3 +-- packages/bruno-cli/src/runner/run-single-request.js | 6 ++++++ packages/bruno-electron/src/ipc/network/index.js | 6 ++++++ .../bruno-electron/src/ipc/network/interpolate-vars.js | 9 +++++++++ .../bruno-electron/src/ipc/network/prepare-request.js | 3 +-- 6 files changed, 32 insertions(+), 4 deletions(-) diff --git a/packages/bruno-cli/src/runner/interpolate-vars.js b/packages/bruno-cli/src/runner/interpolate-vars.js index 6debaffb0..cf7109ad2 100644 --- a/packages/bruno-cli/src/runner/interpolate-vars.js +++ b/packages/bruno-cli/src/runner/interpolate-vars.js @@ -42,6 +42,15 @@ const interpolateVars = (request, envVars = {}, collectionVariables ={}) => { request.data = interpolate(request.data); } } + } else if(request.headers["content-type"] === "application/x-www-form-urlencoded") { + if(typeof request.data === "object") { + try { + let parsed = JSON.stringify(request.data); + parsed = interpolate(parsed); + request.data = JSON.parse(parsed); + } catch (err) { + } + } } else { request.data = interpolate(request.data); } diff --git a/packages/bruno-cli/src/runner/prepare-request.js b/packages/bruno-cli/src/runner/prepare-request.js index bcc388d9c..44d3465b8 100644 --- a/packages/bruno-cli/src/runner/prepare-request.js +++ b/packages/bruno-cli/src/runner/prepare-request.js @@ -1,5 +1,4 @@ const { get, each, filter } = require('lodash'); -const qs = require('qs'); const prepareRequest = (request) => { const headers = {}; @@ -41,7 +40,7 @@ const prepareRequest = (request) => { const params = {}; const enabledParams = filter(request.body.formUrlEncoded, (p) => p.enabled); each(enabledParams, (p) => (params[p.name] = p.value)); - axiosRequest.data = qs.stringify(params); + axiosRequest.data = params; } if (request.body.mode === 'multipartForm') { diff --git a/packages/bruno-cli/src/runner/run-single-request.js b/packages/bruno-cli/src/runner/run-single-request.js index 659536107..e2ce6a839 100644 --- a/packages/bruno-cli/src/runner/run-single-request.js +++ b/packages/bruno-cli/src/runner/run-single-request.js @@ -1,3 +1,4 @@ +const qs = require('qs'); const chalk = require('chalk'); const { forOwn, each, extend, get } = require('lodash'); const FormData = require('form-data'); @@ -39,6 +40,11 @@ const runSingleRequest = async function (filename, bruJson, collectionPath, coll // interpolate variables inside request interpolateVars(request, envVariables, collectionVariables); + // stringify the request url encoded params + if(request.headers['content-type'] = 'application/x-www-form-urlencoded') { + request.data = qs.stringify(request.data); + } + // run request const response = await axios(request); diff --git a/packages/bruno-electron/src/ipc/network/index.js b/packages/bruno-electron/src/ipc/network/index.js index 1c9b0ace4..734af95f5 100644 --- a/packages/bruno-electron/src/ipc/network/index.js +++ b/packages/bruno-electron/src/ipc/network/index.js @@ -1,3 +1,4 @@ +const qs = require('qs'); const axios = require('axios'); const Mustache = require('mustache'); const FormData = require('form-data'); @@ -124,6 +125,11 @@ const registerNetworkIpc = (mainWindow, watcher, lastOpenedCollections) => { interpolateVars(request, envVars, collectionVariables); + // stringify the request url encoded params + if(request.headers['content-type'] = 'application/x-www-form-urlencoded') { + request.data = qs.stringify(request.data); + } + // todo: // i have no clue why electron can't send the request object // without safeParseJSON(safeStringifyJSON(request.data)) diff --git a/packages/bruno-electron/src/ipc/network/interpolate-vars.js b/packages/bruno-electron/src/ipc/network/interpolate-vars.js index c9845f230..8e54430c1 100644 --- a/packages/bruno-electron/src/ipc/network/interpolate-vars.js +++ b/packages/bruno-electron/src/ipc/network/interpolate-vars.js @@ -42,6 +42,15 @@ const interpolateVars = (request, envVars = {}, collectionVariables ={}) => { request.data = interpolate(request.data); } } + } else if(request.headers["content-type"] === "application/x-www-form-urlencoded") { + if(typeof request.data === "object") { + try { + let parsed = JSON.stringify(request.data); + parsed = interpolate(parsed); + request.data = JSON.parse(parsed); + } catch (err) { + } + } } else { request.data = interpolate(request.data); } diff --git a/packages/bruno-electron/src/ipc/network/prepare-request.js b/packages/bruno-electron/src/ipc/network/prepare-request.js index ef2feb45e..9305c25ff 100644 --- a/packages/bruno-electron/src/ipc/network/prepare-request.js +++ b/packages/bruno-electron/src/ipc/network/prepare-request.js @@ -1,5 +1,4 @@ const { get, each, filter } = require('lodash'); -const qs = require('qs'); const prepareRequest = (request) => { const headers = {}; @@ -39,7 +38,7 @@ const prepareRequest = (request) => { const params = {}; const enabledParams = filter(request.body.formUrlEncoded, (p) => p.enabled); each(enabledParams, (p) => (params[p.name] = p.value)); - axiosRequest.data = qs.stringify(params); + axiosRequest.data = params; } if (request.body.mode === 'multipartForm') { From 3b85e7ebcc542aac09fd4913413b105d15c4d63d Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Thu, 27 Apr 2023 19:26:41 +0530 Subject: [PATCH 2/6] chore: version bump v0.12.1 --- packages/bruno-app/src/components/Sidebar/index.js | 2 +- packages/bruno-electron/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/bruno-app/src/components/Sidebar/index.js b/packages/bruno-app/src/components/Sidebar/index.js index 92ddf191f..587cf15ad 100644 --- a/packages/bruno-app/src/components/Sidebar/index.js +++ b/packages/bruno-app/src/components/Sidebar/index.js @@ -117,7 +117,7 @@ const Sidebar = () => { )} -
v0.12.0
+
v0.12.1
diff --git a/packages/bruno-electron/package.json b/packages/bruno-electron/package.json index 50bbb5c94..50a27aaa9 100644 --- a/packages/bruno-electron/package.json +++ b/packages/bruno-electron/package.json @@ -1,5 +1,5 @@ { - "version": "0.12.0", + "version": "0.12.1", "name": "bruno", "description": "Opensource API Client", "homepage": "https://www.usebruno.com", From 51e0ea2c2d17e5fffdc62c1d576ff047541b619b Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Sun, 30 Apr 2023 12:08:23 +0530 Subject: [PATCH 3/6] feat(#155): exit process with non zero code when tests or assertions fail --- packages/bruno-cli/src/commands/run.js | 28 ++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/bruno-cli/src/commands/run.js b/packages/bruno-cli/src/commands/run.js index 80900bbd3..325ced567 100644 --- a/packages/bruno-cli/src/commands/run.js +++ b/packages/bruno-cli/src/commands/run.js @@ -35,6 +35,15 @@ const printRunSummary = (assertionResults, testResults) => { console.log("\n" + chalk.bold(assertSummary)); console.log(chalk.bold(testSummary)); + + return { + totalAssertions, + passedAssertions, + failedAssertions, + totalTests, + passedTests, + failedTests + } }; const getBruFilesRecursively = (dir) => { @@ -45,6 +54,10 @@ const getBruFilesRecursively = (dir) => { const traverse = (currentPath) => { const filesInCurrentDir = fs.readdirSync(currentPath); + + if (currentPath.includes('node_modules')) { + return; + } for (const file of filesInCurrentDir) { const filePath = path.join(currentPath, file); @@ -170,8 +183,14 @@ const handler = async function (argv) { testResults } = result; - printRunSummary(assertionResults, testResults); + const summary = printRunSummary(assertionResults, testResults); console.log(chalk.dim(chalk.grey('Done.'))); + + if(summary.failedAssertions > 0 || summary.failedTests > 0) { + process.exit(1); + } + } else { + process.exit(1); } } @@ -226,12 +245,17 @@ const handler = async function (argv) { } } - printRunSummary(assertionResults, testResults); + const summary = printRunSummary(assertionResults, testResults); console.log(chalk.dim(chalk.grey('Ran all requests.'))); + + if(summary.failedAssertions > 0 || summary.failedTests > 0) { + process.exit(1); + } } } catch (err) { console.log("Something went wrong"); console.error(chalk.red(err.message)); + process.exit(1); } }; From 2976842588972d37dfbb0c3dee18daf534c997e0 Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Sun, 30 Apr 2023 12:10:08 +0530 Subject: [PATCH 4/6] chore: version bump for bruno cli v0.5.0 --- packages/bruno-cli/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/bruno-cli/package.json b/packages/bruno-cli/package.json index 8f31679cd..a4aec32ad 100644 --- a/packages/bruno-cli/package.json +++ b/packages/bruno-cli/package.json @@ -1,6 +1,6 @@ { "name": "@usebruno/cli", - "version": "0.4.4", + "version": "0.5.0", "main": "src/index.js", "bin": { "bru": "./bin/bru.js" From 330a7ad18a7ec012ee0e972ae80bfb0a4d2af961 Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Tue, 2 May 2023 15:25:07 +0530 Subject: [PATCH 5/6] fix: fixed bug where content type was getting overwritten everytime as application/x-www-form-urlencoded --- packages/bruno-cli/src/runner/run-single-request.js | 2 +- packages/bruno-electron/src/ipc/network/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/bruno-cli/src/runner/run-single-request.js b/packages/bruno-cli/src/runner/run-single-request.js index e2ce6a839..950c07901 100644 --- a/packages/bruno-cli/src/runner/run-single-request.js +++ b/packages/bruno-cli/src/runner/run-single-request.js @@ -41,7 +41,7 @@ const runSingleRequest = async function (filename, bruJson, collectionPath, coll interpolateVars(request, envVariables, collectionVariables); // stringify the request url encoded params - if(request.headers['content-type'] = 'application/x-www-form-urlencoded') { + if(request.headers['content-type'] === 'application/x-www-form-urlencoded') { request.data = qs.stringify(request.data); } diff --git a/packages/bruno-electron/src/ipc/network/index.js b/packages/bruno-electron/src/ipc/network/index.js index 734af95f5..8e1997721 100644 --- a/packages/bruno-electron/src/ipc/network/index.js +++ b/packages/bruno-electron/src/ipc/network/index.js @@ -126,7 +126,7 @@ const registerNetworkIpc = (mainWindow, watcher, lastOpenedCollections) => { interpolateVars(request, envVars, collectionVariables); // stringify the request url encoded params - if(request.headers['content-type'] = 'application/x-www-form-urlencoded') { + if(request.headers['content-type'] === 'application/x-www-form-urlencoded') { request.data = qs.stringify(request.data); } From 66024d04e93a471071b7a91c8650211a9d7f5ba3 Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Tue, 2 May 2023 15:26:27 +0530 Subject: [PATCH 6/6] chore: version bump --- packages/bruno-app/src/components/Sidebar/index.js | 2 +- packages/bruno-cli/package.json | 2 +- packages/bruno-electron/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/bruno-app/src/components/Sidebar/index.js b/packages/bruno-app/src/components/Sidebar/index.js index 587cf15ad..712ba6b88 100644 --- a/packages/bruno-app/src/components/Sidebar/index.js +++ b/packages/bruno-app/src/components/Sidebar/index.js @@ -117,7 +117,7 @@ const Sidebar = () => { )} -
v0.12.1
+
v0.12.2
diff --git a/packages/bruno-cli/package.json b/packages/bruno-cli/package.json index a4aec32ad..ec6932f41 100644 --- a/packages/bruno-cli/package.json +++ b/packages/bruno-cli/package.json @@ -1,6 +1,6 @@ { "name": "@usebruno/cli", - "version": "0.5.0", + "version": "0.5.1", "main": "src/index.js", "bin": { "bru": "./bin/bru.js" diff --git a/packages/bruno-electron/package.json b/packages/bruno-electron/package.json index 50a27aaa9..c8b1382d3 100644 --- a/packages/bruno-electron/package.json +++ b/packages/bruno-electron/package.json @@ -1,5 +1,5 @@ { - "version": "0.12.1", + "version": "0.12.2", "name": "bruno", "description": "Opensource API Client", "homepage": "https://www.usebruno.com",