diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2022-03-30 09:59:27 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-30 09:59:27 +1100 |
commit | 061090de7e95e8e7a97f3277bd1a72899ebd1570 (patch) | |
tree | 85fbf3ed3dc4cf51a15c2baaf8257a47149c43ef /runtime/js | |
parent | 4a0b2c28a15d76c0c40bf07c3753dfbcce4dace1 (diff) |
feat(lsp): add experimental testing API (#13798)
Ref: denoland/vscode_deno#629
Diffstat (limited to 'runtime/js')
-rw-r--r-- | runtime/js/40_testing.js | 40 |
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); }; } |