Skip to content

Commit 5b8ed79

Browse files
author
Sunny Gurnani
committedSep 23, 2019
Made find as an Array so multiple regex can be supplied
1 parent 2a69a2b commit 5b8ed79

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed
 

‎lib/specs.js

+20-13
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,27 @@ function specsRunner(specs, reporter, callback, err, data) {
131131
path.pop();
132132
return;
133133
}
134-
if (Array.isArray(data[key]) && specs[key].find && specs[key].find.key && specs[key].find.pattern && specs[key].find.spec) {
135-
var arrData = data[key];
136-
var filteredData = arrData.find(function (item) {
137-
var regex = new RegExp(specs[key].find.pattern);
138-
return regex.test(item[specs[key].find.key]);
134+
if (Array.isArray(data[key]) && specs[key].find && specs[key].find.length) {
135+
specs[key].find.forEach(find => {
136+
if (find.key && find.pattern && find.spec) {
137+
var arrData = data[key];
138+
var filteredData = arrData.find(function (item) {
139+
var regex = new RegExp(find.pattern);
140+
return regex.test(item[find.key]);
141+
});
142+
var keyString = find.key + "." + filteredData[find.key];
143+
if (filteredData) {
144+
path.push(keyString)
145+
traverse(find.spec, filteredData);
146+
path.pop();
147+
} else {
148+
tests.push({
149+
text: path.join('.') + "." + keyString,
150+
result: new Error('not found')
151+
});
152+
}
153+
}
139154
});
140-
if (filteredData) {
141-
traverse(specs[key].find.spec, filteredData);
142-
} else {
143-
tests.push({
144-
text: path.join('.') + " " + specs[key].find.pattern,
145-
result: new Error('not found')
146-
});
147-
}
148155
path.pop();
149156
return;
150157
}

0 commit comments

Comments
 (0)
Please sign in to comment.