summaryrefslogtreecommitdiff
path: root/runtime/js
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/js')
-rw-r--r--runtime/js/40_testing.js40
1 files changed, 27 insertions, 13 deletions
diff --git a/runtime/js/40_testing.js b/runtime/js/40_testing.js
index 3e4a57df1..abbef2ae4 100644
--- a/runtime/js/40_testing.js
+++ b/runtime/js/40_testing.js
@@ -750,23 +750,37 @@
return inspectArgs([error]);
}
+ /**
+ * @param {string | { include?: string[], exclude?: string[] }} filter
+ * @returns {(def: { name: string }) => boolean}
+ */
function createTestFilter(filter) {
+ if (!filter) {
+ return () => true;
+ }
+
+ const regex =
+ typeof filter === "string" && StringPrototypeStartsWith(filter, "/") &&
+ StringPrototypeEndsWith(filter, "/")
+ ? new RegExp(StringPrototypeSlice(filter, 1, filter.length - 1))
+ : undefined;
+
+ const filterIsObject = filter != null && typeof filter === "object";
+
return (def) => {
- if (filter) {
- if (
- StringPrototypeStartsWith(filter, "/") &&
- StringPrototypeEndsWith(filter, "/")
- ) {
- const regex = new RegExp(
- StringPrototypeSlice(filter, 1, filter.length - 1),
- );
- return RegExpPrototypeTest(regex, def.name);
+ if (regex) {
+ return RegExpPrototypeTest(regex, def.name);
+ }
+ if (filterIsObject) {
+ if (filter.include && !filter.include.includes(def.name)) {
+ return false;
+ } else if (filter.exclude && filter.exclude.includes(def.name)) {
+ return false;
+ } else {
+ return true;
}
-
- return StringPrototypeIncludes(def.name, filter);
}
-
- return true;
+ return StringPrototypeIncludes(def.name, filter);
};
}