Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ let defaultFileTypes = {
{
name: "httpRequestFormat",
regex: [
"```(?:http)?\\n([A-Z]+)\\s+([^\\s]+)(?:\\s+HTTP\\/[\\d.]+)?\\s((?:[^\\s]+\\s?)*)(?:\\s([\\s\\S]*)\\s)?```",
"```(?:http)?\\r?\\n([A-Z]+)\\s+([^\\s]+)(?:\\s+HTTP\\/[\\d.]+)?\\r?\\n((?:[^\\s]+:\\s+[^\\s]+\\r?\\n)*)?(?:\\s+([\\s\\S]*)\\s+)?```",
],
actions: [
{
Expand Down
54 changes: 44 additions & 10 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,26 @@ async function parseContent({ config, content, filePath, fileType }) {

if (typeof stringOrObject === "string") {
// Replace $n with values[n]
stringOrObject = stringOrObject.replace(/\$[0-9]+/g, (variable) => {
const index = variable.substring(1);
return values[index];
});
// Find all $n variables in the string
const matches = stringOrObject.match(/\$[0-9]+/g);
if (matches) {
// Check if all variables exist in values
const allExist = matches.every((variable) => {
const index = variable.substring(1);
return (
Object.hasOwn(values, index) && typeof values[index] !== "undefined"
);
});
if (!allExist) {
return null;
} else {
// Perform substitution
stringOrObject = stringOrObject.replace(/\$[0-9]+/g, (variable) => {
const index = variable.substring(1);
return values[index];
});
}
}
}

Object.keys(stringOrObject).forEach((key) => {
Expand All @@ -310,13 +326,29 @@ async function parseContent({ config, content, filePath, fileType }) {
);
} else if (typeof stringOrObject[key] === "string") {
// Replace $n with values[n]
stringOrObject[key] = stringOrObject[key].replace(
/\$[0-9]+/g,
(variable) => {
const matches = stringOrObject[key].match(/\$[0-9]+/g);
if (matches) {
// Check if all variables exist in values
const allExist = matches.every((variable) => {
const index = variable.substring(1);
return values[index];
return (
Object.hasOwn(values, index) &&
typeof values[index] !== "undefined"
);
});
if (!allExist) {
delete stringOrObject[key];
} else {
// Perform substitution
stringOrObject[key] = stringOrObject[key].replace(
/\$[0-9]+/g,
(variable) => {
const index = variable.substring(1);
return values[index];
}
);
}
);
}
}
return key;
});
Expand Down Expand Up @@ -660,7 +692,9 @@ async function parseTests({ config, files }) {
spec.tests.push(...tests);

// Remove tests with no steps
spec.tests = spec.tests.filter((test) => test.steps && test.steps.length > 0);
spec.tests = spec.tests.filter(
(test) => test.steps && test.steps.length > 0
);

// Push spec to specs, if it is valid
const validation = validate({
Expand Down