Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ fn main() {
println!("cargo:rerun-if-changed=providers/javy_quickjs_provider_v2.wasm");
println!("cargo:rerun-if-changed=providers/javy_quickjs_provider_v3.wasm");
println!("cargo:rerun-if-changed=providers/shopify_functions_javy_v1.wasm");
println!("cargo:rerun-if-changed=providers/shopify_functions_javy_v2.wasm");
}
Binary file added providers/shopify_functions_javy_v2.wasm
Binary file not shown.
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/fixtures/js_function_javy_plugin_v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#### Compile

Use this command to recompile the `js_function_javy_plugin_v2.wasm`

```
javy build -C wit=index.wit -C wit-world=index-world -C dynamic -C plugin='../../../providers/shopify_functions_javy_v2.wasm' -o './js_function_javy_plugin_v2.wasm' './functions.js'
```
31 changes: 31 additions & 0 deletions tests/fixtures/js_function_javy_plugin_v2/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// ../../node_modules/@shopify/shopify_function/run.ts
function run_default(userfunction) {
if (!ShopifyFunction) {
throw new Error(
"ShopifyFunction is not defined. Please rebuild your function using the latest version of Shopify CLI."
);
}
const input_obj = ShopifyFunction.readInput();
const output_obj = userfunction(input_obj);
ShopifyFunction.writeOutput(output_obj);
}

// src/run.js
var EMPTY_DISCOUNT = {
discountApplicationStrategy: "FIRST" /* First */,
discounts: []
};
function run(input) {
const configuration = JSON.parse(
input?.discountNode?.metafield?.value ?? "{}"
);
return EMPTY_DISCOUNT;
}

// <stdin>
function run2() {
return run_default(run);
}
export {
run2 as run
};
5 changes: 5 additions & 0 deletions tests/fixtures/js_function_javy_plugin_v2/index.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package local:main;

world index-world {
export run: func();
}
32 changes: 32 additions & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,4 +423,36 @@ mod tests {

Ok(())
}

#[test]
fn run_javy_plugin_v2() -> Result<()> {
let mut cmd = Command::cargo_bin("function-runner")?;
let input = temp_input(json!({"hello": "world"}))?;

cmd.args([
"--function",
"tests/fixtures/build/js_function_javy_plugin_v2.wasm",
])
.arg("--json")
.args(["--codec", "messagepack"])
.args(["--export", "run"])
.arg("--input")
.arg(input.as_os_str())
.stdout(Stdio::piped())
.spawn()
.expect("Failed to spawn child process")
.wait_with_output()
.expect("Failed waiting for output");

// Command should succeed
cmd.assert().success();

// Input should be returned
cmd.assert().stdout(contains("hello"));
cmd.assert().stdout(contains("world"));

// Module output should be returned
cmd.assert().stdout(contains("discountApplicationStrategy"));
Ok(())
}
}