feat(#396): decomment support in json and scripts

This commit is contained in:
Anoop M D 2023-10-05 21:15:38 +05:30
parent d36956e0a4
commit 90f47e5877
7 changed files with 52 additions and 21 deletions

36
package-lock.json generated
View File

@ -6678,6 +6678,18 @@
"node": ">=0.10.0"
}
},
"node_modules/decomment": {
"version": "0.9.5",
"resolved": "https://registry.npmjs.org/decomment/-/decomment-0.9.5.tgz",
"integrity": "sha512-h0TZ8t6Dp49duwyDHo3iw67mnh9/UpFiSSiOb5gDK1sqoXzrfX/SQxIUQd2R2QEiSnqib0KF2fnKnGfAhAs6lg==",
"dependencies": {
"esprima": "4.0.1"
},
"engines": {
"node": ">=6.4",
"npm": ">=2.15"
}
},
"node_modules/decompress-response": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz",
@ -7505,7 +7517,6 @@
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==",
"dev": true,
"bin": {
"esparse": "bin/esparse.js",
"esvalidate": "bin/esvalidate.js"
@ -16765,7 +16776,7 @@
},
"packages/bruno-cli": {
"name": "@usebruno/cli",
"version": "0.10.1",
"version": "0.11.0",
"license": "MIT",
"dependencies": {
"@usebruno/js": "0.6.0",
@ -16773,6 +16784,7 @@
"axios": "^1.5.1",
"chai": "^4.3.7",
"chalk": "^3.0.0",
"decomment": "^0.9.5",
"form-data": "^4.0.0",
"fs-extra": "^10.1.0",
"handlebars": "^4.7.8",
@ -16810,7 +16822,7 @@
},
"packages/bruno-electron": {
"name": "bruno",
"version": "v0.18.0",
"version": "v0.19.0",
"dependencies": {
"@usebruno/js": "0.6.0",
"@usebruno/lang": "0.5.0",
@ -16819,6 +16831,7 @@
"axios": "^1.5.1",
"chai": "^4.3.7",
"chokidar": "^3.5.3",
"decomment": "^0.9.5",
"dotenv": "^16.0.3",
"electron-is-dev": "^2.0.0",
"electron-notarize": "^1.2.2",
@ -16848,7 +16861,9 @@
"dmg-license": "^1.0.11"
}
},
"packages/bruno-electron/0.5cd ../.0": {},
"packages/bruno-electron/0.5cd ../.0": {
"extraneous": true
},
"packages/bruno-electron/node_modules/@types/node": {
"version": "16.18.11",
"dev": true,
@ -20092,6 +20107,7 @@
"axios": "^1.5.1",
"chai": "^4.3.7",
"chalk": "^3.0.0",
"decomment": "*",
"form-data": "^4.0.0",
"fs-extra": "^10.1.0",
"handlebars": "^4.7.8",
@ -21201,6 +21217,7 @@
"axios": "^1.5.1",
"chai": "^4.3.7",
"chokidar": "^3.5.3",
"decomment": "^0.9.5",
"dmg-license": "^1.0.11",
"dotenv": "^16.0.3",
"electron": "21.1.1",
@ -22309,6 +22326,14 @@
"integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==",
"dev": true
},
"decomment": {
"version": "0.9.5",
"resolved": "https://registry.npmjs.org/decomment/-/decomment-0.9.5.tgz",
"integrity": "sha512-h0TZ8t6Dp49duwyDHo3iw67mnh9/UpFiSSiOb5gDK1sqoXzrfX/SQxIUQd2R2QEiSnqib0KF2fnKnGfAhAs6lg==",
"requires": {
"esprima": "4.0.1"
}
},
"decompress-response": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz",
@ -22958,8 +22983,7 @@
"esprima": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==",
"dev": true
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A=="
},
"esrecurse": {
"version": "4.3.0",

View File

@ -29,6 +29,7 @@
"axios": "^1.5.1",
"chai": "^4.3.7",
"chalk": "^3.0.0",
"decomment": "^0.9.5",
"form-data": "^4.0.0",
"fs-extra": "^10.1.0",
"handlebars": "^4.7.8",

View File

@ -1,4 +1,5 @@
const { get, each, filter } = require('lodash');
const decomment = require('decomment');
const prepareRequest = (request) => {
const headers = {};
@ -39,7 +40,7 @@ const prepareRequest = (request) => {
axiosRequest.headers['content-type'] = 'application/json';
}
try {
axiosRequest.data = JSON.parse(request.body.json);
axiosRequest.data = JSON.parse(decomment(request.body.json));
} catch (ex) {
axiosRequest.data = request.body.json;
}
@ -78,7 +79,7 @@ const prepareRequest = (request) => {
if (request.body.mode === 'graphql') {
const graphqlQuery = {
query: get(request, 'body.graphql.query'),
variables: JSON.parse(get(request, 'body.graphql.variables') || '{}')
variables: JSON.parse(decomment(get(request, 'body.graphql.variables') || '{}'))
};
if (!contentTypeDefined) {
axiosRequest.headers['content-type'] = 'application/json';

View File

@ -1,5 +1,6 @@
const qs = require('qs');
const chalk = require('chalk');
const decomment = require('decomment');
const fs = require('fs');
const { forOwn, each, extend, get } = require('lodash');
const FormData = require('form-data');
@ -55,7 +56,7 @@ const runSingleRequest = async function (
if (requestScriptFile && requestScriptFile.length) {
const scriptRuntime = new ScriptRuntime();
await scriptRuntime.runRequestScript(
requestScriptFile,
decomment(requestScriptFile),
request,
envVariables,
collectionVariables,
@ -180,7 +181,7 @@ const runSingleRequest = async function (
if (responseScriptFile && responseScriptFile.length) {
const scriptRuntime = new ScriptRuntime();
await scriptRuntime.runResponseScript(
responseScriptFile,
decomment(responseScriptFile),
request,
response,
envVariables,
@ -221,7 +222,7 @@ const runSingleRequest = async function (
if (typeof testFile === 'string') {
const testRuntime = new TestRuntime();
const result = await testRuntime.runTests(
testFile,
decomment(testFile),
request,
response,
envVariables,

View File

@ -21,6 +21,7 @@
"axios": "^1.5.1",
"chai": "^4.3.7",
"chokidar": "^3.5.3",
"decomment": "^0.9.5",
"dotenv": "^16.0.3",
"electron-is-dev": "^2.0.0",
"electron-notarize": "^1.2.2",

View File

@ -1,6 +1,7 @@
const qs = require('qs');
const https = require('https');
const axios = require('axios');
const decomment = require('decomment');
const Mustache = require('mustache');
const FormData = require('form-data');
const { ipcMain } = require('electron');
@ -151,7 +152,7 @@ const registerNetworkIpc = (mainWindow) => {
if (requestScript && requestScript.length) {
const scriptRuntime = new ScriptRuntime();
const result = await scriptRuntime.runRequestScript(
requestScript,
decomment(requestScript),
request,
envVars,
collectionVariables,
@ -277,7 +278,7 @@ const registerNetworkIpc = (mainWindow) => {
if (responseScript && responseScript.length) {
const scriptRuntime = new ScriptRuntime();
const result = await scriptRuntime.runResponseScript(
responseScript,
decomment(responseScript),
request,
response,
envVars,
@ -323,7 +324,7 @@ const registerNetworkIpc = (mainWindow) => {
if (typeof testFile === 'string') {
const testRuntime = new TestRuntime();
const testResults = await testRuntime.runTests(
testFile,
decomment(testFile),
request,
response,
envVars,
@ -402,7 +403,7 @@ const registerNetworkIpc = (mainWindow) => {
if (typeof testFile === 'string') {
const testRuntime = new TestRuntime();
const testResults = await testRuntime.runTests(
testFile,
decomment(testFile),
request,
error.response,
envVars,
@ -603,7 +604,7 @@ const registerNetworkIpc = (mainWindow) => {
if (requestScript && requestScript.length) {
const scriptRuntime = new ScriptRuntime();
const result = await scriptRuntime.runRequestScript(
requestScript,
decomment(requestScript),
request,
envVars,
collectionVariables,
@ -704,7 +705,7 @@ const registerNetworkIpc = (mainWindow) => {
if (responseScript && responseScript.length) {
const scriptRuntime = new ScriptRuntime();
const result = await scriptRuntime.runResponseScript(
responseScript,
decomment(responseScript),
request,
response,
envVars,
@ -748,7 +749,7 @@ const registerNetworkIpc = (mainWindow) => {
if (typeof testFile === 'string') {
const testRuntime = new TestRuntime();
const testResults = await testRuntime.runTests(
testFile,
decomment(testFile),
request,
response,
envVars,
@ -828,7 +829,7 @@ const registerNetworkIpc = (mainWindow) => {
if (typeof testFile === 'string') {
const testRuntime = new TestRuntime();
const testResults = await testRuntime.runTests(
testFile,
decomment(testFile),
request,
error.response,
envVars,

View File

@ -1,4 +1,5 @@
const { get, each, filter } = require('lodash');
const decomment = require('decomment');
const prepareRequest = (request) => {
const headers = {};
@ -37,7 +38,8 @@ const prepareRequest = (request) => {
axiosRequest.headers['content-type'] = 'application/json';
}
try {
axiosRequest.data = JSON.parse(request.body.json);
// axiosRequest.data = JSON.parse(request.body.json);
axiosRequest.data = JSON.parse(decomment(request.body.json));
} catch (ex) {
axiosRequest.data = request.body.json;
}
@ -76,7 +78,7 @@ const prepareRequest = (request) => {
if (request.body.mode === 'graphql') {
const graphqlQuery = {
query: get(request, 'body.graphql.query'),
variables: JSON.parse(get(request, 'body.graphql.variables') || '{}')
variables: JSON.parse(decomment(get(request, 'body.graphql.variables') || '{}'))
};
if (!contentTypeDefined) {
axiosRequest.headers['content-type'] = 'application/json';