feat: script and tests functionality

This commit is contained in:
Anoop M D
2023-01-22 23:39:16 +05:30
parent b70bbf78b1
commit 5c8d0a9e8a
18 changed files with 360 additions and 12 deletions

View File

@@ -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;
};

View 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;

View 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;