mirror of
https://github.com/usebruno/bruno.git
synced 2025-02-13 00:09:47 +01:00
chore(#197): ran prettier on packages/bruno-lang
This commit is contained in:
parent
5af2f68252
commit
116e050987
@ -1,9 +1,4 @@
|
|||||||
const {
|
const { bruToJson, jsonToBru, bruToEnvJson, envJsonToBru } = require('../v1/src');
|
||||||
bruToJson,
|
|
||||||
jsonToBru,
|
|
||||||
bruToEnvJson,
|
|
||||||
envJsonToBru
|
|
||||||
} = require('../v1/src');
|
|
||||||
|
|
||||||
const bruToJsonV2 = require('../v2/src/bruToJson');
|
const bruToJsonV2 = require('../v2/src/bruToJson');
|
||||||
const jsonToBruV2 = require('../v2/src/jsonToBru');
|
const jsonToBruV2 = require('../v2/src/jsonToBru');
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
const {
|
const { between, regex, everyCharUntil } = require('arcsecond');
|
||||||
between,
|
|
||||||
regex,
|
|
||||||
everyCharUntil
|
|
||||||
} = require("arcsecond");
|
|
||||||
const keyvalLines = require('./key-val-lines');
|
const keyvalLines = require('./key-val-lines');
|
||||||
|
|
||||||
// body(type=json)
|
// body(type=json)
|
||||||
@ -37,7 +33,7 @@ const bodyGraphqlTag = between(bodyGraphqlBegin)(bodyEnd)(everyCharUntil(bodyEnd
|
|||||||
query: bodyGraphql
|
query: bodyGraphql
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const bodyGraphqlVarsTag = between(bodyGraphqlVarsBegin)(bodyEnd)(everyCharUntil(bodyEnd)).map((varsGraphql) => {
|
const bodyGraphqlVarsTag = between(bodyGraphqlVarsBegin)(bodyEnd)(everyCharUntil(bodyEnd)).map((varsGraphql) => {
|
||||||
@ -47,7 +43,7 @@ const bodyGraphqlVarsTag = between(bodyGraphqlVarsBegin)(bodyEnd)(everyCharUntil
|
|||||||
variables: varsGraphql
|
variables: varsGraphql
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const bodyTextTag = between(bodyTextBegin)(bodyEnd)(everyCharUntil(bodyEnd)).map((bodyText) => {
|
const bodyTextTag = between(bodyTextBegin)(bodyEnd)(everyCharUntil(bodyEnd)).map((bodyText) => {
|
||||||
@ -55,7 +51,7 @@ const bodyTextTag = between(bodyTextBegin)(bodyEnd)(everyCharUntil(bodyEnd)).map
|
|||||||
body: {
|
body: {
|
||||||
text: bodyText
|
text: bodyText
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const bodyXmlTag = between(bodyXmlBegin)(bodyEnd)(everyCharUntil(bodyEnd)).map((bodyXml) => {
|
const bodyXmlTag = between(bodyXmlBegin)(bodyEnd)(everyCharUntil(bodyEnd)).map((bodyXml) => {
|
||||||
@ -63,7 +59,7 @@ const bodyXmlTag = between(bodyXmlBegin)(bodyEnd)(everyCharUntil(bodyEnd)).map((
|
|||||||
body: {
|
body: {
|
||||||
xml: bodyXml
|
xml: bodyXml
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,20 +86,22 @@ const bodyMultipartForm = regex(/^body\s*\(\s*type\s*=\s*multipart-form\s*\)\s*\
|
|||||||
// todo: fix this
|
// todo: fix this
|
||||||
const bodyEndRelaxed = regex(/^[\r?\n]*\/body\s*[\r?\n]*/);
|
const bodyEndRelaxed = regex(/^[\r?\n]*\/body\s*[\r?\n]*/);
|
||||||
|
|
||||||
const bodyFormUrlEncodedTagDeprecated = between(bodyFormUrlEncodedDeprecated)(bodyEndRelaxed)(keyvalLines).map(([result]) => {
|
const bodyFormUrlEncodedTagDeprecated = between(bodyFormUrlEncodedDeprecated)(bodyEndRelaxed)(keyvalLines).map(
|
||||||
|
([result]) => {
|
||||||
return {
|
return {
|
||||||
body: {
|
body: {
|
||||||
formUrlEncoded: result
|
formUrlEncoded: result
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
const bodyFormUrlEncodedTag = between(bodyFormUrlEncoded)(bodyEndRelaxed)(keyvalLines).map(([result]) => {
|
const bodyFormUrlEncodedTag = between(bodyFormUrlEncoded)(bodyEndRelaxed)(keyvalLines).map(([result]) => {
|
||||||
return {
|
return {
|
||||||
body: {
|
body: {
|
||||||
formUrlEncoded: result
|
formUrlEncoded: result
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const bodyMultipartFormTag = between(bodyMultipartForm)(bodyEndRelaxed)(keyvalLines).map(([result]) => {
|
const bodyMultipartFormTag = between(bodyMultipartForm)(bodyEndRelaxed)(keyvalLines).map(([result]) => {
|
||||||
@ -111,7 +109,7 @@ const bodyMultipartFormTag = between(bodyMultipartForm)(bodyEndRelaxed)(keyvalLi
|
|||||||
body: {
|
body: {
|
||||||
multipartForm: result
|
multipartForm: result
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
const {
|
const { between, regex } = require('arcsecond');
|
||||||
between,
|
|
||||||
regex,
|
|
||||||
} = require("arcsecond");
|
|
||||||
const { each } = require('lodash');
|
const { each } = require('lodash');
|
||||||
const keyValLines = require('./key-val-lines');
|
const keyValLines = require('./key-val-lines');
|
||||||
|
|
||||||
@ -10,7 +7,7 @@ const end = regex(/^[\r?\n]*\/vars\s*[\r?\n]*/);
|
|||||||
|
|
||||||
const envVarsTag = between(begin)(end)(keyValLines).map(([variables]) => {
|
const envVarsTag = between(begin)(end)(keyValLines).map(([variables]) => {
|
||||||
each(variables, (variable) => {
|
each(variables, (variable) => {
|
||||||
variable.type = "text"
|
variable.type = 'text';
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
const {
|
const { between, regex } = require('arcsecond');
|
||||||
between,
|
|
||||||
regex
|
|
||||||
} = require("arcsecond");
|
|
||||||
const keyValLines = require('./key-val-lines');
|
const keyValLines = require('./key-val-lines');
|
||||||
|
|
||||||
const begin = regex(/^headers\s*\r?\n/);
|
const begin = regex(/^headers\s*\r?\n/);
|
||||||
|
@ -1,13 +1,6 @@
|
|||||||
const {
|
const { many, choice, anyChar } = require('arcsecond');
|
||||||
many,
|
|
||||||
choice,
|
|
||||||
anyChar
|
|
||||||
} = require("arcsecond");
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const {
|
const { indentString, outdentString } = require('./utils');
|
||||||
indentString,
|
|
||||||
outdentString
|
|
||||||
} = require('./utils');
|
|
||||||
|
|
||||||
const inlineTag = require('./inline-tag');
|
const inlineTag = require('./inline-tag');
|
||||||
const paramsTag = require('./params-tag');
|
const paramsTag = require('./params-tag');
|
||||||
@ -26,7 +19,8 @@ const scriptTag = require('./script-tag');
|
|||||||
const testsTag = require('./tests-tag');
|
const testsTag = require('./tests-tag');
|
||||||
|
|
||||||
const bruToJson = (fileContents) => {
|
const bruToJson = (fileContents) => {
|
||||||
const parser = many(choice([
|
const parser = many(
|
||||||
|
choice([
|
||||||
inlineTag,
|
inlineTag,
|
||||||
paramsTag,
|
paramsTag,
|
||||||
headersTag,
|
headersTag,
|
||||||
@ -41,12 +35,10 @@ const bruToJson = (fileContents) => {
|
|||||||
scriptTag,
|
scriptTag,
|
||||||
testsTag,
|
testsTag,
|
||||||
anyChar
|
anyChar
|
||||||
]));
|
])
|
||||||
|
);
|
||||||
|
|
||||||
const parsed = parser
|
const parsed = parser.run(fileContents).result.reduce((acc, item) => _.merge(acc, item), {});
|
||||||
.run(fileContents)
|
|
||||||
.result
|
|
||||||
.reduce((acc, item) => _.merge(acc, item), {});
|
|
||||||
|
|
||||||
const json = {
|
const json = {
|
||||||
type: parsed.type || '',
|
type: parsed.type || '',
|
||||||
@ -93,15 +85,7 @@ const jsonToBru = (json) => {
|
|||||||
type,
|
type,
|
||||||
name,
|
name,
|
||||||
seq,
|
seq,
|
||||||
request: {
|
request: { method, url, params, headers, body, script, tests }
|
||||||
method,
|
|
||||||
url,
|
|
||||||
params,
|
|
||||||
headers,
|
|
||||||
body,
|
|
||||||
script,
|
|
||||||
tests
|
|
||||||
}
|
|
||||||
} = json;
|
} = json;
|
||||||
|
|
||||||
let bru = `name ${name}
|
let bru = `name ${name}
|
||||||
@ -115,7 +99,7 @@ seq ${seq ? seq : 1}
|
|||||||
if (params && params.length) {
|
if (params && params.length) {
|
||||||
bru += `
|
bru += `
|
||||||
params
|
params
|
||||||
${params.map(param => ` ${param.enabled ? 1 : 0} ${param.name} ${param.value}`).join('\n')}
|
${params.map((param) => ` ${param.enabled ? 1 : 0} ${param.name} ${param.value}`).join('\n')}
|
||||||
/params
|
/params
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@ -123,7 +107,7 @@ ${params.map(param => ` ${param.enabled ? 1 : 0} ${param.name} ${param.value}`)
|
|||||||
if (headers && headers.length) {
|
if (headers && headers.length) {
|
||||||
bru += `
|
bru += `
|
||||||
headers
|
headers
|
||||||
${headers.map(header => ` ${header.enabled ? 1 : 0} ${header.name} ${header.value}`).join('\n')}
|
${headers.map((header) => ` ${header.enabled ? 1 : 0} ${header.name} ${header.value}`).join('\n')}
|
||||||
/headers
|
/headers
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@ -171,7 +155,7 @@ ${indentString(body.xml)}
|
|||||||
if (body && body.formUrlEncoded && body.formUrlEncoded.length) {
|
if (body && body.formUrlEncoded && body.formUrlEncoded.length) {
|
||||||
bru += `
|
bru += `
|
||||||
body(type=form-urlencoded)
|
body(type=form-urlencoded)
|
||||||
${body.formUrlEncoded.map(item => ` ${item.enabled ? 1 : 0} ${item.name} ${item.value}`).join('\n')}
|
${body.formUrlEncoded.map((item) => ` ${item.enabled ? 1 : 0} ${item.name} ${item.value}`).join('\n')}
|
||||||
/body
|
/body
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@ -179,7 +163,7 @@ ${body.formUrlEncoded.map(item => ` ${item.enabled ? 1 : 0} ${item.name} ${item
|
|||||||
if (body && body.multipartForm && body.multipartForm.length) {
|
if (body && body.multipartForm && body.multipartForm.length) {
|
||||||
bru += `
|
bru += `
|
||||||
body(type=multipart-form)
|
body(type=multipart-form)
|
||||||
${body.multipartForm.map(item => ` ${item.enabled ? 1 : 0} ${item.name} ${item.value}`).join('\n')}
|
${body.multipartForm.map((item) => ` ${item.enabled ? 1 : 0} ${item.name} ${item.value}`).join('\n')}
|
||||||
/body
|
/body
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@ -207,15 +191,9 @@ ${indentString(tests)}
|
|||||||
const envVarsTag = require('./env-vars-tag');
|
const envVarsTag = require('./env-vars-tag');
|
||||||
|
|
||||||
const bruToEnvJson = (fileContents) => {
|
const bruToEnvJson = (fileContents) => {
|
||||||
const parser = many(choice([
|
const parser = many(choice([envVarsTag, anyChar]));
|
||||||
envVarsTag,
|
|
||||||
anyChar
|
|
||||||
]));
|
|
||||||
|
|
||||||
const parsed = parser
|
const parsed = parser.run(fileContents).result.reduce((acc, item) => _.merge(acc, item), {});
|
||||||
.run(fileContents)
|
|
||||||
.result
|
|
||||||
.reduce((acc, item) => _.merge(acc, item), {});
|
|
||||||
|
|
||||||
const json = {
|
const json = {
|
||||||
variables: parsed.variables || []
|
variables: parsed.variables || []
|
||||||
@ -225,15 +203,13 @@ const bruToEnvJson = (fileContents) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const envJsonToBru = (json) => {
|
const envJsonToBru = (json) => {
|
||||||
const {
|
const { variables } = json;
|
||||||
variables
|
|
||||||
} = json;
|
|
||||||
|
|
||||||
let bru = '';
|
let bru = '';
|
||||||
|
|
||||||
if (variables && variables.length) {
|
if (variables && variables.length) {
|
||||||
bru += `vars
|
bru += `vars
|
||||||
${variables.map(item => ` ${item.enabled ? 1 : 0} ${item.name} ${item.value}`).join('\n')}
|
${variables.map((item) => ` ${item.enabled ? 1 : 0} ${item.name} ${item.value}`).join('\n')}
|
||||||
/vars
|
/vars
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,13 @@
|
|||||||
const {
|
const { sequenceOf, str, regex, choice, endOfInput, everyCharUntil } = require('arcsecond');
|
||||||
sequenceOf,
|
|
||||||
str,
|
|
||||||
regex,
|
|
||||||
choice,
|
|
||||||
endOfInput,
|
|
||||||
everyCharUntil
|
|
||||||
} = require("arcsecond");
|
|
||||||
|
|
||||||
const whitespace = regex(/^[ \t]*/)
|
const whitespace = regex(/^[ \t]*/);
|
||||||
const newline = regex(/^\r?\n/);
|
const newline = regex(/^\r?\n/);
|
||||||
const newLineOrEndOfInput = choice([endOfInput, newline]);
|
const newLineOrEndOfInput = choice([endOfInput, newline]);
|
||||||
|
|
||||||
const inlineTag = sequenceOf([
|
const inlineTag = sequenceOf([
|
||||||
choice([
|
choice([str('type'), str('name'), str('method'), str('url'), str('seq'), str('body-mode')]),
|
||||||
str('type'),
|
|
||||||
str('name'),
|
|
||||||
str('method'),
|
|
||||||
str('url'),
|
|
||||||
str('seq'),
|
|
||||||
str('body-mode')
|
|
||||||
]),
|
|
||||||
whitespace,
|
whitespace,
|
||||||
choice([
|
choice([newline, everyCharUntil(newLineOrEndOfInput)])
|
||||||
newline,
|
|
||||||
everyCharUntil(newLineOrEndOfInput)
|
|
||||||
])
|
|
||||||
]).map(([key, _, val]) => {
|
]).map(([key, _, val]) => {
|
||||||
if (val === '\n' || val === '\r\n') {
|
if (val === '\n' || val === '\r\n') {
|
||||||
val = '';
|
val = '';
|
||||||
|
@ -1,13 +1,4 @@
|
|||||||
const {
|
const { sequenceOf, whitespace, optionalWhitespace, choice, digit, many, regex, sepBy } = require('arcsecond');
|
||||||
sequenceOf,
|
|
||||||
whitespace,
|
|
||||||
optionalWhitespace,
|
|
||||||
choice,
|
|
||||||
digit,
|
|
||||||
many,
|
|
||||||
regex,
|
|
||||||
sepBy,
|
|
||||||
} = require("arcsecond");
|
|
||||||
|
|
||||||
const newline = regex(/^\r?\n/);
|
const newline = regex(/^\r?\n/);
|
||||||
const wordWithoutWhitespace = regex(/^[^\s\r?\t\n]+/g);
|
const wordWithoutWhitespace = regex(/^[^\s\r?\t\n]+/g);
|
||||||
@ -23,37 +14,29 @@ const line = sequenceOf([
|
|||||||
wordWithWhitespace
|
wordWithWhitespace
|
||||||
]).map(([_, enabled, __, key, ___, value]) => {
|
]).map(([_, enabled, __, key, ___, value]) => {
|
||||||
return {
|
return {
|
||||||
"enabled": Number(enabled) ? true : false,
|
enabled: Number(enabled) ? true : false,
|
||||||
"name": key ? key.trim() : "",
|
name: key ? key.trim() : '',
|
||||||
"value": value ? value.trim() : ""
|
value: value ? value.trim() : ''
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// matching lines like: 1 key follows by [whitespaces] and a newline
|
// matching lines like: 1 key follows by [whitespaces] and a newline
|
||||||
const line2 = sequenceOf([
|
const line2 = sequenceOf([optionalWhitespace, digit, whitespace, wordWithoutWhitespace, regex(/^\s*\r?\n/)]).map(
|
||||||
optionalWhitespace,
|
([_, enabled, __, key]) => {
|
||||||
digit,
|
|
||||||
whitespace,
|
|
||||||
wordWithoutWhitespace,
|
|
||||||
regex(/^\s*\r?\n/)
|
|
||||||
]).map(([_, enabled, __, key]) => {
|
|
||||||
return {
|
return {
|
||||||
"enabled": Number(enabled) ? true : false,
|
enabled: Number(enabled) ? true : false,
|
||||||
"name": key,
|
name: key,
|
||||||
"value": ""
|
value: ''
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// matching lines like: 1 followed by [whitespaces] and a newline
|
// matching lines like: 1 followed by [whitespaces] and a newline
|
||||||
const line3 = sequenceOf([
|
const line3 = sequenceOf([optionalWhitespace, digit, regex(/^\s*\r?\n/)]).map(([_, enabled]) => {
|
||||||
optionalWhitespace,
|
|
||||||
digit,
|
|
||||||
regex(/^\s*\r?\n/)
|
|
||||||
]).map(([_, enabled]) => {
|
|
||||||
return {
|
return {
|
||||||
"enabled": Number(enabled) ? true : false,
|
enabled: Number(enabled) ? true : false,
|
||||||
"name": "",
|
name: '',
|
||||||
"value": ""
|
value: ''
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
const {
|
const { between, regex } = require('arcsecond');
|
||||||
between,
|
|
||||||
regex
|
|
||||||
} = require("arcsecond");
|
|
||||||
const keyValLines = require('./key-val-lines');
|
const keyValLines = require('./key-val-lines');
|
||||||
|
|
||||||
const begin = regex(/^params\s*\r?\n/);
|
const begin = regex(/^params\s*\r?\n/);
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
const {
|
const { between, regex, everyCharUntil } = require('arcsecond');
|
||||||
between,
|
|
||||||
regex,
|
|
||||||
everyCharUntil
|
|
||||||
} = require("arcsecond");
|
|
||||||
|
|
||||||
const scriptBegin = regex(/^script\s*\r?\n/);
|
const scriptBegin = regex(/^script\s*\r?\n/);
|
||||||
const scriptEnd = regex(/^[\r?\n]+\/script[\s\r?\n]*/);
|
const scriptEnd = regex(/^[\r?\n]+\/script[\s\r?\n]*/);
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
const {
|
const { between, regex, everyCharUntil } = require('arcsecond');
|
||||||
between,
|
|
||||||
regex,
|
|
||||||
everyCharUntil
|
|
||||||
} = require("arcsecond");
|
|
||||||
|
|
||||||
const testsBegin = regex(/^tests\s*\r?\n/);
|
const testsBegin = regex(/^tests\s*\r?\n/);
|
||||||
const testsEnd = regex(/^[\r?\n]+\/tests[\s\r?\n]*/);
|
const testsEnd = regex(/^[\r?\n]+\/tests[\s\r?\n]*/);
|
||||||
|
@ -12,7 +12,10 @@ const indentString = (str) => {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
return str.split("\n").map(line => " " + line).join("\n");
|
return str
|
||||||
|
.split('\n')
|
||||||
|
.map((line) => ' ' + line)
|
||||||
|
.join('\n');
|
||||||
};
|
};
|
||||||
|
|
||||||
const outdentString = (str) => {
|
const outdentString = (str) => {
|
||||||
@ -20,7 +23,10 @@ const outdentString = (str) => {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
return str.split("\n").map(line => line.replace(/^ /, '')).join("\n");
|
return str
|
||||||
|
.split('\n')
|
||||||
|
.map((line) => line.replace(/^ /, ''))
|
||||||
|
.join('\n');
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
const { bodyJsonTag } = require('../src/body-tag');
|
const { bodyJsonTag } = require('../src/body-tag');
|
||||||
|
|
||||||
|
|
||||||
describe('bodyJsonTag', () => {
|
describe('bodyJsonTag', () => {
|
||||||
const testbodyJson = (input, expected) => {
|
const testbodyJson = (input, expected) => {
|
||||||
const result = bodyJsonTag.run(input);
|
const result = bodyJsonTag.run(input);
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const {
|
const { bruToEnvJson } = require('../src');
|
||||||
bruToEnvJson
|
|
||||||
} = require('../src');
|
|
||||||
|
|
||||||
describe('bruToEnvJson', () => {
|
describe('bruToEnvJson', () => {
|
||||||
it('should parse .bru file contents', () => {
|
it('should parse .bru file contents', () => {
|
||||||
@ -11,23 +9,26 @@ describe('bruToEnvJson', () => {
|
|||||||
const result = bruToEnvJson(requestFile);
|
const result = bruToEnvJson(requestFile);
|
||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
"variables": [{
|
variables: [
|
||||||
"enabled": true,
|
{
|
||||||
"name": "host",
|
enabled: true,
|
||||||
"value": "https://www.google.com",
|
name: 'host',
|
||||||
"type": "text"
|
value: 'https://www.google.com',
|
||||||
}, {
|
type: 'text'
|
||||||
"enabled": true,
|
},
|
||||||
"name": "jwt",
|
{
|
||||||
"value": "secret",
|
enabled: true,
|
||||||
"type": "text"
|
name: 'jwt',
|
||||||
}, {
|
value: 'secret',
|
||||||
"enabled": false,
|
type: 'text'
|
||||||
"name": "Content-type",
|
},
|
||||||
"value": "application/json",
|
{
|
||||||
"type": "text"
|
enabled: false,
|
||||||
}]
|
name: 'Content-type',
|
||||||
|
value: 'application/json',
|
||||||
|
type: 'text'
|
||||||
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const {
|
const { bruToJson } = require('../src');
|
||||||
bruToJson
|
|
||||||
} = require('../src');
|
|
||||||
|
|
||||||
describe('bruToJson', () => {
|
describe('bruToJson', () => {
|
||||||
it('should parse .bru file contents', () => {
|
it('should parse .bru file contents', () => {
|
||||||
@ -11,81 +9,81 @@ describe('bruToJson', () => {
|
|||||||
const result = bruToJson(requestFile);
|
const result = bruToJson(requestFile);
|
||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
"type": "http-request",
|
type: 'http-request',
|
||||||
"name": "Send Bulk SMS",
|
name: 'Send Bulk SMS',
|
||||||
"seq": 1,
|
seq: 1,
|
||||||
"request": {
|
request: {
|
||||||
"method": "GET",
|
method: 'GET',
|
||||||
"url": "https://api.textlocal.in/bulk_json?apiKey=secret=&numbers=919988776655&message=hello&sender=600010",
|
url: 'https://api.textlocal.in/bulk_json?apiKey=secret=&numbers=919988776655&message=hello&sender=600010',
|
||||||
"params": [
|
params: [
|
||||||
{
|
{
|
||||||
"enabled": true,
|
enabled: true,
|
||||||
"name": "apiKey",
|
name: 'apiKey',
|
||||||
"value": "secret"
|
value: 'secret'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"enabled": true,
|
enabled: true,
|
||||||
"name": "numbers",
|
name: 'numbers',
|
||||||
"value": "998877665"
|
value: '998877665'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"enabled": true,
|
enabled: true,
|
||||||
"name": "message",
|
name: 'message',
|
||||||
"value": "hello"
|
value: 'hello'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"headers": [
|
headers: [
|
||||||
{
|
{
|
||||||
"enabled": true,
|
enabled: true,
|
||||||
"name": "content-type",
|
name: 'content-type',
|
||||||
"value": "application/json"
|
value: 'application/json'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"enabled": true,
|
enabled: true,
|
||||||
"name": "accept-language",
|
name: 'accept-language',
|
||||||
"value": "en-US,en;q=0.9,hi;q=0.8"
|
value: 'en-US,en;q=0.9,hi;q=0.8'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"enabled": false,
|
enabled: false,
|
||||||
"name": "transaction-id",
|
name: 'transaction-id',
|
||||||
"value": "{{transactionId}}"
|
value: '{{transactionId}}'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"body": {
|
body: {
|
||||||
"mode": "json",
|
mode: 'json',
|
||||||
"json": '{\n "apikey": "secret",\n "numbers": "+91998877665"\n}',
|
json: '{\n "apikey": "secret",\n "numbers": "+91998877665"\n}',
|
||||||
"graphql": {
|
graphql: {
|
||||||
"query": "{\n launchesPast {\n launch_success\n }\n}"
|
query: '{\n launchesPast {\n launch_success\n }\n}'
|
||||||
},
|
},
|
||||||
"text": "Hello, there. You must be from the past",
|
text: 'Hello, there. You must be from the past',
|
||||||
"xml": "<body>back to the ice age</body>",
|
xml: '<body>back to the ice age</body>',
|
||||||
"formUrlEncoded": [
|
formUrlEncoded: [
|
||||||
{
|
{
|
||||||
"enabled": true,
|
enabled: true,
|
||||||
"name": "username",
|
name: 'username',
|
||||||
"value": "john"
|
value: 'john'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"enabled": false,
|
enabled: false,
|
||||||
"name": "password",
|
name: 'password',
|
||||||
"value": "{{password}}"
|
value: '{{password}}'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"multipartForm": [
|
multipartForm: [
|
||||||
{
|
{
|
||||||
"enabled": true,
|
enabled: true,
|
||||||
"name": "username",
|
name: 'username',
|
||||||
"value": "nash"
|
value: 'nash'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"enabled": false,
|
enabled: false,
|
||||||
"name": "password",
|
name: 'password',
|
||||||
"value": "governingdynamics"
|
value: 'governingdynamics'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"script": "const foo='bar';",
|
script: "const foo='bar';",
|
||||||
"tests": "bruno.test('200 ok', () => {});"
|
tests: "bruno.test('200 ok', () => {});"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -113,8 +111,8 @@ seq 1
|
|||||||
params: [],
|
params: [],
|
||||||
headers: [],
|
headers: [],
|
||||||
body: { mode: 'none' },
|
body: { mode: 'none' },
|
||||||
script: "",
|
script: '',
|
||||||
tests: ""
|
tests: ''
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,29 +1,31 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const {
|
const { envJsonToBru } = require('../src');
|
||||||
envJsonToBru
|
|
||||||
} = require('../src');
|
|
||||||
|
|
||||||
describe('envJsonToBru', () => {
|
describe('envJsonToBru', () => {
|
||||||
it('should convert json file into .bru file', () => {
|
it('should convert json file into .bru file', () => {
|
||||||
const env = {
|
const env = {
|
||||||
"variables": [{
|
variables: [
|
||||||
"enabled": true,
|
{
|
||||||
"name": "host",
|
enabled: true,
|
||||||
"value": "https://www.google.com",
|
name: 'host',
|
||||||
"type": "text"
|
value: 'https://www.google.com',
|
||||||
}, {
|
type: 'text'
|
||||||
"enabled": true,
|
},
|
||||||
"name": "jwt",
|
{
|
||||||
"value": "secret",
|
enabled: true,
|
||||||
"type": "text"
|
name: 'jwt',
|
||||||
}, {
|
value: 'secret',
|
||||||
"enabled": false,
|
type: 'text'
|
||||||
"name": "Content-type",
|
},
|
||||||
"value": "application/json",
|
{
|
||||||
"type": "text"
|
enabled: false,
|
||||||
}]
|
name: 'Content-type',
|
||||||
|
value: 'application/json',
|
||||||
|
type: 'text'
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
const expectedBruFile = fs.readFileSync(path.join(__dirname, 'fixtures', 'env.bru'), 'utf8');
|
const expectedBruFile = fs.readFileSync(path.join(__dirname, 'fixtures', 'env.bru'), 'utf8');
|
||||||
@ -32,4 +34,3 @@ describe('envJsonToBru', () => {
|
|||||||
expect(expectedBruFile).toEqual(actualBruFile);
|
expect(expectedBruFile).toEqual(actualBruFile);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
const inlineTag = require('../src/inline-tag');
|
const inlineTag = require('../src/inline-tag');
|
||||||
const {
|
const { sepBy, char, many } = require('arcsecond');
|
||||||
sepBy,
|
|
||||||
char,
|
|
||||||
many
|
|
||||||
} = require('arcsecond');
|
|
||||||
|
|
||||||
describe('type', () => {
|
describe('type', () => {
|
||||||
it('should parse the type', () => {
|
it('should parse the type', () => {
|
||||||
@ -54,5 +50,5 @@ body-mode json
|
|||||||
[{ body: { mode: 'json' } }],
|
[{ body: { mode: 'json' } }],
|
||||||
[]
|
[]
|
||||||
]);
|
]);
|
||||||
})
|
});
|
||||||
});
|
});
|
@ -1,88 +1,86 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const {
|
const { jsonToBru } = require('../src');
|
||||||
jsonToBru
|
|
||||||
} = require('../src');
|
|
||||||
|
|
||||||
describe('bruToJson', () => {
|
describe('bruToJson', () => {
|
||||||
it('should convert json file into .bru file', () => {
|
it('should convert json file into .bru file', () => {
|
||||||
const request = {
|
const request = {
|
||||||
"type": "http-request",
|
type: 'http-request',
|
||||||
"name": "Send Bulk SMS",
|
name: 'Send Bulk SMS',
|
||||||
"seq": 1,
|
seq: 1,
|
||||||
"request": {
|
request: {
|
||||||
"method": "GET",
|
method: 'GET',
|
||||||
"url": "https://api.textlocal.in/bulk_json?apiKey=secret=&numbers=919988776655&message=hello&sender=600010",
|
url: 'https://api.textlocal.in/bulk_json?apiKey=secret=&numbers=919988776655&message=hello&sender=600010',
|
||||||
"params": [
|
params: [
|
||||||
{
|
{
|
||||||
"enabled": true,
|
enabled: true,
|
||||||
"name": "apiKey",
|
name: 'apiKey',
|
||||||
"value": "secret"
|
value: 'secret'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"enabled": true,
|
enabled: true,
|
||||||
"name": "numbers",
|
name: 'numbers',
|
||||||
"value": "998877665"
|
value: '998877665'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"enabled": true,
|
enabled: true,
|
||||||
"name": "message",
|
name: 'message',
|
||||||
"value": "hello"
|
value: 'hello'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"headers": [
|
headers: [
|
||||||
{
|
{
|
||||||
"enabled": true,
|
enabled: true,
|
||||||
"name": "content-type",
|
name: 'content-type',
|
||||||
"value": "application/json"
|
value: 'application/json'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"enabled": true,
|
enabled: true,
|
||||||
"name": "accept-language",
|
name: 'accept-language',
|
||||||
"value": "en-US,en;q=0.9,hi;q=0.8"
|
value: 'en-US,en;q=0.9,hi;q=0.8'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"enabled": false,
|
enabled: false,
|
||||||
"name": "transaction-id",
|
name: 'transaction-id',
|
||||||
"value": "{{transactionId}}"
|
value: '{{transactionId}}'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"body": {
|
body: {
|
||||||
"mode": "json",
|
mode: 'json',
|
||||||
"json": '{\n "apikey": "secret",\n "numbers": "+91998877665"\n}',
|
json: '{\n "apikey": "secret",\n "numbers": "+91998877665"\n}',
|
||||||
"graphql": {
|
graphql: {
|
||||||
"query": "{\n launchesPast {\n launch_success\n }\n}"
|
query: '{\n launchesPast {\n launch_success\n }\n}'
|
||||||
},
|
},
|
||||||
"text": "Hello, there. You must be from the past",
|
text: 'Hello, there. You must be from the past',
|
||||||
"xml": "<body>back to the ice age</body>",
|
xml: '<body>back to the ice age</body>',
|
||||||
"formUrlEncoded": [
|
formUrlEncoded: [
|
||||||
{
|
{
|
||||||
"enabled": true,
|
enabled: true,
|
||||||
"name": "username",
|
name: 'username',
|
||||||
"value": "john"
|
value: 'john'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"enabled": false,
|
enabled: false,
|
||||||
"name": "password",
|
name: 'password',
|
||||||
"value": "{{password}}"
|
value: '{{password}}'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"multipartForm": [
|
multipartForm: [
|
||||||
{
|
{
|
||||||
"enabled": true,
|
enabled: true,
|
||||||
"name": "username",
|
name: 'username',
|
||||||
"value": "nash"
|
value: 'nash'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"enabled": false,
|
enabled: false,
|
||||||
"name": "password",
|
name: 'password',
|
||||||
"value": "governingdynamics"
|
value: 'governingdynamics'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"script": "const foo='bar';",
|
script: "const foo='bar';",
|
||||||
"tests": "bruno.test('200 ok', () => {});"
|
tests: "bruno.test('200 ok', () => {});"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -92,5 +90,3 @@ describe('bruToJson', () => {
|
|||||||
expect(expectedBruFile).toEqual(actualBruFile);
|
expect(expectedBruFile).toEqual(actualBruFile);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,10 +1,4 @@
|
|||||||
const {
|
const { between, regex, anyChar, many, choice } = require('arcsecond');
|
||||||
between,
|
|
||||||
regex,
|
|
||||||
anyChar,
|
|
||||||
many,
|
|
||||||
choice
|
|
||||||
} = require("arcsecond");
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
const keyValLines = require('../src/key-val-lines');
|
const keyValLines = require('../src/key-val-lines');
|
||||||
@ -19,15 +13,9 @@ const varsTag = between(begin)(end)(keyValLines).map(([variables]) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const toJson = (fileContents) => {
|
const toJson = (fileContents) => {
|
||||||
const parser = many(choice([
|
const parser = many(choice([varsTag, anyChar]));
|
||||||
varsTag,
|
|
||||||
anyChar
|
|
||||||
]));
|
|
||||||
|
|
||||||
const parsed = parser
|
const parsed = parser.run(fileContents).result.reduce((acc, item) => _.merge(acc, item), {});
|
||||||
.run(fileContents)
|
|
||||||
.result
|
|
||||||
.reduce((acc, item) => _.merge(acc, item), {});
|
|
||||||
|
|
||||||
const json = {
|
const json = {
|
||||||
variables: parsed.variables || []
|
variables: parsed.variables || []
|
||||||
@ -46,11 +34,13 @@ vars
|
|||||||
|
|
||||||
const result = toJson(file);
|
const result = toJson(file);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
variables: [{
|
variables: [
|
||||||
|
{
|
||||||
enabled: true,
|
enabled: true,
|
||||||
name: 'host',
|
name: 'host',
|
||||||
value: 'https://www.google.com'
|
value: 'https://www.google.com'
|
||||||
}]
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -64,15 +54,18 @@ vars
|
|||||||
|
|
||||||
const result = toJson(file);
|
const result = toJson(file);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
variables: [{
|
variables: [
|
||||||
|
{
|
||||||
enabled: true,
|
enabled: true,
|
||||||
name: 'host',
|
name: 'host',
|
||||||
value: 'https://www.google.com'
|
value: 'https://www.google.com'
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
enabled: true,
|
enabled: true,
|
||||||
name: 'auth',
|
name: 'auth',
|
||||||
value: 'jwt secret'
|
value: 'jwt secret'
|
||||||
}]
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -87,11 +80,13 @@ vars
|
|||||||
`;
|
`;
|
||||||
const result = toJson(file);
|
const result = toJson(file);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
variables: [{
|
variables: [
|
||||||
|
{
|
||||||
enabled: true,
|
enabled: true,
|
||||||
name: '',
|
name: '',
|
||||||
value: ''
|
value: ''
|
||||||
}]
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -104,11 +99,13 @@ vars
|
|||||||
`;
|
`;
|
||||||
const result = toJson(file);
|
const result = toJson(file);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
variables: [{
|
variables: [
|
||||||
|
{
|
||||||
enabled: true,
|
enabled: true,
|
||||||
name: '',
|
name: '',
|
||||||
value: ''
|
value: ''
|
||||||
}]
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -121,11 +118,13 @@ vars
|
|||||||
`;
|
`;
|
||||||
const result = toJson(file);
|
const result = toJson(file);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
variables: [{
|
variables: [
|
||||||
|
{
|
||||||
enabled: true,
|
enabled: true,
|
||||||
name: 'host',
|
name: 'host',
|
||||||
value: ''
|
value: ''
|
||||||
}]
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -138,11 +137,13 @@ vars
|
|||||||
`;
|
`;
|
||||||
const result = toJson(file);
|
const result = toJson(file);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
variables: [{
|
variables: [
|
||||||
|
{
|
||||||
enabled: true,
|
enabled: true,
|
||||||
name: 'host',
|
name: 'host',
|
||||||
value: ''
|
value: ''
|
||||||
}]
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -157,19 +158,23 @@ vars
|
|||||||
`;
|
`;
|
||||||
const result = toJson(file);
|
const result = toJson(file);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
variables: [{
|
variables: [
|
||||||
|
{
|
||||||
enabled: true,
|
enabled: true,
|
||||||
name: 'host',
|
name: 'host',
|
||||||
value: 'https://www.google.com'
|
value: 'https://www.google.com'
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
enabled: true,
|
enabled: true,
|
||||||
name: '',
|
name: '',
|
||||||
value: ''
|
value: ''
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
enabled: false,
|
enabled: false,
|
||||||
name: 'Content-type',
|
name: 'Content-type',
|
||||||
value: 'application/json'
|
value: 'application/json'
|
||||||
}]
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -184,19 +189,23 @@ vars
|
|||||||
`;
|
`;
|
||||||
const result = toJson(file);
|
const result = toJson(file);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
variables: [{
|
variables: [
|
||||||
|
{
|
||||||
enabled: true,
|
enabled: true,
|
||||||
name: 'host',
|
name: 'host',
|
||||||
value: 'https://www.google.com'
|
value: 'https://www.google.com'
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
enabled: true,
|
enabled: true,
|
||||||
name: '',
|
name: '',
|
||||||
value: ''
|
value: ''
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
enabled: false,
|
enabled: false,
|
||||||
name: 'Content-type',
|
name: 'Content-type',
|
||||||
value: 'application/json'
|
value: 'application/json'
|
||||||
}]
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -211,20 +220,23 @@ vars
|
|||||||
`;
|
`;
|
||||||
const result = toJson(file);
|
const result = toJson(file);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
variables: [{
|
variables: [
|
||||||
|
{
|
||||||
enabled: true,
|
enabled: true,
|
||||||
name: 'host',
|
name: 'host',
|
||||||
value: 'https://www.google.com'
|
value: 'https://www.google.com'
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
enabled: true,
|
enabled: true,
|
||||||
name: 'auth',
|
name: 'auth',
|
||||||
value: ''
|
value: ''
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
enabled: false,
|
enabled: false,
|
||||||
name: 'Content-type',
|
name: 'Content-type',
|
||||||
value: 'application/json'
|
value: 'application/json'
|
||||||
}]
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,9 +1,4 @@
|
|||||||
const {
|
const { safeParseJson, indentString, outdentString, get } = require('../src/utils');
|
||||||
safeParseJson,
|
|
||||||
indentString,
|
|
||||||
outdentString,
|
|
||||||
get
|
|
||||||
} = require('../src/utils');
|
|
||||||
|
|
||||||
describe('utils', () => {
|
describe('utils', () => {
|
||||||
describe('safeParseJson', () => {
|
describe('safeParseJson', () => {
|
||||||
@ -22,16 +17,16 @@ describe('utils', () => {
|
|||||||
|
|
||||||
describe('indentString', () => {
|
describe('indentString', () => {
|
||||||
it('correctly indents a multiline string', () => {
|
it('correctly indents a multiline string', () => {
|
||||||
const input = "line1\nline2\nline3";
|
const input = 'line1\nline2\nline3';
|
||||||
const expectedOutput = " line1\n line2\n line3";
|
const expectedOutput = ' line1\n line2\n line3';
|
||||||
expect(indentString(input)).toBe(expectedOutput);
|
expect(indentString(input)).toBe(expectedOutput);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('outdentString', () => {
|
describe('outdentString', () => {
|
||||||
it('correctly outdents a multiline string', () => {
|
it('correctly outdents a multiline string', () => {
|
||||||
const input = " line1\n line2\n line3";
|
const input = ' line1\n line2\n line3';
|
||||||
const expectedOutput = "line1\nline2\nline3";
|
const expectedOutput = 'line1\nline2\nline3';
|
||||||
expect(outdentString(input)).toBe(expectedOutput);
|
expect(outdentString(input)).toBe(expectedOutput);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
const ohm = require("ohm-js");
|
const ohm = require('ohm-js');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const {
|
const { outdentString } = require('../../v1/src/utils');
|
||||||
outdentString
|
|
||||||
} = require('../../v1/src/utils');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Bru file is made up of blocks.
|
* A Bru file is made up of blocks.
|
||||||
@ -98,11 +96,11 @@ const mapPairListToKeyValPairs = (pairList = []) => {
|
|||||||
if (!pairList.length) {
|
if (!pairList.length) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
return _.map(pairList[0], pair => {
|
return _.map(pairList[0], (pair) => {
|
||||||
let name = _.keys(pair)[0];
|
let name = _.keys(pair)[0];
|
||||||
let value = pair[name];
|
let value = pair[name];
|
||||||
let enabled = true;
|
let enabled = true;
|
||||||
if (name && name.length && name.charAt(0) === "~") {
|
if (name && name.length && name.charAt(0) === '~') {
|
||||||
name = name.slice(1);
|
name = name.slice(1);
|
||||||
enabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
@ -127,7 +125,7 @@ const mapPairListToKeyValPair = (pairList = []) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return _.merge({}, ...pairList[0]);
|
return _.merge({}, ...pairList[0]);
|
||||||
}
|
};
|
||||||
|
|
||||||
const sem = grammar.createSemantics().addAttribute('ast', {
|
const sem = grammar.createSemantics().addAttribute('ast', {
|
||||||
BruFile(tags) {
|
BruFile(tags) {
|
||||||
@ -135,9 +133,13 @@ const sem = grammar.createSemantics().addAttribute('ast', {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return _.reduce(tags.ast, (result, item) => {
|
return _.reduce(
|
||||||
|
tags.ast,
|
||||||
|
(result, item) => {
|
||||||
return _.mergeWith(result, item, concatArrays);
|
return _.mergeWith(result, item, concatArrays);
|
||||||
}, {});
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
dictionary(_1, _2, pairlist, _3) {
|
dictionary(_1, _2, pairlist, _3) {
|
||||||
return pairlist.ast;
|
return pairlist.ast;
|
||||||
@ -189,7 +191,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
|
|||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
_iter(...elements) {
|
_iter(...elements) {
|
||||||
return elements.map(e => e.ast);
|
return elements.map((e) => e.ast);
|
||||||
},
|
},
|
||||||
meta(_1, dictionary) {
|
meta(_1, dictionary) {
|
||||||
let meta = mapPairListToKeyValPair(dictionary.ast);
|
let meta = mapPairListToKeyValPair(dictionary.ast);
|
||||||
@ -347,7 +349,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
|
|||||||
const vars = mapPairListToKeyValPairs(dictionary.ast);
|
const vars = mapPairListToKeyValPairs(dictionary.ast);
|
||||||
_.each(vars, (v) => {
|
_.each(vars, (v) => {
|
||||||
let name = v.name;
|
let name = v.name;
|
||||||
if (name && name.length && name.charAt(0) === "@") {
|
if (name && name.length && name.charAt(0) === '@') {
|
||||||
v.name = name.slice(1);
|
v.name = name.slice(1);
|
||||||
v.local = true;
|
v.local = true;
|
||||||
} else {
|
} else {
|
||||||
@ -365,7 +367,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
|
|||||||
const vars = mapPairListToKeyValPairs(dictionary.ast);
|
const vars = mapPairListToKeyValPairs(dictionary.ast);
|
||||||
_.each(vars, (v) => {
|
_.each(vars, (v) => {
|
||||||
let name = v.name;
|
let name = v.name;
|
||||||
if (name && name.length && name.charAt(0) === "@") {
|
if (name && name.length && name.charAt(0) === '@') {
|
||||||
v.name = name.slice(1);
|
v.name = name.slice(1);
|
||||||
v.local = true;
|
v.local = true;
|
||||||
} else {
|
} else {
|
||||||
@ -401,7 +403,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
|
|||||||
tests(_1, _2, _3, _4, textblock, _5) {
|
tests(_1, _2, _3, _4, textblock, _5) {
|
||||||
return {
|
return {
|
||||||
tests: outdentString(textblock.sourceString)
|
tests: outdentString(textblock.sourceString)
|
||||||
};;
|
};
|
||||||
},
|
},
|
||||||
docs(_1, _2, _3, _4, textblock, _5) {
|
docs(_1, _2, _3, _4, textblock, _5) {
|
||||||
return {
|
return {
|
||||||
@ -418,6 +420,6 @@ const parser = (input) => {
|
|||||||
} else {
|
} else {
|
||||||
throw new Error(match.message);
|
throw new Error(match.message);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = parser;
|
module.exports = parser;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const ohm = require("ohm-js");
|
const ohm = require('ohm-js');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
const grammar = ohm.grammar(`Env {
|
const grammar = ohm.grammar(`Env {
|
||||||
@ -20,9 +20,13 @@ const concatArrays = (objValue, srcValue) => {
|
|||||||
|
|
||||||
const sem = grammar.createSemantics().addAttribute('ast', {
|
const sem = grammar.createSemantics().addAttribute('ast', {
|
||||||
EnvFile(entries) {
|
EnvFile(entries) {
|
||||||
return _.reduce(entries.ast, (result, item) => {
|
return _.reduce(
|
||||||
|
entries.ast,
|
||||||
|
(result, item) => {
|
||||||
return _.mergeWith(result, item, concatArrays);
|
return _.mergeWith(result, item, concatArrays);
|
||||||
}, {});
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
entry(_1, key, _2, _3, _4, value, _5, _6) {
|
entry(_1, key, _2, _3, _4, value, _5, _6) {
|
||||||
return { [key.ast.trim()]: value.ast.trim() };
|
return { [key.ast.trim()]: value.ast.trim() };
|
||||||
@ -40,7 +44,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
|
|||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
_iter(...elements) {
|
_iter(...elements) {
|
||||||
return elements.map(e => e.ast);
|
return elements.map((e) => e.ast);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -53,7 +57,7 @@ const parser = (input) => {
|
|||||||
} else {
|
} else {
|
||||||
throw new Error(match.message);
|
throw new Error(match.message);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
function postProcessEntries(ast) {
|
function postProcessEntries(ast) {
|
||||||
const processed = {};
|
const processed = {};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const ohm = require("ohm-js");
|
const ohm = require('ohm-js');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
const grammar = ohm.grammar(`Bru {
|
const grammar = ohm.grammar(`Bru {
|
||||||
@ -27,11 +27,11 @@ const mapPairListToKeyValPairs = (pairList = []) => {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return _.map(pairList[0], pair => {
|
return _.map(pairList[0], (pair) => {
|
||||||
let name = _.keys(pair)[0];
|
let name = _.keys(pair)[0];
|
||||||
let value = pair[name];
|
let value = pair[name];
|
||||||
let enabled = true;
|
let enabled = true;
|
||||||
if (name && name.length && name.charAt(0) === "~") {
|
if (name && name.length && name.charAt(0) === '~') {
|
||||||
name = name.slice(1);
|
name = name.slice(1);
|
||||||
enabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
@ -58,9 +58,13 @@ const sem = grammar.createSemantics().addAttribute('ast', {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return _.reduce(tags.ast, (result, item) => {
|
return _.reduce(
|
||||||
|
tags.ast,
|
||||||
|
(result, item) => {
|
||||||
return _.mergeWith(result, item, concatArrays);
|
return _.mergeWith(result, item, concatArrays);
|
||||||
}, {});
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
dictionary(_1, _2, pairlist, _3) {
|
dictionary(_1, _2, pairlist, _3) {
|
||||||
return pairlist.ast;
|
return pairlist.ast;
|
||||||
@ -89,7 +93,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
|
|||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
_iter(...elements) {
|
_iter(...elements) {
|
||||||
return elements.map(e => e.ast);
|
return elements.map((e) => e.ast);
|
||||||
},
|
},
|
||||||
vars(_1, dictionary) {
|
vars(_1, dictionary) {
|
||||||
const vars = mapPairListToKeyValPairs(dictionary.ast);
|
const vars = mapPairListToKeyValPairs(dictionary.ast);
|
||||||
@ -107,6 +111,6 @@ const parser = (input) => {
|
|||||||
} else {
|
} else {
|
||||||
throw new Error(match.message);
|
throw new Error(match.message);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = parser;
|
module.exports = parser;
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
const {
|
const { indentString } = require('../../v1/src/utils');
|
||||||
indentString,
|
|
||||||
} = require('../../v1/src/utils');
|
|
||||||
|
|
||||||
const enabled = (items = []) => items.filter(item => item.enabled);
|
const enabled = (items = []) => items.filter((item) => item.enabled);
|
||||||
const disabled = (items = []) => items.filter(item => !item.enabled);
|
const disabled = (items = []) => items.filter((item) => !item.enabled);
|
||||||
|
|
||||||
// remove the last line if two new lines are found
|
// remove the last line if two new lines are found
|
||||||
const stripLastLine = (text) => {
|
const stripLastLine = (text) => {
|
||||||
@ -15,18 +13,7 @@ const stripLastLine = (text) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const jsonToBru = (json) => {
|
const jsonToBru = (json) => {
|
||||||
const {
|
const { meta, http, query, headers, body, script, tests, vars, assertions, docs } = json;
|
||||||
meta,
|
|
||||||
http,
|
|
||||||
query,
|
|
||||||
headers,
|
|
||||||
body,
|
|
||||||
script,
|
|
||||||
tests,
|
|
||||||
vars,
|
|
||||||
assertions,
|
|
||||||
docs
|
|
||||||
} = json;
|
|
||||||
|
|
||||||
let bru = '';
|
let bru = '';
|
||||||
|
|
||||||
@ -56,11 +43,19 @@ const jsonToBru = (json) => {
|
|||||||
if (query && query.length) {
|
if (query && query.length) {
|
||||||
bru += 'query {';
|
bru += 'query {';
|
||||||
if (enabled(query).length) {
|
if (enabled(query).length) {
|
||||||
bru += `\n${indentString(enabled(query).map(item => `${item.name}: ${item.value}`).join('\n'))}`;
|
bru += `\n${indentString(
|
||||||
|
enabled(query)
|
||||||
|
.map((item) => `${item.name}: ${item.value}`)
|
||||||
|
.join('\n')
|
||||||
|
)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (disabled(query).length) {
|
if (disabled(query).length) {
|
||||||
bru += `\n${indentString(disabled(query).map(item => `~${item.name}: ${item.value}`).join('\n'))}`;
|
bru += `\n${indentString(
|
||||||
|
disabled(query)
|
||||||
|
.map((item) => `~${item.name}: ${item.value}`)
|
||||||
|
.join('\n')
|
||||||
|
)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
bru += '\n}\n\n';
|
bru += '\n}\n\n';
|
||||||
@ -69,11 +64,19 @@ const jsonToBru = (json) => {
|
|||||||
if (headers && headers.length) {
|
if (headers && headers.length) {
|
||||||
bru += 'headers {';
|
bru += 'headers {';
|
||||||
if (enabled(headers).length) {
|
if (enabled(headers).length) {
|
||||||
bru += `\n${indentString(enabled(headers).map(item => `${item.name}: ${item.value}`).join('\n'))}`;
|
bru += `\n${indentString(
|
||||||
|
enabled(headers)
|
||||||
|
.map((item) => `${item.name}: ${item.value}`)
|
||||||
|
.join('\n')
|
||||||
|
)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (disabled(headers).length) {
|
if (disabled(headers).length) {
|
||||||
bru += `\n${indentString(disabled(headers).map(item => `~${item.name}: ${item.value}`).join('\n'))}`;
|
bru += `\n${indentString(
|
||||||
|
disabled(headers)
|
||||||
|
.map((item) => `~${item.name}: ${item.value}`)
|
||||||
|
.join('\n')
|
||||||
|
)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
bru += '\n}\n\n';
|
bru += '\n}\n\n';
|
||||||
@ -106,11 +109,19 @@ ${indentString(body.xml)}
|
|||||||
if (body && body.formUrlEncoded && body.formUrlEncoded.length) {
|
if (body && body.formUrlEncoded && body.formUrlEncoded.length) {
|
||||||
bru += `body:form-urlencoded {`;
|
bru += `body:form-urlencoded {`;
|
||||||
if (enabled(body.formUrlEncoded).length) {
|
if (enabled(body.formUrlEncoded).length) {
|
||||||
bru += `\n${indentString(enabled(body.formUrlEncoded).map(item => `${item.name}: ${item.value}`).join('\n'))}`;
|
bru += `\n${indentString(
|
||||||
|
enabled(body.formUrlEncoded)
|
||||||
|
.map((item) => `${item.name}: ${item.value}`)
|
||||||
|
.join('\n')
|
||||||
|
)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (disabled(body.formUrlEncoded).length) {
|
if (disabled(body.formUrlEncoded).length) {
|
||||||
bru += `\n${indentString(disabled(body.formUrlEncoded).map(item => `~${item.name}: ${item.value}`).join('\n'))}`;
|
bru += `\n${indentString(
|
||||||
|
disabled(body.formUrlEncoded)
|
||||||
|
.map((item) => `~${item.name}: ${item.value}`)
|
||||||
|
.join('\n')
|
||||||
|
)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
bru += '\n}\n\n';
|
bru += '\n}\n\n';
|
||||||
@ -119,11 +130,19 @@ ${indentString(body.xml)}
|
|||||||
if (body && body.multipartForm && body.multipartForm.length) {
|
if (body && body.multipartForm && body.multipartForm.length) {
|
||||||
bru += `body:multipart-form {`;
|
bru += `body:multipart-form {`;
|
||||||
if (enabled(body.multipartForm).length) {
|
if (enabled(body.multipartForm).length) {
|
||||||
bru += `\n${indentString(enabled(body.multipartForm).map(item => `${item.name}: ${item.value}`).join('\n'))}`;
|
bru += `\n${indentString(
|
||||||
|
enabled(body.multipartForm)
|
||||||
|
.map((item) => `${item.name}: ${item.value}`)
|
||||||
|
.join('\n')
|
||||||
|
)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (disabled(body.multipartForm).length) {
|
if (disabled(body.multipartForm).length) {
|
||||||
bru += `\n${indentString(disabled(body.multipartForm).map(item => `~${item.name}: ${item.value}`).join('\n'))}`;
|
bru += `\n${indentString(
|
||||||
|
disabled(body.multipartForm)
|
||||||
|
.map((item) => `~${item.name}: ${item.value}`)
|
||||||
|
.join('\n')
|
||||||
|
)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
bru += '\n}\n\n';
|
bru += '\n}\n\n';
|
||||||
@ -137,7 +156,7 @@ ${indentString(body.xml)}
|
|||||||
|
|
||||||
if (body && body.graphql && body.graphql.variables) {
|
if (body && body.graphql && body.graphql.variables) {
|
||||||
bru += `body:graphql:vars {\n`;
|
bru += `body:graphql:vars {\n`;
|
||||||
bru += `${indentString(body.graphql.variables)}`
|
bru += `${indentString(body.graphql.variables)}`;
|
||||||
bru += '\n}\n\n';
|
bru += '\n}\n\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,19 +171,19 @@ ${indentString(body.xml)}
|
|||||||
bru += `vars:pre-request {`;
|
bru += `vars:pre-request {`;
|
||||||
|
|
||||||
if (varsEnabled.length) {
|
if (varsEnabled.length) {
|
||||||
bru += `\n${indentString(varsEnabled.map(item => `${item.name}: ${item.value}`).join('\n'))}`;
|
bru += `\n${indentString(varsEnabled.map((item) => `${item.name}: ${item.value}`).join('\n'))}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (varsLocalEnabled.length) {
|
if (varsLocalEnabled.length) {
|
||||||
bru += `\n${indentString(varsLocalEnabled.map(item => `@${item.name}: ${item.value}`).join('\n'))}`;
|
bru += `\n${indentString(varsLocalEnabled.map((item) => `@${item.name}: ${item.value}`).join('\n'))}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (varsDisabled.length) {
|
if (varsDisabled.length) {
|
||||||
bru += `\n${indentString(varsDisabled.map(item => `~${item.name}: ${item.value}`).join('\n'))}`;
|
bru += `\n${indentString(varsDisabled.map((item) => `~${item.name}: ${item.value}`).join('\n'))}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (varsLocalDisabled.length) {
|
if (varsLocalDisabled.length) {
|
||||||
bru += `\n${indentString(varsLocalDisabled.map(item => `~@${item.name}: ${item.value}`).join('\n'))}`;
|
bru += `\n${indentString(varsLocalDisabled.map((item) => `~@${item.name}: ${item.value}`).join('\n'))}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
bru += '\n}\n\n';
|
bru += '\n}\n\n';
|
||||||
@ -178,19 +197,19 @@ ${indentString(body.xml)}
|
|||||||
bru += `vars:post-response {`;
|
bru += `vars:post-response {`;
|
||||||
|
|
||||||
if (varsEnabled.length) {
|
if (varsEnabled.length) {
|
||||||
bru += `\n${indentString(varsEnabled.map(item => `${item.name}: ${item.value}`).join('\n'))}`;
|
bru += `\n${indentString(varsEnabled.map((item) => `${item.name}: ${item.value}`).join('\n'))}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (varsLocalEnabled.length) {
|
if (varsLocalEnabled.length) {
|
||||||
bru += `\n${indentString(varsLocalEnabled.map(item => `@${item.name}: ${item.value}`).join('\n'))}`;
|
bru += `\n${indentString(varsLocalEnabled.map((item) => `@${item.name}: ${item.value}`).join('\n'))}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (varsDisabled.length) {
|
if (varsDisabled.length) {
|
||||||
bru += `\n${indentString(varsDisabled.map(item => `~${item.name}: ${item.value}`).join('\n'))}`;
|
bru += `\n${indentString(varsDisabled.map((item) => `~${item.name}: ${item.value}`).join('\n'))}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (varsLocalDisabled.length) {
|
if (varsLocalDisabled.length) {
|
||||||
bru += `\n${indentString(varsLocalDisabled.map(item => `~@${item.name}: ${item.value}`).join('\n'))}`;
|
bru += `\n${indentString(varsLocalDisabled.map((item) => `~@${item.name}: ${item.value}`).join('\n'))}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
bru += '\n}\n\n';
|
bru += '\n}\n\n';
|
||||||
@ -200,11 +219,19 @@ ${indentString(body.xml)}
|
|||||||
bru += `assert {`;
|
bru += `assert {`;
|
||||||
|
|
||||||
if (enabled(assertions).length) {
|
if (enabled(assertions).length) {
|
||||||
bru += `\n${indentString(enabled(assertions).map(item => `${item.name}: ${item.value}`).join('\n'))}`;
|
bru += `\n${indentString(
|
||||||
|
enabled(assertions)
|
||||||
|
.map((item) => `${item.name}: ${item.value}`)
|
||||||
|
.join('\n')
|
||||||
|
)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (disabled(assertions).length) {
|
if (disabled(assertions).length) {
|
||||||
bru += `\n${indentString(disabled(assertions).map(item => `~${item.name}: ${item.value}`).join('\n'))}`;
|
bru += `\n${indentString(
|
||||||
|
disabled(assertions)
|
||||||
|
.map((item) => `~${item.name}: ${item.value}`)
|
||||||
|
.join('\n')
|
||||||
|
)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
bru += '\n}\n\n';
|
bru += '\n}\n\n';
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/**
|
/**
|
||||||
* This test file is used to test the text parser.
|
* This test file is used to test the text parser.
|
||||||
*/
|
*/
|
||||||
const parser = require("../src/bruToJson");
|
const parser = require('../src/bruToJson');
|
||||||
|
|
||||||
describe("assert parser", () => {
|
describe('assert parser', () => {
|
||||||
it("should parse assert statement", () => {
|
it('should parse assert statement', () => {
|
||||||
const input = `
|
const input = `
|
||||||
assert {
|
assert {
|
||||||
res("data.airports").filter(a => a.code ==="BLR").name: "Bangalore International Airport"
|
res("data.airports").filter(a => a.code ==="BLR").name: "Bangalore International Airport"
|
||||||
@ -13,11 +13,13 @@ assert {
|
|||||||
|
|
||||||
const output = parser(input);
|
const output = parser(input);
|
||||||
const expected = {
|
const expected = {
|
||||||
"assertions": [{
|
assertions: [
|
||||||
name: "res(\"data.airports\").filter(a => a.code ===\"BLR\").name",
|
{
|
||||||
|
name: 'res("data.airports").filter(a => a.code ==="BLR").name',
|
||||||
value: '"Bangalore International Airport"',
|
value: '"Bangalore International Airport"',
|
||||||
enabled: true
|
enabled: true
|
||||||
}]
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
expect(output).toEqual(expected);
|
expect(output).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
const bruToJson = require("../src/bruToJson");
|
const bruToJson = require('../src/bruToJson');
|
||||||
|
|
||||||
describe("defaults", () => {
|
describe('defaults', () => {
|
||||||
it("should parse the default type and seq", () => {
|
it('should parse the default type and seq', () => {
|
||||||
const input = `
|
const input = `
|
||||||
meta {
|
meta {
|
||||||
name: Create user
|
name: Create user
|
||||||
@ -12,21 +12,21 @@ post {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
const expected = {
|
const expected = {
|
||||||
"meta": {
|
meta: {
|
||||||
"name": "Create user",
|
name: 'Create user',
|
||||||
"seq": 1,
|
seq: 1,
|
||||||
"type": "http"
|
type: 'http'
|
||||||
},
|
},
|
||||||
"http": {
|
http: {
|
||||||
"method": "post",
|
method: 'post',
|
||||||
"url": "/users"
|
url: '/users'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const output = bruToJson(input);
|
const output = bruToJson(input);
|
||||||
expect(output).toEqual(expected);
|
expect(output).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should parse the default body mode as json if the body is found", () => {
|
it('should parse the default body mode as json if the body is found', () => {
|
||||||
const input = `
|
const input = `
|
||||||
meta {
|
meta {
|
||||||
name: Create user
|
name: Create user
|
||||||
@ -45,18 +45,18 @@ body {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const expected = {
|
const expected = {
|
||||||
"meta": {
|
meta: {
|
||||||
"name": "Create user",
|
name: 'Create user',
|
||||||
"seq": 1,
|
seq: 1,
|
||||||
"type": "http"
|
type: 'http'
|
||||||
},
|
},
|
||||||
"http": {
|
http: {
|
||||||
"method": "post",
|
method: 'post',
|
||||||
"url": "/users",
|
url: '/users',
|
||||||
"body": "json"
|
body: 'json'
|
||||||
},
|
},
|
||||||
"body": {
|
body: {
|
||||||
"json": "{\n name: John\n age: 30\n}"
|
json: '{\n name: John\n age: 30\n}'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,35 +2,37 @@
|
|||||||
* This test file is used to test the dictionary parser.
|
* This test file is used to test the dictionary parser.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const parser = require("../src/bruToJson");
|
const parser = require('../src/bruToJson');
|
||||||
|
|
||||||
const assertSingleHeader = (input) => {
|
const assertSingleHeader = (input) => {
|
||||||
const output = parser(input);
|
const output = parser(input);
|
||||||
|
|
||||||
const expected = {
|
const expected = {
|
||||||
"headers": [{
|
headers: [
|
||||||
"name": "hello",
|
{
|
||||||
"value": "world",
|
name: 'hello',
|
||||||
"enabled": true
|
value: 'world',
|
||||||
}]
|
enabled: true
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
expect(output).toEqual(expected);
|
expect(output).toEqual(expected);
|
||||||
};
|
};
|
||||||
|
|
||||||
describe("headers parser", () => {
|
describe('headers parser', () => {
|
||||||
it("should parse empty header", () => {
|
it('should parse empty header', () => {
|
||||||
const input = `
|
const input = `
|
||||||
headers {
|
headers {
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
const output = parser(input);
|
const output = parser(input);
|
||||||
const expected = {
|
const expected = {
|
||||||
"headers": []
|
headers: []
|
||||||
};
|
};
|
||||||
expect(output).toEqual(expected);
|
expect(output).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should parse single header", () => {
|
it('should parse single header', () => {
|
||||||
const input = `
|
const input = `
|
||||||
headers {
|
headers {
|
||||||
hello: world
|
hello: world
|
||||||
@ -39,7 +41,7 @@ headers {
|
|||||||
assertSingleHeader(input);
|
assertSingleHeader(input);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should parse single header with spaces", () => {
|
it('should parse single header with spaces', () => {
|
||||||
const input = `
|
const input = `
|
||||||
headers {
|
headers {
|
||||||
hello: world
|
hello: world
|
||||||
@ -48,7 +50,7 @@ headers {
|
|||||||
assertSingleHeader(input);
|
assertSingleHeader(input);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should parse single header with spaces and newlines", () => {
|
it('should parse single header with spaces and newlines', () => {
|
||||||
const input = `
|
const input = `
|
||||||
headers {
|
headers {
|
||||||
|
|
||||||
@ -60,7 +62,7 @@ headers {
|
|||||||
assertSingleHeader(input);
|
assertSingleHeader(input);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should parse single header with empty value", () => {
|
it('should parse single header with empty value', () => {
|
||||||
const input = `
|
const input = `
|
||||||
headers {
|
headers {
|
||||||
hello:
|
hello:
|
||||||
@ -68,16 +70,18 @@ headers {
|
|||||||
|
|
||||||
const output = parser(input);
|
const output = parser(input);
|
||||||
const expected = {
|
const expected = {
|
||||||
"headers": [{
|
headers: [
|
||||||
"name": "hello",
|
{
|
||||||
"value": "",
|
name: 'hello',
|
||||||
"enabled": true
|
value: '',
|
||||||
}]
|
enabled: true
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
expect(output).toEqual(expected);
|
expect(output).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should parse multi headers", () => {
|
it('should parse multi headers', () => {
|
||||||
const input = `
|
const input = `
|
||||||
headers {
|
headers {
|
||||||
content-type: application/json
|
content-type: application/json
|
||||||
@ -87,20 +91,23 @@ headers {
|
|||||||
|
|
||||||
const output = parser(input);
|
const output = parser(input);
|
||||||
const expected = {
|
const expected = {
|
||||||
"headers": [{
|
headers: [
|
||||||
"name": "content-type",
|
{
|
||||||
"value": "application/json",
|
name: 'content-type',
|
||||||
"enabled": true
|
value: 'application/json',
|
||||||
}, {
|
enabled: true
|
||||||
"name": "Authorization",
|
},
|
||||||
"value": "JWT secret",
|
{
|
||||||
"enabled": true
|
name: 'Authorization',
|
||||||
}]
|
value: 'JWT secret',
|
||||||
|
enabled: true
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
expect(output).toEqual(expected);
|
expect(output).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should parse disabled headers", () => {
|
it('should parse disabled headers', () => {
|
||||||
const input = `
|
const input = `
|
||||||
headers {
|
headers {
|
||||||
~content-type: application/json
|
~content-type: application/json
|
||||||
@ -108,16 +115,18 @@ headers {
|
|||||||
|
|
||||||
const output = parser(input);
|
const output = parser(input);
|
||||||
const expected = {
|
const expected = {
|
||||||
"headers": [{
|
headers: [
|
||||||
"name": "content-type",
|
{
|
||||||
"value": "application/json",
|
name: 'content-type',
|
||||||
"enabled": false
|
value: 'application/json',
|
||||||
}]
|
enabled: false
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
expect(output).toEqual(expected);
|
expect(output).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should parse empty url", () => {
|
it('should parse empty url', () => {
|
||||||
const input = `
|
const input = `
|
||||||
get {
|
get {
|
||||||
url:
|
url:
|
||||||
@ -126,16 +135,16 @@ get {
|
|||||||
|
|
||||||
const output = parser(input);
|
const output = parser(input);
|
||||||
const expected = {
|
const expected = {
|
||||||
"http": {
|
http: {
|
||||||
"url": "",
|
url: '',
|
||||||
"method": "get",
|
method: 'get',
|
||||||
"body": "json",
|
body: 'json'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
expect(output).toEqual(expected);
|
expect(output).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw error on invalid header", () => {
|
it('should throw error on invalid header', () => {
|
||||||
const input = `
|
const input = `
|
||||||
headers {
|
headers {
|
||||||
hello: world
|
hello: world
|
||||||
@ -145,7 +154,7 @@ headers {
|
|||||||
expect(() => parser(input)).toThrow();
|
expect(() => parser(input)).toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw error on invalid header", () => {
|
it('should throw error on invalid header', () => {
|
||||||
const input = `
|
const input = `
|
||||||
headers {
|
headers {
|
||||||
hello: world
|
hello: world
|
||||||
@ -154,4 +163,3 @@ headers {
|
|||||||
expect(() => parser(input)).toThrow();
|
expect(() => parser(input)).toThrow();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ BEEP=false
|
|||||||
const expected = {
|
const expected = {
|
||||||
FOO: 'bar',
|
FOO: 'bar',
|
||||||
BAZ: 2,
|
BAZ: 2,
|
||||||
BEEP: false,
|
BEEP: false
|
||||||
};
|
};
|
||||||
const output = parser(input);
|
const output = parser(input);
|
||||||
expect(output).toEqual(expected);
|
expect(output).toEqual(expected);
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
const parser = require("../src/envToJson");
|
const parser = require('../src/envToJson');
|
||||||
|
|
||||||
describe("env parser", () => {
|
describe('env parser', () => {
|
||||||
it("should parse empty vars", () => {
|
it('should parse empty vars', () => {
|
||||||
const input = `
|
const input = `
|
||||||
vars {
|
vars {
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
const output = parser(input);
|
const output = parser(input);
|
||||||
const expected = {
|
const expected = {
|
||||||
"variables": []
|
variables: []
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(output).toEqual(expected);
|
expect(output).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should parse single var line", () => {
|
it('should parse single var line', () => {
|
||||||
const input = `
|
const input = `
|
||||||
vars {
|
vars {
|
||||||
url: http://localhost:3000
|
url: http://localhost:3000
|
||||||
@ -22,17 +22,19 @@ vars {
|
|||||||
|
|
||||||
const output = parser(input);
|
const output = parser(input);
|
||||||
const expected = {
|
const expected = {
|
||||||
"variables": [{
|
variables: [
|
||||||
"name": "url",
|
{
|
||||||
"value": "http://localhost:3000",
|
name: 'url',
|
||||||
"enabled" : true,
|
value: 'http://localhost:3000',
|
||||||
}]
|
enabled: true
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(output).toEqual(expected);
|
expect(output).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should parse multiple var lines", () => {
|
it('should parse multiple var lines', () => {
|
||||||
const input = `
|
const input = `
|
||||||
vars {
|
vars {
|
||||||
url: http://localhost:3000
|
url: http://localhost:3000
|
||||||
@ -42,25 +44,29 @@ vars {
|
|||||||
|
|
||||||
const output = parser(input);
|
const output = parser(input);
|
||||||
const expected = {
|
const expected = {
|
||||||
"variables": [{
|
variables: [
|
||||||
"name": "url",
|
{
|
||||||
"value": "http://localhost:3000",
|
name: 'url',
|
||||||
"enabled" : true
|
value: 'http://localhost:3000',
|
||||||
}, {
|
enabled: true
|
||||||
"name": "port",
|
},
|
||||||
"value": "3000",
|
{
|
||||||
"enabled" : true
|
name: 'port',
|
||||||
}, {
|
value: '3000',
|
||||||
"name": "token",
|
enabled: true
|
||||||
"value": "secret",
|
},
|
||||||
"enabled" : false
|
{
|
||||||
}]
|
name: 'token',
|
||||||
|
value: 'secret',
|
||||||
|
enabled: false
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(output).toEqual(expected);
|
expect(output).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should gracefully handle empty lines and spaces", () => {
|
it('should gracefully handle empty lines and spaces', () => {
|
||||||
const input = `
|
const input = `
|
||||||
|
|
||||||
vars {
|
vars {
|
||||||
@ -72,21 +78,24 @@ vars {
|
|||||||
|
|
||||||
const output = parser(input);
|
const output = parser(input);
|
||||||
const expected = {
|
const expected = {
|
||||||
"variables": [{
|
variables: [
|
||||||
"name": "url",
|
{
|
||||||
"value": "http://localhost:3000",
|
name: 'url',
|
||||||
"enabled" : true,
|
value: 'http://localhost:3000',
|
||||||
}, {
|
enabled: true
|
||||||
"name": "port",
|
},
|
||||||
"value": "3000",
|
{
|
||||||
"enabled" : true,
|
name: 'port',
|
||||||
}]
|
value: '3000',
|
||||||
|
enabled: true
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(output).toEqual(expected);
|
expect(output).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should parse vars with empty values", () => {
|
it('should parse vars with empty values', () => {
|
||||||
const input = `
|
const input = `
|
||||||
vars {
|
vars {
|
||||||
url:
|
url:
|
||||||
@ -97,19 +106,23 @@ vars {
|
|||||||
|
|
||||||
const output = parser(input);
|
const output = parser(input);
|
||||||
const expected = {
|
const expected = {
|
||||||
"variables": [{
|
variables: [
|
||||||
"name": "url",
|
{
|
||||||
"value": "",
|
name: 'url',
|
||||||
"enabled" : true,
|
value: '',
|
||||||
}, {
|
enabled: true
|
||||||
"name": "phone",
|
},
|
||||||
"value": "",
|
{
|
||||||
"enabled" : true,
|
name: 'phone',
|
||||||
}, {
|
value: '',
|
||||||
"name": "api-key",
|
enabled: true
|
||||||
"value": "",
|
},
|
||||||
"enabled" : true,
|
{
|
||||||
}]
|
name: 'api-key',
|
||||||
|
value: '',
|
||||||
|
enabled: true
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(output).toEqual(expected);
|
expect(output).toEqual(expected);
|
||||||
|
@ -9,19 +9,23 @@
|
|||||||
"url": "https://api.textlocal.in/send",
|
"url": "https://api.textlocal.in/send",
|
||||||
"body": "json"
|
"body": "json"
|
||||||
},
|
},
|
||||||
"query": [{
|
"query": [
|
||||||
|
{
|
||||||
"name": "apiKey",
|
"name": "apiKey",
|
||||||
"value": "secret",
|
"value": "secret",
|
||||||
"enabled": true
|
"enabled": true
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
"name": "numbers",
|
"name": "numbers",
|
||||||
"value": "998877665",
|
"value": "998877665",
|
||||||
"enabled": true
|
"enabled": true
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
"name": "message",
|
"name": "message",
|
||||||
"value": "hello",
|
"value": "hello",
|
||||||
"enabled": false
|
"enabled": false
|
||||||
}],
|
}
|
||||||
|
],
|
||||||
"headers": [
|
"headers": [
|
||||||
{
|
{
|
||||||
"name": "content-type",
|
"name": "content-type",
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
const fs = require("fs");
|
const fs = require('fs');
|
||||||
const path = require("path");
|
const path = require('path');
|
||||||
const bruToJson = require("../src/bruToJson");
|
const bruToJson = require('../src/bruToJson');
|
||||||
const jsonToBru = require("../src/jsonToBru");
|
const jsonToBru = require('../src/jsonToBru');
|
||||||
|
|
||||||
describe("bruToJson", () => {
|
describe('bruToJson', () => {
|
||||||
it("should parse the bru file", () => {
|
it('should parse the bru file', () => {
|
||||||
const input = fs.readFileSync(path.join(__dirname, 'fixtures', 'request.bru'), 'utf8');
|
const input = fs.readFileSync(path.join(__dirname, 'fixtures', 'request.bru'), 'utf8');
|
||||||
const expected = require("./fixtures/request.json");
|
const expected = require('./fixtures/request.json');
|
||||||
const output = bruToJson(input);
|
const output = bruToJson(input);
|
||||||
|
|
||||||
expect(output).toEqual(expected);
|
expect(output).toEqual(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("jsonToBru", () => {
|
describe('jsonToBru', () => {
|
||||||
it("should parse the bru file", () => {
|
it('should parse the bru file', () => {
|
||||||
const input = require("./fixtures/request.json");
|
const input = require('./fixtures/request.json');
|
||||||
const expected = fs.readFileSync(path.join(__dirname, 'fixtures', 'request.bru'), 'utf8');
|
const expected = fs.readFileSync(path.join(__dirname, 'fixtures', 'request.bru'), 'utf8');
|
||||||
const output = jsonToBru(input);
|
const output = jsonToBru(input);
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
const parser = require("../src/jsonToEnv");
|
const parser = require('../src/jsonToEnv');
|
||||||
|
|
||||||
describe("env parser", () => {
|
describe('env parser', () => {
|
||||||
it("should parse empty vars", () => {
|
it('should parse empty vars', () => {
|
||||||
const input = {
|
const input = {
|
||||||
"variables": []
|
variables: []
|
||||||
};
|
};
|
||||||
|
|
||||||
const output = parser(input);
|
const output = parser(input);
|
||||||
@ -14,13 +14,15 @@ describe("env parser", () => {
|
|||||||
expect(output).toEqual(expected);
|
expect(output).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should parse single var line", () => {
|
it('should parse single var line', () => {
|
||||||
const input = {
|
const input = {
|
||||||
"variables": [{
|
variables: [
|
||||||
"name": "url",
|
{
|
||||||
"value": "http://localhost:3000",
|
name: 'url',
|
||||||
"enabled" : true,
|
value: 'http://localhost:3000',
|
||||||
}]
|
enabled: true
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
const output = parser(input);
|
const output = parser(input);
|
||||||
@ -31,17 +33,20 @@ describe("env parser", () => {
|
|||||||
expect(output).toEqual(expected);
|
expect(output).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should parse multiple var lines", () => {
|
it('should parse multiple var lines', () => {
|
||||||
const input = {
|
const input = {
|
||||||
"variables": [{
|
variables: [
|
||||||
"name": "url",
|
{
|
||||||
"value": "http://localhost:3000",
|
name: 'url',
|
||||||
"enabled" : true
|
value: 'http://localhost:3000',
|
||||||
}, {
|
enabled: true
|
||||||
"name": "port",
|
},
|
||||||
"value": "3000",
|
{
|
||||||
"enabled" : false
|
name: 'port',
|
||||||
}]
|
value: '3000',
|
||||||
|
enabled: false
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
const expected = `vars {
|
const expected = `vars {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/**
|
/**
|
||||||
* This test file is used to test the text parser.
|
* This test file is used to test the text parser.
|
||||||
*/
|
*/
|
||||||
const parser = require("../src/bruToJson");
|
const parser = require('../src/bruToJson');
|
||||||
|
|
||||||
describe("script parser", () => {
|
describe('script parser', () => {
|
||||||
it("should parse request script", () => {
|
it('should parse request script', () => {
|
||||||
const input = `
|
const input = `
|
||||||
script:pre-request {
|
script:pre-request {
|
||||||
$req.setHeader('Content-Type', 'application/json');
|
$req.setHeader('Content-Type', 'application/json');
|
||||||
@ -13,14 +13,14 @@ script:pre-request {
|
|||||||
|
|
||||||
const output = parser(input);
|
const output = parser(input);
|
||||||
const expected = {
|
const expected = {
|
||||||
"script": {
|
script: {
|
||||||
"req": "$req.setHeader('Content-Type', 'application/json');"
|
req: "$req.setHeader('Content-Type', 'application/json');"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
expect(output).toEqual(expected);
|
expect(output).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should parse response script", () => {
|
it('should parse response script', () => {
|
||||||
const input = `
|
const input = `
|
||||||
script:post-response {
|
script:post-response {
|
||||||
expect(response.status).to.equal(200);
|
expect(response.status).to.equal(200);
|
||||||
@ -29,8 +29,8 @@ script:post-response {
|
|||||||
|
|
||||||
const output = parser(input);
|
const output = parser(input);
|
||||||
const expected = {
|
const expected = {
|
||||||
"script": {
|
script: {
|
||||||
"res": "expect(response.status).to.equal(200);"
|
res: 'expect(response.status).to.equal(200);'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
expect(output).toEqual(expected);
|
expect(output).toEqual(expected);
|
||||||
|
Loading…
Reference in New Issue
Block a user