- Getting Started
- Methods
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>')
})
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
More examples how to create tests and use Syncano Test library you can find in the Tests section of the Cookbook.
Installing from NPM
npm i @syncano/test --save
Name | Description |
---|---|
generateMeta | Generate radnom meta data |
run | Call socket locally |
response.is | Check if response match response from syncano.yml |
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})
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>')
})
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)
})