File tree Expand file tree Collapse file tree 7 files changed +76
-0
lines changed
js_function_javy_plugin_v2 Expand file tree Collapse file tree 7 files changed +76
-0
lines changed Original file line number Diff line number Diff line change @@ -3,4 +3,5 @@ fn main() {
33 println ! ( "cargo:rerun-if-changed=providers/javy_quickjs_provider_v2.wasm" ) ;
44 println ! ( "cargo:rerun-if-changed=providers/javy_quickjs_provider_v3.wasm" ) ;
55 println ! ( "cargo:rerun-if-changed=providers/shopify_functions_javy_v1.wasm" ) ;
6+ println ! ( "cargo:rerun-if-changed=providers/shopify_functions_javy_v2.wasm" ) ;
67}
Original file line number Diff line number Diff line change 1+ #### Compile
2+
3+ Use this command to recompile the ` js_function_javy_plugin_v2.wasm `
4+
5+ ```
6+ 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'
7+ ```
Original file line number Diff line number Diff line change 1+ // ../../node_modules/@shopify /shopify_function/run.ts
2+ function run_default ( userfunction ) {
3+ if ( ! ShopifyFunction ) {
4+ throw new Error (
5+ "ShopifyFunction is not defined. Please rebuild your function using the latest version of Shopify CLI."
6+ ) ;
7+ }
8+ const input_obj = ShopifyFunction . readInput ( ) ;
9+ const output_obj = userfunction ( input_obj ) ;
10+ ShopifyFunction . writeOutput ( output_obj ) ;
11+ }
12+
13+ // src/run.js
14+ var EMPTY_DISCOUNT = {
15+ discountApplicationStrategy : "FIRST" /* First */ ,
16+ discounts : [ ]
17+ } ;
18+ function run ( input ) {
19+ const configuration = JSON . parse (
20+ input ?. discountNode ?. metafield ?. value ?? "{}"
21+ ) ;
22+ return EMPTY_DISCOUNT ;
23+ }
24+
25+ // <stdin>
26+ function run2 ( ) {
27+ return run_default ( run ) ;
28+ }
29+ export {
30+ run2 as run
31+ } ;
Original file line number Diff line number Diff line change 1+ package local : main ;
2+
3+ world index-world {
4+ export run : func ();
5+ }
Original file line number Diff line number Diff line change @@ -423,4 +423,36 @@ mod tests {
423423
424424 Ok ( ( ) )
425425 }
426+
427+ #[ test]
428+ fn run_javy_plugin_v2 ( ) -> Result < ( ) > {
429+ let mut cmd = Command :: cargo_bin ( "function-runner" ) ?;
430+ let input = temp_input ( json ! ( { "hello" : "world" } ) ) ?;
431+
432+ cmd. args ( [
433+ "--function" ,
434+ "tests/fixtures/build/js_function_javy_plugin_v2.wasm" ,
435+ ] )
436+ . arg ( "--json" )
437+ . args ( [ "--codec" , "messagepack" ] )
438+ . args ( [ "--export" , "run" ] )
439+ . arg ( "--input" )
440+ . arg ( input. as_os_str ( ) )
441+ . stdout ( Stdio :: piped ( ) )
442+ . spawn ( )
443+ . expect ( "Failed to spawn child process" )
444+ . wait_with_output ( )
445+ . expect ( "Failed waiting for output" ) ;
446+
447+ // Command should succeed
448+ cmd. assert ( ) . success ( ) ;
449+
450+ // Input should be returned
451+ cmd. assert ( ) . stdout ( contains ( "hello" ) ) ;
452+ cmd. assert ( ) . stdout ( contains ( "world" ) ) ;
453+
454+ // Module output should be returned
455+ cmd. assert ( ) . stdout ( contains ( "discountApplicationStrategy" ) ) ;
456+ Ok ( ( ) )
457+ }
426458}
You can’t perform that action at this time.
0 commit comments