Socket
Socket
Sign inDemoInstall

api-supertest

Package Overview
Dependencies
167
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 0.2.1

4

lib/index.js

@@ -26,2 +26,3 @@ "use strict";

json: joi.object().optional(),
result: joi.alternatives().optional().try(joi.func(), joi.string()),

@@ -40,3 +41,4 @@ maxRedirects: joi.number().integer().optional().default(10).min(0),

.without('patch', ['post', 'put', 'method', 'head'])
.without('head', ['post', 'put', 'patch', 'method']),
.without('head', ['post', 'put', 'patch', 'method'])
.xor('result', 'json'),
optionsDefinition = joi.object({

@@ -43,0 +45,0 @@ base: joi.string().regex(/$https?:\/\//),

{
"name": "api-supertest",
"version": "0.2.0",
"version": "0.2.1",
"description": "Beautiful test suite & runner for api tests.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -82,4 +82,8 @@ # API Supertest

path | Path to be loaded (eg. ```path: /test``` would result to ```http://github.com/api/test```)
priority | Optional number (default 1). Entries with higher priority will be executed first.
method | Optional http method, will default to get
context | (Object, optional) Data context to be used to resolve `${}` blocks (will be merged with the runtime context and during the derivision)
data | Data to be passed to a post/put/head/push request
requestHeader | (Object, optional) A set of headers to be when requesting the resource (will be merged during derive)
responseHeader | (Object, optional) A set of headers to check the response against (will be merged during derive)
push, put, post, head | Shortcuts to define a request as (eg.) post & with the given data (eg. ```post: "foo=bar&baz=boz"``` is the same as ```method: post``` and ```data: "foo=bar&baz=boz"```)

@@ -90,3 +94,4 @@ get | Adds a query string to the path. (replaces the query string if its already there). Add it without the leading "?": eg. ```foo=bar&baz=qux``` this will also set the method to ```get```.

maxRedirects | Number of redirects to follow. (default: none)
after | A function will be called before this test is run (syntax: [!!js/function](https://github.com/nodeca/js-yaml#user-content-supported-yaml-types))
before | A function will be called before this test is run (syntax: [!!js/function](https://github.com/nodeca/js-yaml#user-content-supported-yaml-types))
after | A function will be called after this test is run (syntax: [!!js/function](https://github.com/nodeca/js-yaml#user-content-supported-yaml-types))

@@ -121,2 +126,32 @@ Test can also contain a (recursive!) ```derive``` statement that allows you to specify multiple tests in a faster fashion:

## Context Variables
It is possible to use context variables in the definitions. The simplest example would look like:
```yaml
tests:
- path: ${my_var}
context:
my_var: /my_path
```
This, by itself, is not really useful but it can be helpful if you combine it with `after`, `json` and `priority`:
```yaml
tests:
- path: /user
json: !!type USER
priority: 2
after: !!js/function
function(item, global, cb) {
global.context.user_id = item.json.id;
cb();
}
- path: /avatar
get: id=${user_id}
```
The example above loads the user first (because of the higher priority). After the data was found it stores the result id in the global context's `user_id` field. Using the new context variable it is possible to load the avatar for a user.
## type.js

@@ -123,0 +158,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc