Skip to content

Latest commit

 

History

History
114 lines (85 loc) · 3.24 KB

readme.md

File metadata and controls

114 lines (85 loc) · 3.24 KB

Documentation

Getting Started

Usage

import {run, generateMeta} from '@syncano/test'
run('generate', {args, meta})
  .then(response => response.is('success'))
  .then(response => {
    assert.propertyVal(response, 'data', '<p>Hello, my name is John</p>')
  })

Test TypeScript endpoints

By default run function will execute file from syncano/<socket_name>/.dist/src. To execute file from syncano/<socket_name>/src set env variables:

# @default .dist/src
export SYNCANO_TEST_RUN_DIR=src
# @default js
export SYNCANO_TEST_RUN_EXT=ts

Learn more

More examples how to create tests and use Syncano Test library you can find in the Tests section of the Cookbook.

Installation

Installing from NPM

npm i @syncano/test --save

Methods

Name Description
generateMeta Generate radnom meta data
run Call socket locally
response.is Check if response match response from syncano.yml

generateMeta()

Generating random metadata. Usually you don't need to use this method and instead of it pass additional metadata keys to the run method. Those examples are equal:

run('generate', {args, meta: {newMetaKey: 'test value'}})
const meta = generateMeta()

meta.newMetaKey = 'test value'

run('generate', {args, meta})

run(endpointName, options?)

Type Name Default Description
string endpointName
object options {}
object options.args {} Parameters passed to endpoint
object options.meta {} Endpoint configuration
object options.config {} Socket configuration
run('generate', {args, meta})
  .then(response => {
    assert.propertyVal(response, 'data', '<p>Hello, my name is John</p>')
  })

response.is(responseName)

Type Name Default Description
string responseName Response name from syncano.yml

Check if the response is valid. This operation verifies response based on schema definition in socket.yml:

  • exit code
  • MIME type
  • arguments
run('search', {args: {post_code: '0161'}})
  .then(response => response.is('success'))
  .then(response => {
    assert.propertyVal(response.data, 'city', 'Oslo')
    assert.propertyVal(response.data, 'municipality', 'Oslo')
    assert.propertyVal(response.data, 'county', 'Oslo')
    assert.propertyVal(response.data, 'category', 'G')
    done()
  })
  .catch(err => {
    done(err)
  })