mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-08 22:45:25 +00:00
feat: script and tests functionality
This commit is contained in:
@@ -21,6 +21,8 @@ const {
|
||||
bodyFormUrlEncodedTag,
|
||||
bodyMultipartFormTag
|
||||
} = require('./body-tag');
|
||||
const scriptTag = require('./script-tag');
|
||||
const testsTag = require('./tests-tag');
|
||||
|
||||
const bruToJson = (fileContents) => {
|
||||
const parser = many(choice([
|
||||
@@ -33,6 +35,8 @@ const bruToJson = (fileContents) => {
|
||||
bodyXmlTag,
|
||||
bodyFormUrlEncodedTag,
|
||||
bodyMultipartFormTag,
|
||||
scriptTag,
|
||||
testsTag,
|
||||
anyChar
|
||||
]));
|
||||
|
||||
@@ -50,7 +54,9 @@ const bruToJson = (fileContents) => {
|
||||
url: parsed.url || '',
|
||||
params: parsed.params || [],
|
||||
headers: parsed.headers || [],
|
||||
body: parsed.body || {mode: 'none'}
|
||||
body: parsed.body || {mode: 'none'},
|
||||
script: parsed.script ? outdentString(parsed.script) : '',
|
||||
tests: parsed.tests ? outdentString(parsed.tests) : ''
|
||||
}
|
||||
};
|
||||
|
||||
@@ -85,7 +91,9 @@ const jsonToBru = (json) => {
|
||||
url,
|
||||
params,
|
||||
headers,
|
||||
body
|
||||
body,
|
||||
script,
|
||||
tests
|
||||
}
|
||||
} = json;
|
||||
|
||||
@@ -161,6 +169,22 @@ ${body.multipartForm.map(item => ` ${item.enabled ? 1 : 0} ${item.name} ${item.
|
||||
`;
|
||||
}
|
||||
|
||||
if(script && script.length) {
|
||||
bru += `
|
||||
script
|
||||
${indentString(script)}
|
||||
/script
|
||||
`;
|
||||
}
|
||||
|
||||
if(tests && tests.length) {
|
||||
bru += `
|
||||
tests
|
||||
${indentString(tests)}
|
||||
/tests
|
||||
`;
|
||||
}
|
||||
|
||||
return bru;
|
||||
};
|
||||
|
||||
|
||||
16
packages/bruno-lang/src/script-tag.js
Normal file
16
packages/bruno-lang/src/script-tag.js
Normal file
@@ -0,0 +1,16 @@
|
||||
const {
|
||||
between,
|
||||
regex,
|
||||
everyCharUntil
|
||||
} = require("arcsecond");
|
||||
|
||||
const scriptBegin = regex(/^script\s*\r?\n/);
|
||||
const scriptEnd = regex(/^[\r?\n]+\/script[\s\r?\n]*/);
|
||||
|
||||
const scriptTag = between(scriptBegin)(scriptEnd)(everyCharUntil(scriptEnd)).map((script) => {
|
||||
return {
|
||||
script: script
|
||||
};
|
||||
});
|
||||
|
||||
module.exports = scriptTag;
|
||||
16
packages/bruno-lang/src/tests-tag.js
Normal file
16
packages/bruno-lang/src/tests-tag.js
Normal file
@@ -0,0 +1,16 @@
|
||||
const {
|
||||
between,
|
||||
regex,
|
||||
everyCharUntil
|
||||
} = require("arcsecond");
|
||||
|
||||
const testsBegin = regex(/^tests\s*\r?\n/);
|
||||
const testsEnd = regex(/^[\r?\n]+\/tests[\s\r?\n]*/);
|
||||
|
||||
const testsTag = between(testsBegin)(testsEnd)(everyCharUntil(testsEnd)).map((tests) => {
|
||||
return {
|
||||
tests: tests
|
||||
};
|
||||
});
|
||||
|
||||
module.exports = testsTag;
|
||||
Reference in New Issue
Block a user