expr-js-story Pub Share

These are tested separately, for performance testing reasons

simple scripting

send::  msg test.util.todayjs 

expect::  (payload ~= "....-..-..")

send::  msg test.util.addMonths  (mths:Number=1)

expect::  (payload ~= "....-..-..")

send::  msg ctx.set  (payload)

expect::  (payload contains "UTC")$ifc:: NOT (diesel[="isLocaldevbox"])
expect::  (payload is Exception)$ifc:: diesel[="isLocaldevbox"]

The diesel object:

send::  msg ctx.set  (res5)

expect::  (res5 not empty)

send::  msg ctx.set  (res139)

expect::  (res139 not empty)

The wix object:

send::  msg ctx.set  (res144)

expect::  (res144 not empty)

Javascript and regex

These are not used: send::  msg ctx.set  (a:Number=1, b:Number=2)

The input parameters overwrite context above send::  msg expr.js.sum1  (a:Number=1, b:Number=2)

expect::  (res39 is 3)

send::  msg expr.js.sum2  (a:Number=1, b:Number=2)

expect::  (res42 is 3.0)

send::  msg expr.js.name1  (email="jane@doe.com")

expect::  (res40 is "jane")

/$send ctx.setVal (name="cart", value={})

send::  msg expr.js.validateEmail  (email="jane@doe.com")

expect::  (ok25 is true)

send::  msg ctx.set  (ok25:Boolean)

send::  msg expr.js.validateEmail  (email="janedoe.com")

expect::  (ok25 is false)

Javascript expressions

Simple javascript - script is independent (no arguments):

send::  msg ctx.set  (a225)

expect::  (a225 is 5)

Escaping quotes with javascript regex (notice a230 available inside the js expression):

val a230="{"a":32}"="{"a":32}" send::  msg ctx.set  (a231)

expect::  (a231 is "{"a":32}")

More JS examples:

send::  msg ctx.set  (now)

send::  msg ctx.set  (later)

send::  msg ctx.set  (later)

send::  msg ctx.set  (noweh, later)

expect::  (now is number)

JS as lambdas

send::  msg ctx.set  (res57="1 2 3 ")

Convert to string and use a JS expression for filter lambda send::  msg ctx.set  (a298 :Array)

send::  msg ctx.echo  (res299)

expect::  (res299 is ["1"])


Was this useful?    

By: Razie | 2020-01-10 .. 2022-03-17 | Tags: story , dsl , sanity


Viewed 861 times ( | History | Print ) this page.

You need to log in to post a comment!

© Copyright DieselApps, 2012-2024, all rights reserved.