Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(test): proper type checking for files with doc tests #23654

Merged
merged 5 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions cli/tools/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1326,37 +1326,30 @@ pub async fn check_specifiers(
)
.await?;

let mut module_specifiers = specifiers
.into_iter()
.filter_map(|(specifier, mode)| {
if mode != TestMode::Documentation {
Some(specifier)
} else {
None
}
})
.collect::<Vec<_>>();

if !inline_files.is_empty() {
let specifiers = inline_files
.iter()
.map(|file| file.specifier.clone())
.collect();
.collect::<Vec<_>>();
crowlKats marked this conversation as resolved.
Show resolved Hide resolved

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?;
module_specifiers.extend(specifiers);
}

let module_specifiers = specifiers
.into_iter()
.filter_map(|(specifier, mode)| {
if mode != TestMode::Documentation {
Some(specifier)
} else {
None
}
})
.collect();

module_load_preparer
.prepare_module_load(
module_specifiers,
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/test_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ itest!(text {
output: "test/text.out",
});

itest!(type_check_with_doc {
crowlKats marked this conversation as resolved.
Show resolved Hide resolved
args: "test --doc test/type_check_with_doc.ts",
exit_code: 1,
output: "test/type_check_with_doc.out",
});

itest!(quiet {
args: "test --quiet test/quiet.ts",
exit_code: 0,
Expand Down
13 changes: 13 additions & 0 deletions tests/testdata/test/type_check_with_doc.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Check [WILDCARD]/tests/testdata/test/type_check.ts
Check [WILDCARD]/tests/testdata/test/type_check.ts$2-5.ts
error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'.
const a: string = 1;
^
at file://[WILDCARD]/tests/testdata/test/type_check.ts:8:7

TS2322 [ERROR]: Type 'string' is not assignable to type 'number'.
const b: number = "1";
^
at file://[WILDCARD]/tests/testdata/test/type_check.ts$2-5.ts:1:7

Found 2 errors.
8 changes: 8 additions & 0 deletions tests/testdata/test/type_check_with_doc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* ```ts
* const b: number = "1";
* ```
*/
function foo() {}

const a: string = 1;
Loading