Skip to content

Commit

Permalink
added tests and fixed a issue with types
Browse files Browse the repository at this point in the history
  • Loading branch information
afinch7 committed Nov 19, 2019
1 parent 29df218 commit 1fc95be
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cli/js/lib.deno_runtime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ declare namespace Deno {
control: Uint8Array,
zeroCopy?: ArrayBufferView | null
): Uint8Array | null;
setAsyncHandler(handler: MessageCallback): void;
setAsyncHandler(handler: AsyncHandler): void;
}

export interface NativePlugin {
Expand Down
29 changes: 29 additions & 0 deletions cli/tests/052_native_plugins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const filenameBase = "test_native_plugin";

let filenameSuffix = ".so";
let filenamePrefix = "lib";

if (Deno.build.os === "win") {
filenameSuffix = ".dll";
filenamePrefix = "";
}
if (Deno.build.os === "mac") {
filenameSuffix = ".dylib";
}

const filename = `${filenamePrefix}${filenameBase}${filenameSuffix}`;

const plugin = Deno.openPlugin(`./../../target/${Deno.args[1]}/${filename}`);

// eslint-disable-next-line @typescript-eslint/camelcase
const test_io_sync = plugin.ops.test_io_sync;

const textDecoder = new TextDecoder();

// eslint-disable-next-line @typescript-eslint/camelcase
const response = test_io_sync.dispatch(
new Uint8Array([116, 101, 115, 116]),
new Uint8Array([116, 101, 115, 116])
);

console.log(`Native Binding Response: ${textDecoder.decode(response)}`);
2 changes: 2 additions & 0 deletions cli/tests/052_native_plugins.ts.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Hello from native bindings. data: test | zero_copy: test
Native Binding Response: test
14 changes: 14 additions & 0 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,20 @@ itest!(_051_wasm_import {
http_server: true,
});

#[cfg(not(debug_assertions))]
itest!(_052_native_plugins_release {
args: "run --reload --allow-native 052_native_plugins.ts release",
output: "052_native_plugins.ts.out",
http_server: false,
});

#[cfg(debug_assertions)]
itest!(_052_native_plugins_debug {
args: "run --reload --allow-native 052_native_plugins.ts debug",
output: "052_native_plugins.ts.out",
http_server: false,
});

itest!(lock_check_ok {
args: "run --lock=lock_check_ok.json http://127.0.0.1:4545/cli/tests/003_relative_import.ts",
output: "003_relative_import.ts.out",
Expand Down
6 changes: 0 additions & 6 deletions cli/tests/test_native_plugin/mod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
const plugin = Deno.openPlugin(
"./../../../target/debug/libtest_native_plugin.so"
);
const op_test_io_async = plugin.ops.op_test_io_async;

console.log(op_test_io_async);

0 comments on commit 1fc95be

Please sign in to comment.