testapi6
TypeScript icon, indicating that this package has built-in type declarations

1.2.89 • Public • Published

testapi6

Utility tools for dev which run base on scenario yaml files

Features

  1. Test APIs base on scenario files *.yaml
  2. Validate data after each steps
  3. Re-use variable after each steps
  4. Split a huge testcase to many small testcases which make easy to test in a big project
  5. Easy to extends, customize for specific project
  6. Load external modules (mysql, postgreSQL, mongo, redis, grpc, rabbitmq...) or create tags by yourself
  7. Support run benchmark via wrk
  8. Auto generate sequence diagram from any file base on comment

Practice

Installation

Visual code

  • Install extension doanthuanthanh88.testapi6

CLI

# install via npm
npm install -g testapi6
# install via yarn
yarn global add testapi6 --prefix /usr/local

Docker

  docker pull doanthuanthanh88/testapi6

How to run

Visual code extension

  1. Create a scenario files *.yaml
  2. Open the scenario file
  3. Press ctr+shift+t or cmd+opt+t

CLI

  testapi6 ${PATH_TO_SCENARIO_FILE}

Docker

  1. Run with local scenario files
  docker run --rm \
    -v $PWD/scenario_file.yaml:/test/index.yaml \
    -e {var_name_1}={value} \
    -e URL=http://urlhere... \
    doanthuanthanh88/testapi6
  1. Run with http scenario files
  docker run --rm \
    -e {var_name_1}={value} \
    -e URL=http://urlhere... \
    doanthuanthanh88/testapi6 \
    http://.../scenario_file.yaml
  1. Run with scenario encrypted files which need a password to decrypted before run
  docker run --rm \
    -v $PWD/scenario_file.yaml.encrypt:/test/index.yaml.encrypt \
    -e {var_name_1}={value} \
    -e URL=http://urlhere... \
    doanthuanthanh88/testapi6 \
    http://.../scenario_file.yaml \
    $PASSWORD
  1. Run with some external modules
  docker run --rm \
  -v $PWD/test/examples/mock_data.yaml:/test/index.yaml \
  -e MODULES="testapi6-mockapi testapi6-sql" \
  doanthuanthanh88/testapi6

The environment variables always override all of vars in Testcase file

Scenario file example

title:                      # Document title
description:                # Document description
developer: email@gmail.com  # Author
version: 1.0.0              # Document version
servers:                    # Example server in document
  production: https://prod.abc.vn/my-service/v1.0
  staging: https://staging.abc.vn/my-service/v1.0
  development: http://localhost:3001
# debug: true
vars:                               # Declare global variables
  url: http://0.0.0.0:3001
templates:                          # Declare templates which not run
  # Make request
  - Api:
  - Get:
  - Post:
  - Put:
  - Patch:
  - Delete:
  - Head:
  - Group:
steps:
  # Make request
  - Api:            # REST API
  - Get:            # API GET method
  - Delete:         # API DELETE method
  - Head:           # API HEAD method
  - Post:           # API POST method
  - Put:            # API PUT method
  - Patch:          # API PATCH method
  # Print
  - Echo:           # Print data
  - Schema:         # Print object schema
  # Logic
  - Script:         # Inject javascript in scenario
  - Vars:           # Declare global variables
  - Regex:          # Handle regex string
  # Validate
  - Validate:       # Validate logic
  - Validator:      # Create a new validator
  # Common
  - Pause:          # Pause or delay calls
  - Import:         # Import files
  - Load:           # Load data file then assign the value to a variable
  - Require:        # Load external module or embed code to create a new tags
  - Group:          # Group steps to manage
  - Exec:           # Execute external command
  - Utils:          # Utility functions
  - Define:         # Declare new Utils/Validate/Vars
  - Input:          # Get user input keyboard
  - OutputFile:     # Save data to file
  - DocSwagger:     # Save to swagger document
  - DocMarkdown:    # Save to markdown document
  - DocSequence:    # Generate to sequence diagram base on comments in code
  ...

Support some tags

!remove             # Remove item array when merge 
!keep               # Not override item in array when merge
!erase              # Delete field in object or item in array
!upload             # Incase upload file

Examples

Package Sidebar

Install

npm i testapi6

Weekly Downloads

214

Version

1.2.89

License

MIT

Unpacked Size

1.86 MB

Total Files

191

Last publish

Collaborators

  • doanthuanthanh88