Skip to content

Commit

Permalink
fix(typescript-test): ignore potentially-junk files in node_modules
Browse files Browse the repository at this point in the history
  • Loading branch information
strager committed Sep 23, 2023
1 parent 01b7dfa commit de8c9b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/test-typescript-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,19 @@ TEST(Test_TypeScript_Test, markdown_unit_is_ignored) {
EXPECT_FALSE(units[1].get_linter_options().has_value());
EXPECT_TRUE(units[2].get_linter_options().has_value());
}

TEST(Test_TypeScript_Test, files_in_node_modules_are_ignored) {
// compiler/moduleResolutionWithExtensions_unexpected2.ts has garbage files in
// node_modules. I think this means we should ignore anything in node_modules
// (unless explicitly imported?).
Padded_String file(
u8"// @filename: /node_modules/foo.js\n"_sv
u8"hello();\n"_sv);
TypeScript_Test_Units units =
extract_units_from_typescript_test(std::move(file), u8"hello.js");
ASSERT_EQ(units.size(), 1);
EXPECT_FALSE(units[0].get_linter_options().has_value());
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions tools/test-typescript/typescript-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ find_typescript_test_filename_metadata_directive(
}

std::optional<Linter_Options> TypeScript_Test_Unit::get_linter_options() const {
if (starts_with(String8_View(this->name), u8"/node_modules/"_sv)) {
return std::nullopt;
}
if (ends_with(String8_View(this->name), u8".json"_sv)) {
return std::nullopt;
}
Expand Down

0 comments on commit de8c9b3

Please sign in to comment.