feat(#334): bru cli support for collection headers, auth, scripts and tests

This commit is contained in:
Anoop M D
2023-10-09 08:26:10 +05:30
parent f9f1ca0640
commit 362289b7cd
8 changed files with 96 additions and 19 deletions

View File

@@ -1,12 +1,33 @@
const _ = require('lodash');
const Mustache = require('mustache');
const { bruToEnvJsonV2, bruToJsonV2 } = require('@usebruno/lang');
const { bruToEnvJsonV2, bruToJsonV2, collectionBruToJson: _collectionBruToJson } = require('@usebruno/lang');
// override the default escape function to prevent escaping
Mustache.escape = function (value) {
return value;
};
const collectionBruToJson = (bru) => {
try {
const json = _collectionBruToJson(bru);
const transformedJson = {
request: {
params: _.get(json, 'query', []),
headers: _.get(json, 'headers', []),
auth: _.get(json, 'auth', {}),
script: _.get(json, 'script', {}),
vars: _.get(json, 'vars', {}),
tests: _.get(json, 'tests', '')
}
};
return transformedJson;
} catch (error) {
return Promise.reject(error);
}
};
/**
* The transformer function for converting a BRU file to JSON.
*
@@ -91,5 +112,6 @@ module.exports = {
bruToJson,
bruToEnvJson,
getEnvVars,
getOptions
getOptions,
collectionBruToJson
};