Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Mar 4, 2024
1 parent 3386cd3 commit c3f48bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 10 additions & 6 deletions crates/turborepo-lib/src/global_deps_package_detector.rs
Expand Up @@ -2,7 +2,7 @@ use thiserror::Error;
use turbopath::AnchoredSystemPath;
use turborepo_repository::{
change_mapper::{DefaultPackageDetector, PackageDetection, PackageDetector},
package_graph::PackageGraph,
package_graph::{PackageGraph, WorkspacePackage},
};
use wax::{BuildError, Program};

Expand Down Expand Up @@ -41,15 +41,16 @@ impl<'a> PackageDetector for GlobalDepsPackageDetector<'a> {
fn detect_package(&self, path: &AnchoredSystemPath) -> PackageDetection {
match DefaultPackageDetector::new(self.pkg_dep_graph).detect_package(path) {
// Since `DefaultPackageDetector` is overly conservative, we can check here if
// the path is actually in globalDeps and if not, return it as PackageDetection::None.
// the path is actually in globalDeps and if not, return it as
// PackageDetection::Package(WorkspacePackage::root()).
PackageDetection::All => {
let cleaned_path = path.clean();
let in_global_deps = self.global_deps_matcher.is_match(cleaned_path.as_str());

if in_global_deps {
PackageDetection::All
} else {
PackageDetection::None
PackageDetection::Package(WorkspacePackage::root())
}
}
result => result,
Expand All @@ -67,7 +68,7 @@ mod tests {
change_mapper::{ChangeMapper, DefaultPackageDetector, PackageChanges},
discovery,
discovery::PackageDiscovery,
package_graph::PackageGraphBuilder,
package_graph::{PackageGraphBuilder, WorkspacePackage},
package_json::PackageJson,
};

Expand Down Expand Up @@ -135,9 +136,12 @@ mod tests {
None,
)?;

// We shouldn't get any changes since we have global deps specified and
// We only get a root workspace change since we have global deps specified and
// README.md is not one of them
assert_eq!(package_changes, PackageChanges::Some(HashSet::new()));
assert_eq!(
package_changes,
PackageChanges::Some([WorkspacePackage::root()].into_iter().collect())
);

Ok(())
}
Expand Down
8 changes: 6 additions & 2 deletions packages/turbo-repository/__tests__/find.test.ts
Expand Up @@ -59,9 +59,13 @@ describe("Workspace", () => {
],
},
{
description: "global change that can be ignored",
description:
"global change should be irrelevant but still triggers all packages",
files: ["README.md"],
expected: [],
expected: [
{ name: "app-a", relativePath: "apps/app" },
{ name: "ui", relativePath: "packages/ui" },
],
},
];

Expand Down

0 comments on commit c3f48bb

Please sign in to comment.