Skip to content

Commit 7b9b4d9

Browse files
brooksmtownsendthomastaylor312
authored andcommitted
test(core): add test for transitive local dep
Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com>
1 parent a6378d9 commit 7b9b4d9

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

crates/wasm-pkg-core/tests/fetch.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,69 @@ async fn test_nested_local(#[values(OutputType::Wasm, OutputType::Wit)] output:
7777
);
7878
}
7979

80+
#[rstest]
81+
#[tokio::test]
82+
async fn test_transitive_local(#[values(OutputType::Wasm, OutputType::Wit)] output: OutputType) {
83+
let (_temp, fixture_path) = common::load_fixture("transitive-local").await.unwrap();
84+
let project_path = fixture_path.join("example-a");
85+
let lock_file = project_path.join("wkg.lock");
86+
let mut lock = LockFile::new_with_path([], &lock_file)
87+
.await
88+
.expect("Should be able to create a new lock file");
89+
// ```toml
90+
// [overrides]
91+
// "example-b:bar" = { "path" = "../example-b/wit" }
92+
// "example-c:baz" = { "path" = "../example-c/wit" }
93+
// ```
94+
let config = Config {
95+
overrides: Some(HashMap::from([
96+
(
97+
"example-b:bar".to_string(),
98+
Override {
99+
path: Some(fixture_path.join("example-b").join("wit")),
100+
version: None,
101+
},
102+
),
103+
(
104+
"example-c:baz".to_string(),
105+
Override {
106+
path: Some(fixture_path.join("example-c").join("wit")),
107+
version: None,
108+
},
109+
),
110+
])),
111+
..Default::default()
112+
};
113+
let (_temp_cache, client) = common::get_client().await.unwrap();
114+
115+
assert!(
116+
// If overrides didn't properly resolve, this will fail
117+
wit::fetch_dependencies(&config, project_path.join("wit"), &mut lock, client, output)
118+
.await
119+
.is_ok(),
120+
"Should be able to fetch the dependencies"
121+
);
122+
123+
// Ensure that the deps directory contains the correct dependencies
124+
let mut deps_dir = tokio::fs::read_dir(project_path.join("wit").join("deps"))
125+
.await
126+
.expect("Should be able to read the deps directory");
127+
let mut deps = Vec::new();
128+
while let Ok(Some(entry)) = deps_dir.next_entry().await {
129+
deps.push(entry.file_name().to_string_lossy().to_string());
130+
}
131+
assert_eq!(deps.len(), 2);
132+
assert!(deps.contains(&"example-b-bar-0.1.0".to_string()));
133+
assert!(deps.contains(&"example-c-baz-0.1.0".to_string()));
134+
135+
// All dependencies are local, so the lock file should be empty
136+
assert_eq!(
137+
lock.packages.len(),
138+
0,
139+
"Should have the correct number of packages in the lock file"
140+
);
141+
}
142+
80143
async fn build_component(fixture_path: &Path) {
81144
let output = Command::new(env!("CARGO"))
82145
.current_dir(fixture_path)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package example-a:foo@0.1.0;
2+
3+
interface foo {
4+
record request {
5+
foo: list<u8>,
6+
}
7+
}
8+
9+
world handler {
10+
import example-b:bar/bar@0.1.0;
11+
export foo;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package example-b:bar@0.1.0;
2+
3+
interface bar {
4+
record response {
5+
bar: list<u8>,
6+
}
7+
}
8+
9+
world handler {
10+
import example-c:baz/baz@0.1.0;
11+
export bar;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package example-c:baz@0.1.0;
2+
3+
interface baz {
4+
record requestresponse {
5+
baz: list<u8>,
6+
}
7+
}
8+
9+
world handler {
10+
// No dependencies to import
11+
export baz;
12+
}

0 commit comments

Comments
 (0)