summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/integration/test_tests.rs12
-rw-r--r--cli/tests/testdata/test/doc_markdown.out7
-rw-r--r--cli/tests/testdata/test/markdown.md (renamed from cli/tests/testdata/test/doc_markdown/doc.md)0
-rw-r--r--cli/tests/testdata/test/markdown.out7
-rw-r--r--cli/tests/testdata/test/text.md1
-rw-r--r--cli/tests/testdata/test/text.out4
-rw-r--r--cli/tools/test_runner.rs62
7 files changed, 68 insertions, 25 deletions
diff --git a/cli/tests/integration/test_tests.rs b/cli/tests/integration/test_tests.rs
index 1cb38562f..b9b2d41ff 100644
--- a/cli/tests/integration/test_tests.rs
+++ b/cli/tests/integration/test_tests.rs
@@ -55,10 +55,16 @@ itest!(doc {
output: "test/doc.out",
});
-itest!(doc_markdown {
- args: "test --doc --allow-all test/doc_markdown",
+itest!(markdown {
+ args: "test --doc --allow-all test/markdown.md",
exit_code: 1,
- output: "test/doc_markdown.out",
+ output: "test/markdown.out",
+});
+
+itest!(text {
+ args: "test --doc --allow-all test/text.md",
+ exit_code: 0,
+ output: "test/text.out",
});
itest!(quiet {
diff --git a/cli/tests/testdata/test/doc_markdown.out b/cli/tests/testdata/test/doc_markdown.out
deleted file mode 100644
index 9d2c35974..000000000
--- a/cli/tests/testdata/test/doc_markdown.out
+++ /dev/null
@@ -1,7 +0,0 @@
-Check [WILDCARD]/test/doc_markdown/doc.md$11-14.js
-Check [WILDCARD]/test/doc_markdown/doc.md$17-20.ts
-Check [WILDCARD]/test/doc_markdown/doc.md$23-26.ts
-error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'.
-const a: string = 42;
- ^
- at [WILDCARD]/test/doc_markdown/doc.md$23-26.ts:1:7
diff --git a/cli/tests/testdata/test/doc_markdown/doc.md b/cli/tests/testdata/test/markdown.md
index e5afb841b..e5afb841b 100644
--- a/cli/tests/testdata/test/doc_markdown/doc.md
+++ b/cli/tests/testdata/test/markdown.md
diff --git a/cli/tests/testdata/test/markdown.out b/cli/tests/testdata/test/markdown.out
new file mode 100644
index 000000000..3f7bc7366
--- /dev/null
+++ b/cli/tests/testdata/test/markdown.out
@@ -0,0 +1,7 @@
+Check [WILDCARD]/test/markdown.md$11-14.js
+Check [WILDCARD]/test/markdown.md$17-20.ts
+Check [WILDCARD]/test/markdown.md$23-26.ts
+error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'.
+const a: string = 42;
+ ^
+ at [WILDCARD]/test/markdown.md$23-26.ts:1:7
diff --git a/cli/tests/testdata/test/text.md b/cli/tests/testdata/test/text.md
new file mode 100644
index 000000000..be89d24bf
--- /dev/null
+++ b/cli/tests/testdata/test/text.md
@@ -0,0 +1 @@
+This fixture contains no actual tests.
diff --git a/cli/tests/testdata/test/text.out b/cli/tests/testdata/test/text.out
new file mode 100644
index 000000000..b09b04c05
--- /dev/null
+++ b/cli/tests/testdata/test/text.out
@@ -0,0 +1,4 @@
+running 0 tests from [WILDCARD]/test/text.md
+
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD])
+
diff --git a/cli/tools/test_runner.rs b/cli/tools/test_runner.rs
index 9e5489bf7..ca8fa7792 100644
--- a/cli/tools/test_runner.rs
+++ b/cli/tools/test_runner.rs
@@ -264,7 +264,7 @@ where
Ok(prepared)
}
-pub async fn run_test_file(
+pub async fn test_specifier(
program_state: Arc<ProgramState>,
main_module: ModuleSpecifier,
permissions: Permissions,
@@ -273,21 +273,32 @@ pub async fn run_test_file(
shuffle: Option<u64>,
channel: Sender<TestEvent>,
) -> Result<(), AnyError> {
+ let mut fetch_permissions = Permissions::allow_all();
+
+ let main_file = program_state
+ .file_fetcher
+ .fetch(&main_module, &mut fetch_permissions)
+ .await?;
+
let test_module =
deno_core::resolve_path(&format!("{}$deno$test.js", Uuid::new_v4()))?;
- let test_source = format!(
- r#"
- import "{}";
- await new Promise(resolve => setTimeout(resolve, 0));
- await Deno[Deno.internal].runTests({});
- "#,
- main_module,
+
+ let mut test_source = String::new();
+ if main_file.media_type != MediaType::Unknown {
+ test_source.push_str(&format!("import \"{}\";\n", main_module));
+ }
+
+ test_source
+ .push_str("await new Promise(resolve => setTimeout(resolve, 0));\n");
+
+ test_source.push_str(&format!(
+ "await Deno[Deno.internal].runTests({});\n",
json!({
- "disableLog": quiet,
- "filter": filter,
- "shuffle": shuffle,
- })
- );
+ "disableLog": quiet,
+ "filter": filter,
+ "shuffle": shuffle,
+ }),
+ ));
let test_file = File {
local: test_module.to_file_path().unwrap(),
@@ -562,9 +573,30 @@ pub async fn run_tests(
.await?;
}
+ let prepare_roots = {
+ let mut files = Vec::new();
+ let mut fetch_permissions = Permissions::allow_all();
+ for specifier in &test_modules {
+ let file = program_state
+ .file_fetcher
+ .fetch(specifier, &mut fetch_permissions)
+ .await?;
+
+ files.push(file);
+ }
+
+ let prepare_roots = files
+ .iter()
+ .filter(|file| file.media_type != MediaType::Unknown)
+ .map(|file| file.specifier.clone())
+ .collect();
+
+ prepare_roots
+ };
+
program_state
.prepare_module_graph(
- test_modules.clone(),
+ prepare_roots,
lib.clone(),
Permissions::allow_all(),
permissions.clone(),
@@ -587,7 +619,7 @@ pub async fn run_tests(
tokio::task::spawn_blocking(move || {
let join_handle = std::thread::spawn(move || {
- let future = run_test_file(
+ let future = test_specifier(
program_state,
main_module,
permissions,