diff options
Diffstat (limited to 'test_plugin')
-rw-r--r-- | test_plugin/src/lib.rs | 13 | ||||
-rw-r--r-- | test_plugin/tests/integration_tests.rs | 10 | ||||
-rw-r--r-- | test_plugin/tests/test.js | 26 |
3 files changed, 28 insertions, 21 deletions
diff --git a/test_plugin/src/lib.rs b/test_plugin/src/lib.rs index c88052e9a..0c8655c5d 100644 --- a/test_plugin/src/lib.rs +++ b/test_plugin/src/lib.rs @@ -1,17 +1,16 @@ -#[macro_use] extern crate deno_core; extern crate futures; +use deno_core::Buf; use deno_core::Op; -use deno_core::PluginInitContext; -use deno_core::{Buf, ZeroCopyBuf}; +use deno_core::ZeroCopyBuf; use futures::future::FutureExt; -fn init(context: &mut dyn PluginInitContext) { - context.register_op("testSync", Box::new(op_test_sync)); - context.register_op("testAsync", Box::new(op_test_async)); +#[no_mangle] +pub fn deno_plugin_init(isolate: &mut deno_core::Isolate) { + isolate.register_op("testSync", op_test_sync); + isolate.register_op("testAsync", op_test_async); } -init_fn!(init); pub fn op_test_sync( _isolate: &mut deno_core::Isolate, diff --git a/test_plugin/tests/integration_tests.rs b/test_plugin/tests/integration_tests.rs index 04a032635..fc18d79d9 100644 --- a/test_plugin/tests/integration_tests.rs +++ b/test_plugin/tests/integration_tests.rs @@ -1,3 +1,7 @@ +// To run this test manually: +// cd test_plugin +// ../target/debug/deno --allow-plugin tests/test.js debug + // TODO(ry) Re-enable this test on windows. It is flaky for an unknown reason. #![cfg(not(windows))] @@ -38,11 +42,7 @@ fn basic() { println!("stderr {}", stderr); } assert!(output.status.success()); - let expected = if cfg!(target_os = "windows") { - "Hello from plugin. data: test | zero_copy: test\nPlugin Sync Response: test\r\nHello from plugin. data: test | zero_copy: test\nPlugin Async Response: test\r\n" - } else { - "Hello from plugin. data: test | zero_copy: test\nPlugin Sync Response: test\nHello from plugin. data: test | zero_copy: test\nPlugin Async Response: test\n" - }; + let expected = "Hello from plugin. data: test | zero_copy: test\nPlugin Sync Response: test\nHello from plugin. data: test | zero_copy: test\nPlugin Async Response: test\n"; assert_eq!(stdout, expected); assert_eq!(stderr, ""); } diff --git a/test_plugin/tests/test.js b/test_plugin/tests/test.js index d34624f09..3661e1078 100644 --- a/test_plugin/tests/test.js +++ b/test_plugin/tests/test.js @@ -17,14 +17,21 @@ const filename = `../target/${Deno.args[0]}/${filenamePrefix}${filenameBase}${fi // in runTestClose() below. const resourcesPre = Deno.resources(); -const plugin = Deno.openPlugin(filename); +const rid = Deno.openPlugin(filename); -const { testSync, testAsync } = plugin.ops; +const { testSync, testAsync } = Deno.core.ops(); +if (!(testSync > 0)) { + throw "bad op id for testSync"; +} +if (!(testAsync > 0)) { + throw "bad op id for testAsync"; +} const textDecoder = new TextDecoder(); function runTestSync() { - const response = testSync.dispatch( + const response = Deno.core.dispatch( + testSync, new Uint8Array([116, 101, 115, 116]), new Uint8Array([116, 101, 115, 116]) ); @@ -32,12 +39,13 @@ function runTestSync() { console.log(`Plugin Sync Response: ${textDecoder.decode(response)}`); } -testAsync.setAsyncHandler((response) => { +Deno.core.setAsyncHandler(testAsync, (response) => { console.log(`Plugin Async Response: ${textDecoder.decode(response)}`); }); function runTestAsync() { - const response = testAsync.dispatch( + const response = Deno.core.dispatch( + testAsync, new Uint8Array([116, 101, 115, 116]), new Uint8Array([116, 101, 115, 116]) ); @@ -50,22 +58,22 @@ function runTestAsync() { function runTestOpCount() { const start = Deno.metrics(); - testSync.dispatch(new Uint8Array([116, 101, 115, 116])); + Deno.core.dispatch(testSync, new Uint8Array([116, 101, 115, 116])); const end = Deno.metrics(); - if (end.opsCompleted - start.opsCompleted !== 2) { + if (end.opsCompleted - start.opsCompleted !== 1) { // one op for the plugin and one for Deno.metrics throw new Error("The opsCompleted metric is not correct!"); } - if (end.opsDispatched - start.opsDispatched !== 2) { + if (end.opsDispatched - start.opsDispatched !== 1) { // one op for the plugin and one for Deno.metrics throw new Error("The opsDispatched metric is not correct!"); } } function runTestPluginClose() { - plugin.close(); + Deno.close(rid); const resourcesPost = Deno.resources(); |