@@ -9,6 +9,7 @@ use std::sync::{Arc, LazyLock, Mutex};
99
1010use common:: { generate_code, TestEmitter } ;
1111use cubetranspilers:: cube_prop_ctx_transpiler:: * ;
12+ use insta:: assert_snapshot;
1213use swc_core:: ecma:: ast:: { EsVersion , Program } ;
1314use swc_core:: {
1415 common:: {
@@ -206,11 +207,8 @@ fn test_simple_transform() {
206207
207208 let output_code = generate_code ( & program, & cm) ;
208209
209- assert ! (
210- output_code. contains( "sql: ()=>`" ) ,
211- "Output code should contain arrow function for *.sql, got:\n {}" ,
212- output_code
213- ) ;
210+ assert_snapshot ! ( "simple_transform" , output_code) ;
211+
214212 let diags = diagnostics. lock ( ) . unwrap ( ) ;
215213 assert ! (
216214 diags. is_empty( ) ,
@@ -512,61 +510,8 @@ fn test_complicated_transform_1st_stage() {
512510
513511 let output_code = generate_code ( & program, & cm) ;
514512
515- assert ! (
516- output_code. contains( "sql: ()=>`" ) ,
517- "Output code should contain arrow function for *.sql, got:\n {}" ,
518- output_code
519- ) ;
520- assert ! (
521- output_code. contains( "sql: (FILTER_GROUP, FILTER_PARAMS)=>`" ) ,
522- "Output code should contain `sql` arrow function with (FILTER_GROUP, FILTER_PARAMS), got:\n {}" ,
523- output_code
524- ) ;
525- assert ! (
526- output_code. contains( "measures: ()=>[" ) ,
527- "Output code should contain arrow function for preAggregations.measures, got:\n {}" ,
528- output_code
529- ) ;
530- assert ! (
531- output_code. contains( "dimensions: ()=>[" ) ,
532- "Output code should contain arrow function for preAggregations.dimensions, got:\n {}" ,
533- output_code
534- ) ;
535- assert ! (
536- output_code. contains( "timeDimension: ()=>" ) ,
537- "Output code should contain arrow function for preAggregations.timeDimension, got:\n {}" ,
538- output_code
539- ) ;
540- assert ! (
541- output_code. contains( "drillMembers: ()=>[" ) ,
542- "Output code should contain arrow function for measure.drillMembers, got:\n {}" ,
543- output_code
544- ) ;
545- assert ! (
546- output_code. contains( "sql: (CUBE)=>`${CUBE}.status = 'shipped'`" ) ,
547- "Output code should contain arrow function with CUBE as parameter for *.sql, got:\n {}" ,
548- output_code
549- ) ;
550- assert ! (
551- output_code. contains( "sql: (SQL_UTILS)=>SQL_UTILS.convertTz(`completed_at`)" ) ,
552- "Output code should contain arrow function with SQL_UTILS as parameter for *.sql, got:\n {}" ,
553- output_code
554- ) ;
555- assert ! (
556- output_code. contains( "if: ()=>`true`" ) ,
557- "Output code should contain arrow function for acl if condition, got:\n {}" ,
558- output_code
559- ) ;
560- assert ! (
561- output_code. contains( "member: (CUBE)=>`${CUBE}.id`" ) ,
562- "Output code should contain arrow function for acl rowlevel filters member, got:\n {}" ,
563- output_code
564- ) ;
565- assert ! (
566- output_code. contains( "values: ()=>[" ) ,
567- "Output code should contain arrow function for acl rowlevel filters values, got:\n {}" ,
568- output_code
569- ) ;
513+ assert_snapshot ! ( "complicated_transform_1st_stage" , output_code) ;
514+
570515 let diags = diagnostics. lock ( ) . unwrap ( ) ;
571516 assert ! (
572517 diags. is_empty( ) ,
@@ -877,67 +822,8 @@ fn test_complicated_transform_2nd_stage() {
877822
878823 let output_code = generate_code ( & program, & cm) ;
879824
880- assert ! (
881- output_code. contains( "sql: ()=>`" ) ,
882- "Output code should contain arrow function for *.sql, got:\n {}" ,
883- output_code
884- ) ;
885- assert ! (
886- output_code
887- . contains( "sql: (zero_sum)=>`CASE WHEN ${zero_sum} = 0 THEN 1 ELSE 1/${zero_sum} end`" ) ,
888- "Output code should contain arrow function for sql() with local member as param, got:\n {}" ,
889- output_code
890- ) ;
891- assert ! (
892- output_code. contains( "sql: (FILTER_GROUP, FILTER_PARAMS)=>`" ) ,
893- "Output code should contain `sql` arrow function with (FILTER_GROUP, FILTER_PARAMS), got:\n {}" ,
894- output_code
895- ) ;
896- assert ! (
897- output_code. contains( "measures: (count, rolling_count_month)=>[" ) ,
898- "Output code should contain arrow function for preAggregations.measures, got:\n {}" ,
899- output_code
900- ) ;
901- assert ! (
902- output_code. contains( "dimensions: (status)=>[" ) ,
903- "Output code should contain arrow function for preAggregations.dimensions, got:\n {}" ,
904- output_code
905- ) ;
906- assert ! (
907- output_code. contains( "timeDimension: (createdAt)=>createdAt" ) ,
908- "Output code should contain arrow function for preAggregations.timeDimension, got:\n {}" ,
909- output_code
910- ) ;
911- assert ! (
912- output_code. contains( "drillMembers: (id, createdAt)=>[" ) ,
913- "Output code should contain arrow function for measure.drillMembers, got:\n {}" ,
914- output_code
915- ) ;
916- assert ! (
917- output_code. contains( "sql: (CUBE)=>`${CUBE}.status = 'shipped'`" ) ,
918- "Output code should contain arrow function with CUBE as parameter for *.sql, got:\n {}" ,
919- output_code
920- ) ;
921- assert ! (
922- output_code. contains( "sql: (SQL_UTILS)=>SQL_UTILS.convertTz(`completed_at`)" ) ,
923- "Output code should contain arrow function with SQL_UTILS as parameter for *.sql, got:\n {}" ,
924- output_code
925- ) ;
926- assert ! (
927- output_code. contains( "if: ()=>`true`" ) ,
928- "Output code should contain arrow function for acl if condition, got:\n {}" ,
929- output_code
930- ) ;
931- assert ! (
932- output_code. contains( "member: (CUBE)=>`${CUBE}.id`" ) ,
933- "Output code should contain arrow function for acl rowlevel filters member, got:\n {}" ,
934- output_code
935- ) ;
936- assert ! (
937- output_code. contains( "values: ()=>[" ) ,
938- "Output code should contain arrow function for acl rowlevel filters values, got:\n {}" ,
939- output_code
940- ) ;
825+ assert_snapshot ! ( "complicated_transform_2nd_stage" , output_code) ;
826+
941827 let diags = diagnostics. lock ( ) . unwrap ( ) ;
942828 assert ! (
943829 diags. is_empty( ) ,
0 commit comments