1.0.1 β€’ Published 4 years ago

@danilo_pereira/pipe-test v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

About

Execute endpoint tests with a simple JSON file.

Pipe-test is an automatic testing solution for REST APIs, easy to configure and easy to use.

Installation

Use your favorite JavaScript package manager!

$ npm install @danilo_pereira/pipe-test

$ yarn add @danilo_pereira/pipe-test

Dependencies

Likewise, the p-iteration dependency must be installed manually for the project to work.

$ npm install p-iteration

$ yarn add p-iteration

Usage

After installed, the pipe-test command will be available. The command accepts 2 arguments, both of which must be valid JSON files:

  1. The pipeline file
  2. The configuration file (optional)
pipe-test pipeline.json options.json

If no configuration file is provided, the default configuration will be used.

Output

Upon each execution, 2 output files are generated on the configured output path: 1. A JSON file

The JSON output is only generated at the end of the pipeline execution - it contains every stage's information and its respective result, SUCCESS or FAIL.

  1. A log file

The log file is updated real-time during the pipeline execution, and includes extra information such as the complete request with all global values replaced and the request return information, with timestamps. This file should be the most important for debugging in case of request failure.

πŸ”© The pipeline

The pipeline consists of a JSON file with a single array that contains the test objects, and each object represents a stage in the test pipeline.

If a test passes, the pipeline sleeps for the configured delay time before starting the next stage. In case of a test failure, the pipeline stops execution.

Below is a table description of each valid object property and how it works.

AttributeRequirementDefaultOptionsDescription
descriptionoptional--String field that describes the test, meant for organizational and understanding purposes
typeat least one SET_GLOBAL required in the pipelineCRUDSET_GLOBAL, CRUDSET_GLOBAL β‡’ Overwrites the global variable, mandatory at the beginning of the pipeline to set the base URL, header configurations and any initial global values CRUD β‡’ Default value, used to indicate a REST request
requestrequired--Request object, structured as shown here
resultrequired--Object with allow and deny integer array properties that define the valid response statuses for the test to be considered a success or a fail.While allow is always required, deny is also required, except in the case of the asterisk operator (*) in allow. See the correct structure here
funcsoptional--Array of strings that contain JavaScript code that will be executed in an eval function if the test passes. Useful for manipulating the global variable, e.g. adding a new field with the request's result data to be used in a later request. See an example
variablesexclusive to SET_GLOBAL, optional but highly recommended--Object that overwrites the global variable, with a baseUrl property used to define the base URL used for every request on the pipeline. If no baseUrl is provided, all individual request paths will need to contain the complete URL

🌎 Global variables

A global variable is available to use throughout the pipeline, to facilitate the use of common values in multiple requests, such as an ID. The global variable consists of a JavaScript object with any properties, each property being a global value in it of itself:

const global = {
  name: "Lorem Ipsum",
  age: 40,
}

In order to access these values in the pipeline, you must use $global.<property> e.g. $global.name.

Only the following pipeline properties able to replace global values: path, config and data.

πŸ—οΈ Object structures

Request

AttributeRequirementOptionsDescription
typerequiredGET, POST, PUT, DELETE, PATHThe HTTP request method, in all caps
pathrequired-Request path that will append to the base URL, e.g. with a baseURL of http://localhost:3000/api and a path /user/data, the full request will be to http://localhost:3000/api/user/data
configoptionalObject with any valid HTTP header fieldSets request-specific configuration, such as authentication or encoding
dataoptional-The body of data sent to the request, may be of type object, array or string
"request": {
  "type": "GET",
  "path": "/user/$global.user_id",
  "config": {
    "headers": {
      "Authorization": "$global.user_token"
    }
  }
}

Result

"result": {
  "allow": [
    200,
    404
  ],
  "deny": [
    "*"
  ]
}
"result": {
  "allow": [
    "*"
  ]
}

Funcs

"funcs": [
  "global = {...global, user_data: response.data};"
]

πŸ“Œ Pipeline example

Another example can also be found in the example folder of the project.

[
  {
    "description": "Define global variables and destination URL",
    "type": "SET_GLOBAL",
    "variables": {
      "baseUrl": "http://your-url/api",
      "config": {
        "headers": {
          "Content-Type": "application/json; charset=utf-8"
        }
      },
      "user_id": "abc",
      "user_email": "user123@test.com",
      "user_password": "12345"
    }
  },
  {
    "description": "Perform user login",
    "type": "CRUD", // Can be removed as it's the default value
    "request": {
      "type": "POST",
      "path": "/login/$global.user_id",
      "data": {
        "username": "$global.user_email",
        "password": "$global.user_password"
      }
    },
    "result": {
      "allow": [
        200,
        404
      ],
      "deny": [
        "*"
      ]
    },
    "funcs": [
      "if (response.status === 200) global = {...global, user_token: response.data};"
    ]
  }
 ]

βš™οΈ Custom configuration

The configuration file is a simple JSON with the following properties: | Attribute | Options | Description | |-----------|---------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | delay | - | Milliseconds to wait between the execution of each individual test (number data type, not string) | | path | - | By default, the output files are generated in the same directory where the command was executed. Therefore, use this property if you would like to change the output path. If the provided output directory does not exist, it will be created Note: In order for the files to be created correctly in the desired directory, you must add a forward slash at the end of the path, e.g. ./output/ instead of ./output | | name_mode | BY_DATE, CUSTOM | BY_DATE β‡’ Default value, saves both JSON and log output files with the ISO 8601 datetime format i.e. "YYYY-MM-DDThh:mm:ss", e.g 2021-06-22T14:00:00.json. Because of this, this option creates 2 new output files on each execution CRUD β‡’ Saves output files with a custom name, provided by the name property. With this option, the log file appends new content and the JSON file is overwritten on each new execution | | name | - | Custom output file name (the same name will be used for both JSON and log files) Note: This name will only be considered if name_mode is CUSTOM |

πŸ“Œ Example

{
  "delay": 1500,
  "path": "./tests/output/",
  "name_mode": "BY_DATE"
}

Authors

License

This project is under the GNU General Public License.


Made by LetΓ­cia Vigna.

1.0.1

4 years ago

1.0.0

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago