# @specifai-net/appsync-template-tester

> Unit test AppSync VTL resolvers, with popular frameworks such as Jest

Latest version **1.1.9** (published 2022-01-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install @specifai-net/appsync-template-tester
pnpm add @specifai-net/appsync-template-tester
yarn add @specifai-net/appsync-template-tester
bun add @specifai-net/appsync-template-tester
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.1.9 |
| Published | 2022-01-02 |
| First published | 2022-01-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 206 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | jeroenmeulendijks |
| Keywords | appsync, aws, template, resolver, apache, velocity, vtl, unit, test, tester, jest, mocha, jasmine, velocityjs, compile, parse, util |

## Links

- npm: https://www.npmjs.com/package/@specifai-net/appsync-template-tester
- Repository: https://github.com/specifai-net/appsync-template-tester
- Homepage: https://github.com/specifai-net/appsync-template-tester#readme
- Issues: https://github.com/specifai-net/appsync-template-tester/issues
- npm.io page: https://npm.io/package/@specifai-net/appsync-template-tester

## Dependencies (3)

- [uuid](https://npm.io/package/uuid.md) ^8.3.2
- [velocityjs](https://npm.io/package/velocityjs.md) ^2.0.5
- [moment-timezone](https://npm.io/package/moment-timezone.md) ^0.5.34

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 1.1.9 (latest) — 2022-01-02
- 1.3.2 (master) — 2022-10-17
- 1.3.1 — 2022-10-17
- 1.3.0 — 2022-10-17
- 1.2.0 — 2022-01-02

## README

# appsync-template-tester

[![Built with
typescript](https://badgen.net/badge/icon/typescript?icon=typescript&label)](https://www.typescriptlang.org/)
[![version](https://badgen.net/npm/v/appsync-template-tester)](https://www.npmjs.com/package/appsync-template-tester)
![dependants](https://badgen.net/npm/dependents/appsync-template-tester) ![license](https://badgen.net/npm/license/appsync-template-tester)

Unit test AppSync VTL resolvers, with popular frameworks such as Jest.

## Use

### Example

```shell
yarn add appsync-template-tester --dev
```

```typescript
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 (note JSON becomes a JS object for ease of testing)
  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](https://docs.aws.amazon.com/appsync/latest/devguide/resolver-util-reference.html).

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

## Built by Skyhook

This module is contributed by the team at [Skyhook](https://www.skyhookadventure.com/).
And extended by [SpecifAI](https://specifai.net/) for internal use of testing AppSync, but it should be useable for everyone using AppSync and wants to test the VTL templates. We switched from [Amplify-appsync-simulator](https://github.com/aws-amplify/amplify-cli/tree/master/packages/amplify-appsync-simulator) to this package because the simulator needs more setting up, which is to extensive for just unittesting. The package from Skyhook lacked some support see (https://github.com/skyhookadventure/appsync-template-tester/issues/17) and therefore we added support by merging code based on (https://github.com/aws-amplify/amplify-cli/tree/master/packages/amplify-appsync-simulator/src/velocity)

---
_Source: https://npm.io/package/@specifai-net/appsync-template-tester · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
