Skip to content

Commit a607e0e

Browse files
committed
fix: resolve broadcast_channel tests and custom_import_logic example
- Add explicit type annotations to broadcast_channel async test methods - Fix test import paths (use super::BroadcastChannel) - Replace URL-dependent assert module with simpler colors module - All tests now pass with --all-features (50 tests)
1 parent 0b21cfa commit a607e0e

2 files changed

Lines changed: 33 additions & 21 deletions

File tree

examples/custom_import_logic.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ impl ImportProvider for MyImportProvider {
101101

102102
fn main() -> Result<(), rustyscript::Error> {
103103
let mut import_provider = MyImportProvider::default();
104-
import_provider.add_redirect("mod_assert", "https://deno.land/std@0.224.0/assert/mod.ts")?;
105-
import_provider.add_static_module("my-module", "export const foo = 1");
104+
// Add a redirect for a simple utility module
105+
import_provider.add_redirect("colors", "https://deno.land/std@0.224.0/fmt/colors.ts")?;
106+
// Add a static module with some test data
107+
import_provider.add_static_module("my-module", "export const foo = 1; export const bar = 'test';");
106108

107109
let mut runtime = Runtime::new(RuntimeOptions {
108110
import_provider: Some(Box::new(import_provider)),
@@ -112,10 +114,17 @@ fn main() -> Result<(), rustyscript::Error> {
112114
let module = Module::new(
113115
"custom_imports.js",
114116
"
115-
import { assertEquals } from 'redirect:mod_assert';
116-
import { foo } from 'static:my-module';
117-
118-
assertEquals(1, foo)
117+
import { bold } from 'redirect:colors';
118+
import { foo, bar } from 'static:my-module';
119+
120+
// Test static module imports
121+
if (foo !== 1) throw new Error('Expected foo to be 1');
122+
if (bar !== 'test') throw new Error('Expected bar to be test');
123+
124+
// Test redirect module import
125+
const text = bold('Hello from custom imports!');
126+
console.log(text);
127+
console.log('✓ All custom import tests passed!');
119128
",
120129
);
121130

src/ext/broadcast_channel/wrapper.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ impl Drop for BroadcastChannelWrapper {
255255

256256
#[cfg(test)]
257257
mod test {
258-
use crate::{BroadcastChannel, Runtime, RuntimeOptions};
258+
use super::BroadcastChannel;
259+
use crate::{Runtime, RuntimeOptions};
259260

260261
#[test]
261262
fn test_broadcast_channel_send_recv() {
@@ -276,17 +277,16 @@ mod test {
276277
let tokio_rt = runtime.tokio_runtime();
277278
tokio_rt.block_on(async {
278279
// Send from wrapper1
279-
wrapper1
280-
.send(&mut runtime, "hello from rust")
281-
.await
282-
.unwrap();
280+
let send_result: Result<(), crate::Error> = wrapper1
281+
.send::<&str>(&mut runtime, "hello from rust")
282+
.await;
283+
send_result.unwrap();
283284

284285
// Receive from wrapper2
285-
let received: String = wrapper2
286-
.recv(&mut runtime, Some(std::time::Duration::from_secs(1)))
287-
.await
288-
.unwrap()
289-
.unwrap();
286+
let recv_result: Result<Option<String>, crate::Error> = wrapper2
287+
.recv::<String>(&mut runtime, Some(std::time::Duration::from_secs(1)))
288+
.await;
289+
let received: String = recv_result.unwrap().unwrap();
290290

291291
assert_eq!(received, "hello from rust");
292292
});
@@ -318,13 +318,16 @@ mod test {
318318
let tokio_rt = runtime.tokio_runtime();
319319
tokio_rt.block_on(async {
320320
// Send to channel_a
321-
wrapper_a.send(&mut runtime, "message for a").await.unwrap();
321+
let send_result: Result<(), crate::Error> = wrapper_a
322+
.send::<&str>(&mut runtime, "message for a")
323+
.await;
324+
send_result.unwrap();
322325

323326
// wrapper_b should not receive this message (different channel name)
324-
let result: Option<String> = wrapper_b
325-
.recv(&mut runtime, Some(std::time::Duration::from_millis(100)))
326-
.await
327-
.unwrap();
327+
let recv_result: Result<Option<String>, crate::Error> = wrapper_b
328+
.recv::<String>(&mut runtime, Some(std::time::Duration::from_millis(100)))
329+
.await;
330+
let result: Option<String> = recv_result.unwrap();
328331

329332
assert!(result.is_none());
330333
});

0 commit comments

Comments
 (0)