confabulation

1.0.0 • Public • Published

Confabulation

pipeline status coverage report

Confabulation is a JavaScript test tool to assist with BDD / Cucumber for Amazon Alexa skills.

Help & support

Install

Confabulation is available as an npm module.

$ npm install confabulation

Dependencies

Confabulation depends on a local DynamoDB instance being present. It has been tested with both

This requires a modification to your skill's index.js.

const aws = require('aws-sdk');

// ...

exports.handler = function(event, context, callback) {
  const alexa = Alexa.handler(event, context);

  if (process.env.NODE_ENV === 'test') {
    alexa.dynamoDBClient = new aws.DynamoDB({
      endpoint: process.env.ENDPOINT_URL || 'http://localhost:8000/',
      accessKeyId: 'dynamo',
      region: 'test',
      secretAccessKey: 'secret',
    });
  }

  // ...
};

And a change to your package.json:

  "scripts": {
    "cucumber": "NODE_ENV=test cucumber-js"
  }

And changes to CI (E.G. .gitlab-ci.yml):

services:
  - name: dwmkerr/dynamodb
    alias: dynamodb

variables:
  ENDPOINT_URL: "http://dynamodb:8000/"

Usage

Setup

Create an endpoint in world.js:

const skill = require('../../index.js');
const { setWorldConstructor } = require('cucumber');
const { Endpoint } = require('confabulation');

class CustomWorld {
  constructor({attach, parameters}) {
    this.attach = attach;
    this.parameters = parameters;
    this.endpoint = new Endpoint()
      .withSkill(skill)
      .withApplicationId('<your-skill-id>')
      .withTableName('<your-table-name>')
      .withDbUrl(process.env.ENDPOINT_URL || 'http://localhost:8000/')
  }
}

setWorldConstructor(CustomWorld);

Invoking the skill

You can then add invocations in steps:

When('the user opens the skill', function(callback) {
  this.endpoint.say(new Intent('LaunchIntent'), callback);
}

Including passing in slot data:

When('the user says the number {int}', function(number, callback) {
  this.endpoint.say(new Intent('CountIntent').withSlot('count', number), callback);
});

When('the user says {word}', function(value, callback) {
  const value_id = value.toUpperCase();
  this.endpoint.say(new Intent('SelectListItemIntent').withSlot('list_item', value, value_id), callback);
});

Working with session data

You can set session data:

Given('the user has {int} items', function(value) {
  this.endpoint.setAttribute('item_count', value);
});

And check session data:

Then('the player should have {int} items', function(value) {
  expect(this.endpoint.getAttribute('item_count'))).to.equal(value);
});

Working with response data

You can check the response:

Then('the user should hear {string}', function(phrase) {
  expect(this.endpoint.response.response.outputSpeech.ssml).to.contain(phrase);
});

Credits

Portions of confabulation are copied/modified from Joan Gamell Farre's alexa-conversation module (as indicated in the source).

Readme

Keywords

Package Sidebar

Install

npm i confabulation

Weekly Downloads

1

Version

1.0.0

License

Apache-2.0

Unpacked Size

45.1 kB

Total Files

14

Last publish

Collaborators

  • dan.malec