diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-05-03 01:00:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-03 00:00:38 +0000 |
commit | cf0579c7d4b69fcb205fb0d5320e0a00012720ee (patch) | |
tree | 114fe9f5a83aa17b01374de39364cfdf176db147 /tests/util/server/src/npm.rs | |
parent | 1b27b5839624ebf9fef65cea28a17281f3b79a74 (diff) |
test: npm registry handles two test scopes (#23663)
This commit updates our testing npm registry to handle
additional `@denotest2` scope in addition to `@denotest`
scope. I might have to update it further in the future to handle
additional scopes, but it's good enough for now.
Diffstat (limited to 'tests/util/server/src/npm.rs')
-rw-r--r-- | tests/util/server/src/npm.rs | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/tests/util/server/src/npm.rs b/tests/util/server/src/npm.rs index b747ca291..809584ced 100644 --- a/tests/util/server/src/npm.rs +++ b/tests/util/server/src/npm.rs @@ -16,6 +16,7 @@ use tar::Builder; use crate::testdata_path; pub const DENOTEST_SCOPE_NAME: &str = "@denotest"; +pub const DENOTEST2_SCOPE_NAME: &str = "@denotest2"; pub static PUBLIC_TEST_NPM_REGISTRY: Lazy<TestNpmRegistry> = Lazy::new(|| { TestNpmRegistry::new( @@ -121,16 +122,33 @@ impl TestNpmRegistry { uri_path.strip_prefix(&self.path) } - pub fn strip_denotest_prefix_from_uri_path<'s>( + pub fn get_test_scope_and_package_name_with_path_from_uri_path<'s>( &self, uri_path: &'s str, - ) -> Option<&'s str> { + ) -> Option<(&'s str, &'s str)> { let prefix1 = format!("{}{}/", self.path, DENOTEST_SCOPE_NAME); let prefix2 = format!("{}{}%2f", self.path, DENOTEST_SCOPE_NAME); - uri_path + let maybe_package_name_with_path = uri_path .strip_prefix(&prefix1) - .or_else(|| uri_path.strip_prefix(&prefix2)) + .or_else(|| uri_path.strip_prefix(&prefix2)); + + if let Some(package_name_with_path) = maybe_package_name_with_path { + return Some((DENOTEST_SCOPE_NAME, package_name_with_path)); + } + + let prefix1 = format!("{}{}/", self.path, DENOTEST2_SCOPE_NAME); + let prefix2 = format!("{}{}%2f", self.path, DENOTEST2_SCOPE_NAME); + + let maybe_package_name_with_path = uri_path + .strip_prefix(&prefix1) + .or_else(|| uri_path.strip_prefix(&prefix2)); + + if let Some(package_name_with_path) = maybe_package_name_with_path { + return Some((DENOTEST2_SCOPE_NAME, package_name_with_path)); + } + + None } pub fn uri_path_starts_with_registry_path(&self, uri_path: &str) -> bool { |