1.1.17 • Published 1 year ago

@gxxc/appsync-template-tester v1.1.17

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Appsync VTL Tester

Built with
typescript version downloads

Write unit tests for AWS AppSync VTL resolvers, with popular frameworks such as Jest.

Use

Example

yarn add appsync-template-tester --dev
import Parser from 'appsync-template-tester';
import { readFileSync } from 'fs';
import { join } from 'path';

// Load from a file (if not in a string already)
const templateFilePath = join(__dirname, './pathToFile.vtl');
const template = readFileSync(templateFilePath, {
  encoding: 'utf8',
});

// Create the resolver
const parser = new Parser(template);

test('Test the resolver', () => {
  // The Appsync Context (ctx) object
  const context = {
    // For example with a dynamoDB response resolver:
    result: {
      id: 'testId',
      // ...
    },
  };

  // parser.resolve() automatically typecasts
  const response = parser.resolve(context);

  // For convenience, the response is returned as a JS object rather than JSON
  expect(response.id).toBe('testId');
});

Util helpers supported

This module supports all the provided core, map & time \$util methods, and most of the dynamodb methods. The underlying methods can be seen in the Resolver Mapping Template Utility Reference docs.

Note: The errors list is also not returned (but \$util.error will throw an error).