Git Product home page Git Product logo

Comments (13)

brucek avatar brucek commented on June 26, 2024

FWIW I was following the instructions here to set up VTL unit testing:
https://mechanicalrock.github.io/2020/04/27/ensuring-resolvers-aren't-rejected.html

I have not yet tried another option I stumbled on:
https://github.com/skyhookadventure/appsync-template-tester

from velocity.js.

shepherdwind avatar shepherdwind commented on June 26, 2024

Can you provide the basic logic code of the function createVtlContext . I need that function to run you test code.

from velocity.js.

brucek avatar brucek commented on June 26, 2024

Can you provide the basic logic code of the function createVtlContext . I need that function to run you test code.

sorry, forgot about that:

function createVtlContext(args) {
  const util = utils.create([], new Date(Date.now()), Object())
  const context = {
    args,
    arguments: args
  }
  return {
    util,
    utils: util,
    ctx: context,
    context
  }
}

from velocity.js.

shepherdwind avatar shepherdwind commented on June 26, 2024

utils.create is missing.

from velocity.js.

brucek avatar brucek commented on June 26, 2024

Not sure what you mean exactly @shepherdwind:

function createVtlContext(args) {
  const util = utils.create([], new Date(Date.now()), Object()) ## calling utils.create here
  [...]

In tests with other templates (ie, try the below), parsing and rendering works fine:

const ast = parse(`
  #set( $keyFields = ["id"] )
`);

from velocity.js.

shepherdwind avatar shepherdwind commented on June 26, 2024

I need the code of utils.create, I need it to run the code you provide.I need complete, repeatable code to reproduce the problem.

from velocity.js.

brucek avatar brucek commented on June 26, 2024

I need the code of utils.create

Sorry; my misunderstanding. I am using utils from the AWS amplify-appsync-simulator

As I mentioned, I am just following the code template from https://mechanicalrock.github.io/2020/04/27/ensuring-resolvers-aren't-rejected.html

Thanks for your patience 🙏

from velocity.js.

brucek avatar brucek commented on June 26, 2024

@shepherdwind Random Q: what is this line doing?

if (typeof index === 'number') {

as far as I can tell, this will never be true, and so the first branch will never execute

Also, the current test suite never executes it as well

Not sure if related to this issue, but just discovered it while investigating

from velocity.js.

shepherdwind avatar shepherdwind commented on June 26, 2024

@shepherdwind Random Q: what is this line doing?

if (typeof index === 'number') {

as far as I can tell, this will never be true, and so the first branch will never execute

Also, the current test suite never executes it as well

Not sure if related to this issue, but just discovered it while investigating

The code was submitted by others #124 , I did not look closely at the specific implementation at the time, and just tried it does not run to this branch.

Also,Did the #141 pr fix the bug you mentioned here with that commit? I'll publish a new version directly, and then I will find time to refactor this repository code later, it's a bit too old.

from velocity.js.

shepherdwind avatar shepherdwind commented on June 26, 2024

I am sorry I don't know about AWS amplify-appsync-simulator very much, I have never touched this tool before . A pr with test code would be more useful, and it would be perfect if it included test pass code.

from velocity.js.

brucek avatar brucek commented on June 26, 2024

So the #141 pr fixed a related issue which is that the error output was itself erroring and gave unusable output.

I'm still not yet sure what is the root cause of the original issue

Possibly related to this? serverless-appsync/serverless-appsync-simulator#106

from velocity.js.

shepherdwind avatar shepherdwind commented on June 26, 2024

I know what the problem is, I optimized the exception stack display, and now the exceptions look like this.

     TypeError: map.keySet is not a function on $util.map.copyAndRemoveAllKeys($ctx.args.input,$keyFields).entrySet() at L/N 3:6
      at Object.copyAndRemoveAllKeys (node_modules/[email protected]@amplify-appsync-simulator/lib/velocity/util/map-utils.js:34:14)
      at Velocity.getPropMethod (src/compile/references.js:315:23)
      at Velocity.getAttributes (src/compile/references.js:188:20)

And the code of amplify-appsync-simulator/lib/velocity/util/map-utils.js:34:14 like this

    copyAndRemoveAllKeys: function (map, keys) {
        var keysStr = keys.toJSON();
        var result = map
            .keySet()
            .toJSON()

So the root cause of this issue is the map do not have the keySet methods. I publish a new beta version, so you can try the beta version on your local machine.

There are two ways to solve this problem, first wrap the input to an map, for example

const args = {
input: mapper.map({
id: '000',
timestamp: '2021-12-01T08:00:00.000Z',
})
}

The second one, maybe the complier option valueMapper should map every value, now the valueMapper only handle #set condiction.

from velocity.js.

shepherdwind avatar shepherdwind commented on June 26, 2024

new version 2.0.5 published

from velocity.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.