diff --git a/build.rs b/build.rs index b8a7c775..94121b0d 100644 --- a/build.rs +++ b/build.rs @@ -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"); } diff --git a/providers/shopify_functions_javy_v2.wasm b/providers/shopify_functions_javy_v2.wasm new file mode 100644 index 00000000..a269dc4d Binary files /dev/null and b/providers/shopify_functions_javy_v2.wasm differ diff --git a/tests/fixtures/build/js_function_javy_plugin_v2.wasm b/tests/fixtures/build/js_function_javy_plugin_v2.wasm new file mode 100644 index 00000000..83b1e236 Binary files /dev/null and b/tests/fixtures/build/js_function_javy_plugin_v2.wasm differ diff --git a/tests/fixtures/js_function_javy_plugin_v2/README.md b/tests/fixtures/js_function_javy_plugin_v2/README.md new file mode 100644 index 00000000..04f740c8 --- /dev/null +++ b/tests/fixtures/js_function_javy_plugin_v2/README.md @@ -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' +``` diff --git a/tests/fixtures/js_function_javy_plugin_v2/functions.js b/tests/fixtures/js_function_javy_plugin_v2/functions.js new file mode 100644 index 00000000..2509cf2e --- /dev/null +++ b/tests/fixtures/js_function_javy_plugin_v2/functions.js @@ -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; +} + +// +function run2() { + return run_default(run); +} +export { + run2 as run +}; diff --git a/tests/fixtures/js_function_javy_plugin_v2/index.wit b/tests/fixtures/js_function_javy_plugin_v2/index.wit new file mode 100644 index 00000000..961a48fb --- /dev/null +++ b/tests/fixtures/js_function_javy_plugin_v2/index.wit @@ -0,0 +1,5 @@ +package local:main; + +world index-world { + export run: func(); +} \ No newline at end of file diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index b1ccec0a..5161c3ea 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -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(()) + } }