mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 21:50:00 -05:00
fix(test): proper type checking for files with doc tests (#23654)
Closes https://github.com/denoland/deno/issues/23430 --------- Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
This commit is contained in:
parent
811280af77
commit
1b27b58396
4 changed files with 37 additions and 22 deletions
|
@ -1326,27 +1326,7 @@ pub async fn check_specifiers(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if !inline_files.is_empty() {
|
let mut module_specifiers = specifiers
|
||||||
let specifiers = inline_files
|
|
||||||
.iter()
|
|
||||||
.map(|file| file.specifier.clone())
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
for file in inline_files {
|
|
||||||
file_fetcher.insert_memory_files(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
module_load_preparer
|
|
||||||
.prepare_module_load(
|
|
||||||
specifiers,
|
|
||||||
false,
|
|
||||||
lib,
|
|
||||||
PermissionsContainer::new(Permissions::allow_all()),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let module_specifiers = specifiers
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|(specifier, mode)| {
|
.filter_map(|(specifier, mode)| {
|
||||||
if mode != TestMode::Documentation {
|
if mode != TestMode::Documentation {
|
||||||
|
@ -1355,7 +1335,16 @@ pub async fn check_specifiers(
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
if !inline_files.is_empty() {
|
||||||
|
module_specifiers
|
||||||
|
.extend(inline_files.iter().map(|file| file.specifier.clone()));
|
||||||
|
|
||||||
|
for file in inline_files {
|
||||||
|
file_fetcher.insert_memory_files(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module_load_preparer
|
module_load_preparer
|
||||||
.prepare_module_load(
|
.prepare_module_load(
|
||||||
|
|
5
tests/specs/test/type_check_with_doc/__test__.jsonc
Normal file
5
tests/specs/test/type_check_with_doc/__test__.jsonc
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"args": "test --doc main.ts",
|
||||||
|
"output": "main.out",
|
||||||
|
"exitCode": 1
|
||||||
|
}
|
13
tests/specs/test/type_check_with_doc/main.out
Normal file
13
tests/specs/test/type_check_with_doc/main.out
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
Check [WILDCARD]/main.ts
|
||||||
|
Check [WILDCARD]/main.ts$2-5.ts
|
||||||
|
error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'.
|
||||||
|
const a: string = 1;
|
||||||
|
^
|
||||||
|
at file://[WILDCARD]/main.ts:8:7
|
||||||
|
|
||||||
|
TS2322 [ERROR]: Type 'string' is not assignable to type 'number'.
|
||||||
|
const b: number = "1";
|
||||||
|
^
|
||||||
|
at file://[WILDCARD]/main.ts$2-5.ts:1:7
|
||||||
|
|
||||||
|
Found 2 errors.
|
8
tests/specs/test/type_check_with_doc/main.ts
Normal file
8
tests/specs/test/type_check_with_doc/main.ts
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
/**
|
||||||
|
* ```ts
|
||||||
|
* const b: number = "1";
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
function foo() {}
|
||||||
|
|
||||||
|
const a: string = 1;
|
Loading…
Add table
Reference in a new issue