为了为我的 AppSync 解析器编写单元测试,我使用 VelocityJS 包来解析我的 sam 模板中的 VTL。但是,VTL 模板没有被完全解析。
该代码在 AWS 上运行良好,是单元测试出错。 https://github.com/shepherdwind/velocity.js
#if($util.isNullOrBlank($ctx.result.themePreferences))
#set($themePreverences = {})
$util.qr($themePreverences.put("darkMode", "DEFAULT"))
$util.qr($ctx.result.put("themePreferences", $themePreverences))
#end
$util.toJson($ctx.result)
当使用let result = Velocity.parse(template, ctx);
结果是字符串"$util.toJson($ctx.result)"
而不是 JSON 值时$ctx.result
。
IE:
{ "themePreferences": { "darkMode": "DEFAULT" } }