summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/flags.rs2
-rw-r--r--cli/js/testing.ts5
-rw-r--r--cli/tests/unit/filter_function_test.ts52
-rw-r--r--cli/tests/unit/unit_tests.ts1
4 files changed, 59 insertions, 1 deletions
diff --git a/cli/flags.rs b/cli/flags.rs
index b78dc646a..4cacb01e4 100644
--- a/cli/flags.rs
+++ b/cli/flags.rs
@@ -1105,7 +1105,7 @@ fn test_subcommand<'a, 'b>() -> App<'a, 'b> {
Arg::with_name("filter")
.long("filter")
.takes_value(true)
- .help("Run tests with this string in the test name"),
+ .help("Run tests with this string or pattern in the test name"),
)
.arg(
Arg::with_name("files")
diff --git a/cli/js/testing.ts b/cli/js/testing.ts
index e8d42c2eb..0648683a4 100644
--- a/cli/js/testing.ts
+++ b/cli/js/testing.ts
@@ -308,6 +308,9 @@ function createFilterFn(
if (filter) {
if (filter instanceof RegExp) {
passes = passes && filter.test(def.name);
+ } else if (filter.startsWith("/") && filter.endsWith("/")) {
+ const filterAsRegex = new RegExp(filter.slice(1, filter.length - 1));
+ passes = passes && filterAsRegex.test(def.name);
} else {
passes = passes && def.name.includes(filter);
}
@@ -325,6 +328,8 @@ function createFilterFn(
};
}
+exposeForTest("createFilterFn", createFilterFn);
+
interface RunTestsOptions {
exitOnFail?: boolean;
failFast?: boolean;
diff --git a/cli/tests/unit/filter_function_test.ts b/cli/tests/unit/filter_function_test.ts
new file mode 100644
index 000000000..dd83c1dbc
--- /dev/null
+++ b/cli/tests/unit/filter_function_test.ts
@@ -0,0 +1,52 @@
+import { unitTest, assertEquals } from "./test_util.ts";
+
+// @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol
+const { createFilterFn } = Deno[Deno.internal];
+
+unitTest(function filterAsString(): void {
+ const filterFn = createFilterFn("my-test");
+ const tests = [
+ {
+ fn(): void {},
+ name: "my-test",
+ },
+ {
+ fn(): void {},
+ name: "other-test",
+ },
+ ];
+ const filteredTests = tests.filter(filterFn);
+ assertEquals(filteredTests.length, 1);
+});
+
+unitTest(function filterAsREGEX(): void {
+ const filterFn = createFilterFn("/.+-test/");
+ const tests = [
+ {
+ fn(): void {},
+ name: "my-test",
+ },
+ {
+ fn(): void {},
+ name: "other-test",
+ },
+ ];
+ const filteredTests = tests.filter(filterFn);
+ assertEquals(filteredTests.length, 2);
+});
+
+unitTest(function filterAsEscapedREGEX(): void {
+ const filterFn = createFilterFn("/\\w+-test/");
+ const tests = [
+ {
+ fn(): void {},
+ name: "my-test",
+ },
+ {
+ fn(): void {},
+ name: "other-test",
+ },
+ ];
+ const filteredTests = tests.filter(filterFn);
+ assertEquals(filteredTests.length, 2);
+});
diff --git a/cli/tests/unit/unit_tests.ts b/cli/tests/unit/unit_tests.ts
index 1701170d1..ad820a55c 100644
--- a/cli/tests/unit/unit_tests.ts
+++ b/cli/tests/unit/unit_tests.ts
@@ -24,6 +24,7 @@ import "./event_target_test.ts";
import "./fetch_test.ts";
import "./file_test.ts";
import "./files_test.ts";
+import "./filter_function_test.ts";
import "./form_data_test.ts";
import "./format_error_test.ts";
import "./fs_events_test.ts";