All Projects → dareid → Chakram

dareid / Chakram

Licence: mit
REST API test framework. BDD and exploits promises

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Chakram

Mocha
☕️ simple, flexible, fun javascript test framework for node.js & the browser
Stars: ✭ 20,986 (+2201.1%)
Mutual labels:  test, mocha, bdd
Node Express Mongodb Jwt Rest Api Skeleton
This is a basic API REST skeleton written on JavaScript using async/await. Great for building a starter web API for your front-end (Android, iOS, Vue, react, angular, or anything that can consume an API). Demo of frontend in VueJS here: https://github.com/davellanedam/vue-skeleton-mvp
Stars: ✭ 603 (-33.88%)
Mutual labels:  rest, mocha, chai
Enzyme
JavaScript Testing utilities for React
Stars: ✭ 19,781 (+2068.97%)
Mutual labels:  test, mocha, chai
Should Enzyme
Useful functions for testing React Components with Enzyme.
Stars: ✭ 41 (-95.5%)
Mutual labels:  test, mocha, bdd
Javascript Testing Best Practices
📗🌐 🚢 Comprehensive and exhaustive JavaScript & Node.js testing best practices (August 2021)
Stars: ✭ 13,976 (+1432.46%)
Mutual labels:  test, mocha, chai
Postman Bdd
A BDD test framework for Postman and Newman
Stars: ✭ 139 (-84.76%)
Mutual labels:  rest, bdd, chai
Snap Shot It
Smarter snapshot utility for Mocha and BDD test runners + data-driven testing!
Stars: ✭ 138 (-84.87%)
Mutual labels:  test, mocha, bdd
chai-exclude
Exclude keys to compare from a deep equal operation with chai expect or assert.
Stars: ✭ 33 (-96.38%)
Mutual labels:  mocha, bdd, chai
Baretest
An extremely fast and simple JavaScript test runner.
Stars: ✭ 364 (-60.09%)
Mutual labels:  mocha, bdd
Shellspec
A full-featured BDD unit testing framework for bash, ksh, zsh, dash and all POSIX shells
Stars: ✭ 375 (-58.88%)
Mutual labels:  test, bdd
Vue Skeleton Mvp
VueJs, Vuetify, Vue Router and Vuex skeleton MVP written on JavaScript using async/await built to work with API REST skeleton: https://github.com/davellanedam/node-express-mongodb-jwt-rest-api-skeleton
Stars: ✭ 406 (-55.48%)
Mutual labels:  mocha, chai
Fakerest
Patch fetch/XMLHttpRequest to fake a REST API server in the browser, based on JSON data.
Stars: ✭ 350 (-61.62%)
Mutual labels:  rest, test
Ginkgo
BDD Testing Framework for Go
Stars: ✭ 5,346 (+486.18%)
Mutual labels:  test, bdd
React Progressive Web App
An opinionated React based repository which is optimized for Progressive Web App development.
Stars: ✭ 548 (-39.91%)
Mutual labels:  mocha, chai
Rest Assured
Java DSL for easy testing of REST services
Stars: ✭ 5,646 (+519.08%)
Mutual labels:  rest, test
Stubb
Specify REST API stubs using your file system.
Stars: ✭ 289 (-68.31%)
Mutual labels:  rest, test
nodejs-application-architecture
👨‍🔧 A discussion on how Node.js projects can be organized.
Stars: ✭ 81 (-91.12%)
Mutual labels:  mocha, chai
Jest Codemods
Codemods for migrating to Jest https://github.com/facebook/jest 👾
Stars: ✭ 731 (-19.85%)
Mutual labels:  mocha, chai
Specs2
Software Specifications for Scala
Stars: ✭ 696 (-23.68%)
Mutual labels:  test, bdd
Webdriverio
Next-gen browser and mobile automation test framework for Node.js
Stars: ✭ 7,214 (+691.01%)
Mutual labels:  test, mocha

Chakram

Build Status Test Coverage Code Climate Gitter

Chakram is no longer actively maintained, PRs are welcomed

Chakram is an API testing framework designed to perform end to end tests on JSON REST endpoints.

The library offers a BDD testing style and fully exploits javascript promises - the resulting tests are simple, clear and expressive. Chakram is built on node.js, mocha, chai and request.

This readme offers an introduction to the library. For more information, visit Chakram's documentation and tests which demonstrate all of Chakram's capabilities. In addition, example tests of publicly accessible APIs are available in the examples directory. If required, assistance can be found in the project's gitter chat room.

Features

  • HTTP specific assertions. Allows testing of:
    • Status codes
    • Cookie presence and value
    • Header presence and value
    • JSON values
    • JSON structure (using the JSON schema specification)
    • Compression
    • Response times
  • BDD formatting and hooks (e.g. beforeEach, afterEach)
  • Promise based
  • Plugin support
  • Custom assertions
  • Exports results in a variety of formats
  • Debugging support

Plugins

Awesome plugins from the community:

We would love to see more plugins! If you have a plugin, please add it to the list.

Getting Started

Install Chakram

Chakram requires Node.js and npm to be installed. It is available as an npm module. Ideally, Chakram should be added to your testing project's devDependencies. This can be achieved with the following command:

npm install chakram --save-dev

Writing Tests

Chakram builds on top of the mocha testing framework. As such, the tests follow mocha's BDD style. The following sections introduce the various aspects of writing a Chakram test.

Making Requests

Chakram makes use of the request library and as such boasts a comprehensive request capability. Chakram exposes helper methods for the most common HTTP request verbs. The methods typically require the URL as the first parameter, the request body (if applicable) as the second parameter and any request options as an optional last parameter. For full documentation of the request methods see here. The request methods return a promise which resolves to a Chakram response object.

Below is an example of making a HTTP GET request:

var chakram = require('chakram');

describe("Chakram", function() {
    it("should offer simple HTTP request capabilities", function () {
        return chakram.get("http://httpbin.org/get");
    });
});

Testing Responses

Chakram offers a range of HTTP specific assertions which can test the information returned from API requests. Chakram offers a BDD testing style through Chakram's expect interface.

When testing API responses, pass the request promise as an argument into chakram.expect. This will return an object which exposes the Chakram and Chai assertions. Perform an assertion by calling the desired Chakram assertion method. Chai properties can be used as a prefix to the assertion, improving the test's readability.

The assertion is performed once the response is received (i.e. the request promise is fulfilled). Chakram assertions return a promise which resolve to a Chakram response object once the test has been performed.

Below is an example of testing the status code of a HTTP GET request:

var chakram = require('chakram'),
    expect = chakram.expect;

describe("Chakram", function() {
    it("should provide HTTP specific assertions", function () {
        var response = chakram.get("http://httpbin.org/get");
        return expect(response).to.have.status(200);
    });
});

In addition to the HTTP specific assertions, chakram.expect exposes all of Chai's BDD properties and methods. Documentation for the HTTP specific assertions can be seen here.

Waiting

As this library focuses on testing REST APIs, the tests are naturally asynchronous. Mocha has native support for promises, which Chakram exploits. Returning a promise from an it callback will cause the test to wait until the promise resolves before continuing. Chakram's requests and expectations return promises which fulfill to Chakram response objects. These promises can be returned to ensure the test waits for them to complete (as can be seen in the previous two examples).

It is important that tests wait for all requests and assertions to be completed. To help, chakram includes a wait method. This returns a promise which will be fulfilled once all assertions have been performed. Furthermore, Chakram will fail any tests which do not wait for assertions to complete. Below is a test using the wait method.

var chakram = require('chakram'),
    expect = chakram.expect;

describe("Chakram", function() {
    it("should provide a simple async testing framework", function () {
        var response = chakram.get("http://httpbin.org/get");
        expect(response).to.have.status(200);
        expect(response).not.to.have.header('non-existing-header');
        return chakram.wait();
    });
});

Complex Promise Use

Due to the use of promises, complex tests can be written requiring chains of requests and assertions. An example can be seen below:

describe("Chakram", function () {
  it("should support sequential API interaction", function () {
    var artist = "Notorious B.I.G.";
    return chakram.get("https://api.spotify.com/v1/search?q="+artist+"&type=artist")
    .then(function (searchResponse) {
      var bigID = searchResponse.body.artists.items[0].id;
      return chakram.get("https://api.spotify.com/v1/artists/"+bigID+"/top-tracks?country=GB");
    })
    .then(function (topTrackResponse) {
      var topTrack = topTrackResponse.body.tracks[0];
      expect(topTrack.name).to.contain("Old Thing Back");
    });
  });
});

Chakram exposes three promise related methods:

  • all, which takes an array of promises and returns a promise which is fulfilled once all promises in the provided array are fulfilled. The fulfillment value of the returned promise is an array of the fulfillment values of the promises which were passed to the function.
  • wait, which returns a promise which is fulfilled once all Chakram expectations are fulfilled.
  • waitFor, which takes an array of promises and returns a promise which is fulfilled once all promises in the provided array are fulfilled. This is similar to chakram.all, except it is fulfilled with the fulfillment value of the last promise in the provided array.

Running Tests

To run Chakram tests, install the Mocha testing framework globally (or as a dev dependency):

npm install -g mocha

Once installed, run the tests using the Mocha command line, which in its simplest form is:

mocha path/to/tests

Test results can be exported in multiple formats, Mocha's builtin formats are described here and export plugins for Mocha are available on NPM.

Adding Assertions

New assertions can be easily added to Chakram. The plugin tests demonstrate how properties and methods can be added. Further information is available in Chai's plugin documentation.

Contributing

Issues, pull requests and questions are welcomed.

Pull Requests

  • Fork the repository
  • Make changes
  • If required, write tests covering the new functionality (tests are normally written against httpbin.org)
  • Ensure all tests pass and 100% code coverage is achieved (run npm test)
  • Raise pull request
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].