1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

fix(cli): allow specifiers of unknown media types with test command (#11652)

This commit is contained in:
Casper Beyer 2021-08-13 02:10:14 +08:00 committed by GitHub
parent eae9d5b647
commit 3dff757927
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 68 additions and 25 deletions

View file

@ -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 {

View file

@ -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

7
cli/tests/testdata/test/markdown.out vendored Normal file
View file

@ -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

1
cli/tests/testdata/test/text.md vendored Normal file
View file

@ -0,0 +1 @@
This fixture contains no actual tests.

4
cli/tests/testdata/test/text.out vendored Normal file
View file

@ -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])

View file

@ -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,
})
);
}),
));
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,