diff --git a/test/test-typescript-test.cpp b/test/test-typescript-test.cpp index b697b70046..e175348625 100644 --- a/test/test-typescript-test.cpp +++ b/test/test-typescript-test.cpp @@ -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()); +} } } diff --git a/tools/test-typescript/typescript-test.cpp b/tools/test-typescript/typescript-test.cpp index 6c98f69b1e..a5814f2a5f 100644 --- a/tools/test-typescript/typescript-test.cpp +++ b/tools/test-typescript/typescript-test.cpp @@ -127,6 +127,9 @@ find_typescript_test_filename_metadata_directive( } std::optional 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; }