Skip to content

Commit

Permalink
Support to Find files relative to suites
Browse files Browse the repository at this point in the history
  • Loading branch information
kiranz committed Aug 1, 2018
1 parent 83c71b4 commit f5558f3
Show file tree
Hide file tree
Showing 24 changed files with 560 additions and 221 deletions.
76 changes: 40 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,73 +6,77 @@
[![Twitter](https://img.shields.io/twitter/follow/just_api_.svg?style=social&label=Follow)](https://twitter.com/intent/follow?screen_name=just_api_)


Just-API is a robust, specification based test framework for `REST`, `GraphQL` (or any HTTP-based) APIs. It runs on [node.js](http://nodejs.org/). Users can test APIs without writing code, or they can tap into code when they want to. It takes API test specification from YAML files and runs them either in serial or in parallel mode. Reports errors and test results in several formats including HTML and JSON.
Just-API is a declarative, specification based test framework for `REST`, `GraphQL` APIs. Users can test APIs without writing code, but they can also tap into code when they want to. It reads API test specification from YAML files and runs them in serial/parallel mode. Test reports can be generated in several formats including HTML and JSON.
<br>


In simple terms, users build a suite by providing a set of request and response validation specification in a YAML file. Each suite can contain one or more specs. Just-API builds the request, sends it to server and validates response as per the specification. You can choose to validate any or all of following
In simple terms, users build a test suite by providing a set of request and response validation specification in a YAML file. Each suite can have one or more specs. Just-API builds the request, sends it to server and validates response as per the specification.
One can choose to validate any or all of following

- Response Status code
- Response Headers
- Response JSON body
- Response JSON schema

_or Provide your own custom Javascript validator function_
_or Provide a custom Javascript function to validate the response_

[Find more](http://kiranz.github.io/just-api/)
Find more [here](http://kiranz.github.io/just-api/)
<br>

## Links

- **[Documentation](http://kiranz.github.io/just-api/)**
- [Gitter Chatroom](https://gitter.im/just-api/Lobby) (ask questions here!)
- [Documentation](http://kiranz.github.io/just-api/)
- [Gitter Chatroom](https://gitter.im/just-api/Lobby)
- [Google Group](https://groups.google.com/forum/#!forum/just-api)
- [Issue Tracker](https://github.com/kiranz/just-api/issues)

## Features

- Runs test suites in parallel/serial mode
- Supports all widely used HTTP methods
- Supports Form, Multipart requests, File uploads
- Response Validation (Headers, Status code, JSON body, JSON schema, Custom Response Validation function)
- Runs imported custom functions from modules
- Custom inline and module Javascript sync/async functions
- Hooks (Before all, After all, Before each, After each, Before test, After test)
- Supports x-www-form-urlencoded requests, Multipart requests, File uploads
- Built-in Response Validation Constructs(Headers, Status code, JSON body, JSON schema)
- Custom Response validator functions
- Supports running custom inline or module javascript sync/async functions
- Supports Hooks (Before All, After All, Before Each, After Each, Before Test, After Test)
- Custom suite configuration
- Chained Request flows
- Ability to define/override Request path, query params, path params, headers, body at runtime
- Storing suite & test data in context for reuse
- Importing specs from multiple suites
- Intrasuite and Intersuite spec dependency execution
- Define/override Request path, query params, path params, headers, body at runtime
- Suite and test context for reuse
- Supports importing specs from one or more test suites
- Intrasuite and Intersuite spec dependencies
- Reusing test specification
- Retry failed tests
- Looping: Generate 'n' number of tests with a list
- Built-in HTML, JSON reporters
- Ability to generate reports in multiple formats for the same run
- Can generate reports in multiple formats for the same run
- Logging HTTP request/response data for failed tests
- Proper error reporting
- Runs only tests matching with a given pattern/string
- Can run tests matching with a given pattern/string
- Skipping tests with specification
- Disable or Enable redirections
- Reports test duration
- Allows user to plug-in custom reporters

[Find out all features](https://kiranz.github.io/just-api/features/)
[See all features](https://kiranz.github.io/just-api/features/)


## Getting Started

Following is a simple example showing usage of Just-API.

>To run just-api, you will need Node.js v7.10.0 or newer.
### Installation
```sh
$ npm install just-api
```

Following is a simple example showing usage of Just-API.

```sh
$ mkdir specs
$ $EDITOR specs/starwars_service.yml # or open with your preferred editor
$ vim specs/starwars_service.yml
```

In your editor
Write following suite in your editor

```yaml
meta:
Expand All @@ -82,7 +86,7 @@ configuration:
host: swapi.co
base_path: /api
specs:
- name: get "Luke Skywalker" info
- name: get Luke Skywalker info
request:
path: /people/1/
method: get
Expand All @@ -101,20 +105,20 @@ Back in the terminal
```sh
$ ./node_modules/.bin/just-api

✓ get Luke Skywalker info (1516ms)
✓ get Luke Skywalker info (1216ms)

Done: specs/suite.yml (Passed)
Done: specs/starwars_service.yml (Passed)

0 skipped, 0 failed, 1 passed (1 tests)
0 skipped, 0 failed, 1 passed (1 suites)
Duration: 1.6s
Duration: 1.3s
```
### Testing GraphQL APIs
Following example tests a GraphQL API that returns location for a given ip address.
Create the yaml suite file and run just-api.
Create a YAML suite and run just-api.
```yaml
meta:
Expand All @@ -123,7 +127,7 @@ configuration:
host: api.graphloc.com
scheme: https
specs:
- name: Get Location of a an ip address
- name: Get Location of a given ip address
request:
method: post
path: /graphql
Expand All @@ -148,16 +152,15 @@ specs:
status_code: 200
json_data:
- path: $.data.getLocation.country.iso_code
value: "US"

value: US
```
### A chained request flow with hook and custom validation
When you need to test complex chained API flows, you can run dependencies in hooks to fetch prerequisite data
When you need to test complex chained API flows, run dependencies in hooks to fetch pre-requisite data
and pass it to actual test.
Following example shows how to get data from dependencies with hooks and using custom validator functions to validate the response.
Following example shows how to run dependencies using a hook, get data and validating response with a custom validator function.
```yaml
meta:
Expand Down Expand Up @@ -204,9 +207,10 @@ specs:
throw new Error('R2-D2 not returned in search results');
}
```
Note that you can also place your custom JS functions in separate JS file and specify the function name in YAML to import.
You can do much more advanced stuff with Just-API. Our documentation says it all.
Note: You can also place custom JS functions in a module and specify the function name, module path in YAML to import.
More advanced stuff can be done with Just-API. Documentation says it all.
Take a look at [Just-API Website](http://kiranz.github.io/just-api/) for detailed documentation.
If you are looking to use Docker to run Just-API, you might want to checkout
Expand All @@ -218,7 +222,7 @@ Kiran kiran.6d.hex@gmail.com
## License
Just-API is [MIT-licensed](https://github.com/kiranz/just-api/blob/master/LICENSE)
[MIT-licensed](https://github.com/kiranz/just-api/blob/master/LICENSE)
## References
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ Usage: just-api [options] [files]
Options:
-V, --version output the version number
-V, --version outputs the version number
--parallel <integer> specify the number of suites to be run in parallel
--reporter <reporternames> specify the reporters to use, comma separated list e.g json,html
--reporter-options <k=v,k2=v2,...> reporter-specific options
--grep <pattern> only run tests matching <pattern>
--grep <pattern> only run tests matching <pattern/string>
--recursive include sub directories when searching for suites
--reporters display available reporters
-h, --help output usage information
-h, --help outputs usage information
```
32 changes: 19 additions & 13 deletions docs/docs/basic-concepts.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
# Basic Concepts

This section covers some high level basic concepts that are important to understand for day to day Just-API usage. We highly recommend that you read this
page before proceeding to use Just-API.
This section covers some high level basic concepts that are important to understand for day to day Just-API usage. We highly recommend that you read this page before proceeding to use Just-API.

## The High-level View

Just-API is a framework that you can use to run HTTP based API tests.
Just-API's main purpose is to test HTTP-based APIs without code, and make API testing easy, free and fast for everyone.

You write your API test specification and tell Just-API to run them. API test specifications are written in YAML and we call each YAML file a test suite, with the option to write Javascript (using any `npm` module if needed) to write custom logic.

Just-API's main purpose is to test HTTP based APIs without code, and make API testing easy, free and fast for everyone.

Just-API is written with parallelism as priority while running suites, so your test execution takes as less time as possible.
Write your API test specification and tell Just-API to run them. API test specification is written in YAML and we call each YAML file a test suite, with the option to write Javascript (using any `npm` module if needed) to implement custom logic.

Just-API is written with parallelism as high priority when running test suites, so your test execution takes as less time as possible.

## Putting a test suite together ##

Expand All @@ -22,16 +18,27 @@ And optional sections `hooks` and `spec_dependencies` (you can find more about t

### The `meta` Section ###

This is where you specify `name` for the suite and other suite related metadata.
Specify following suite attributes in this section

- `name` (_required attribute_)
- `locate_files_relative` (_optional attribute_)

*name*[String]: Give a name that describes the suite (e.g: like a microservice name)

*locate_files_relative*[Boolean]: Tells Just-API if file paths provided in the suite are relative to suite path or not. If false, Just-API will try to find files relative to Node process's current working directory.
If true, Just-API will try to find files relative to the suite's path.
Default value is false.

Note: This attribute value applies to every file path you provide in a suite.

### The `configuration` Section ###

You can use `configuration` section to specify API's host, scheme, port etc. you can also provide a custom Javascript function to `custom_configuration` key, so it's easy to
You can use `configuration` section to specify API's host, protocol, port etc. You can also provide a custom Javascript function to `custom_configuration` attribute, so it's easy to
dynamically configure your suite at runtime.

### The `specs` Section ###

`specs` section is a list of tests. Each test contains name, request, response validation specification etc.
`specs` section is a list of tests. Each test contains name, request, response validation specification, and a few other additional attributes.

### An Example Suite ###

Expand Down Expand Up @@ -68,11 +75,10 @@ specs:
status_code: 200
```
**Next:**
- See the full set of features available in [Features](features).
- Learn about **reports** in [Reporters](reporters).
- Learn about **reporters** in [Reporters](reporters).
2 changes: 1 addition & 1 deletion docs/docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Just-API itself is filled with lots of tests covering all supported features.

Please checkout test suites available [here](https://github.com/kiranz/just-api/tree/master/test/cli/src/suites)

Test suites available there should be able to help you build tests for your APIs.
Test suites available there should be able to help you write tests for your APIs.
Loading

0 comments on commit f5558f3

Please sign in to comment.