Socket
Socket
Sign inDemoInstall

chakram

Package Overview
Dependencies
52
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.2 to 0.0.3

lib/matchers/compression.js

10

conf.json
{
"templates": {
"applicationName": "Chakram",
"googleAnalytics": "",
"googleAnalytics": "UA-61133305-1",
"meta": {
"title": "Chakram: BDD REST API test tool",
"description": "Chakram: BDD REST API test tool",
"keyword": "E2E REST API JSON chai mocha nodejs test BDD"
"title": "Chakram: BDD REST API test tool",
"description": "Chakram: BDD REST API test tool",
"keyword": "E2E REST API JSON chai mocha nodejs test BDD"
},
"linenums": true
"linenums": false
}
}

@@ -104,5 +104,15 @@ /**

Returns a promise which is fulfilled once all promises in the array argument are fulfilled.
Similar to Q.all, however, the resulting resolved object is a single object rather than an array.
Identical to {@link https://github.com/kriskowal/q/wiki/API-Reference#promiseall Q.all}.
@method
@param {Promise[]} promiseArray - An array of promises to wait for
@returns {Promise}
@alias module:chakram.all
*/
exports.all = Q.all;
/**
Returns a promise which is fulfilled once all promises in the array argument are fulfilled.
Similar to {@link https://github.com/kriskowal/q/wiki/API-Reference#promiseall Q.all}, however, instead of being fulfilled with an array containing the fulfillment value of each promise, it is fulfilled with the fulfillment value of the last promise in the array argument. This allows chaining of HTTP calls.
@param {Promise[]} promiseArray - An array of promises to wait for
@returns {Promise}
@alias module:chakram.waitFor

@@ -140,17 +150,23 @@ @example

exports.wait = function() {
return exports.waitFor(recordedExpects, true);
return exports.waitFor(recordedExpects);
};
var warnUser = function (message) {
throw new Error(message);
if (this.currentTest.state !== 'failed') {
this.test.error(new Error(message));
}
};
afterEach(function() {
var checkForUnfulfilledExpectations = function () {
for(var ct = 0; ct < recordedExpects.length; ct++) {
if(recordedExpects[ct].isFulfilled !== undefined && recordedExpects[ct].isFulfilled() === false) {
warnUser("Some expectation promises were not fulfilled before the test finished. Ensure you are waiting for all the expectations to run");
warnUser.call(this, "Some expectation promises were not fulfilled before the test finished. Ensure you are waiting for all the expectations to run");
break;
}
}
};
afterEach(function() {
checkForUnfulfilledExpectations.call(this);
recordedExpects = [];
});

@@ -12,3 +12,4 @@ /**

require('./schema.js'),
require('./json.js')
require('./json.js'),
require('./compression.js')
];

@@ -1,2 +0,2 @@

var path = require('object-path');
var path = require('./../utils/objectPath.js');

@@ -30,6 +30,3 @@ /**

if(arguments.length === 2) {
object = path.get(object, arguments[0]);
if(object === undefined || object === null) {
throw new Error("could not find path '"+arguments[0]+"' in object "+JSON.stringify(this._obj.body));
}
object = path.get(utils, object, arguments[0]);
}

@@ -36,0 +33,0 @@

var tv4 = require('tv4'),
path = require('object-path');
path = require('./../utils/objectPath.js');

@@ -36,6 +36,3 @@ /**

if(arguments.length === 2) {
object = path.get(object, arguments[0]);
if(object === undefined || object === null) {
throw new Error("could not find path '"+arguments[0]+"' in object "+JSON.stringify(this._obj.body));
}
object = path.get(utils, object, arguments[0]);
}

@@ -42,0 +39,0 @@

{
"name": "chakram",
"version": "0.0.2",
"description": "Chakram is a REST 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. The library is built on node.js, mocha and chai",
"version": "0.0.3",
"description": "Chakram is a REST 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",
"main": "lib/chakram.js",

@@ -33,3 +33,2 @@ "license": {

"tv4": "1.1.x",
"object-path": "0.9.x",
"chai-shallow-deep-equal": "1.3.x"

@@ -55,2 +54,2 @@ },

}
}
}
# Chakram
[![Build Status](https://travis-ci.org/dareid/chakram.svg?branch=master)](https://travis-ci.org/dareid/chakram) [![Test Coverage](https://codeclimate.com/github/dareid/chakram/badges/coverage.svg)](https://codeclimate.com/github/dareid/chakram)
[![Build Status](https://travis-ci.org/dareid/chakram.svg?branch=master)](https://travis-ci.org/dareid/chakram) [![Test Coverage](https://codeclimate.com/github/dareid/chakram/badges/coverage.svg)](https://codeclimate.com/github/dareid/chakram) [![Code Climate](https://codeclimate.com/github/dareid/chakram/badges/gpa.svg)](https://codeclimate.com/github/dareid/chakram)

@@ -69,3 +69,3 @@ Chakram is a REST 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. The library is built on [node.js](https://nodejs.org/), [mocha](http://mochajs.org/) and [chai](http://chaijs.com/).

it("should include email, username, password and phone number", function () {
return expect(apiRequest).to.have.schema('results.0.user', {
return expect(apiRequest).to.have.schema('results[0].user', {
"required": [

@@ -81,3 +81,3 @@ "email",

it("should return a female user", function () {
return expect(apiRequest).to.have.json('results.0.user.gender', 'female');
return expect(apiRequest).to.have.json('results[0].user.gender', 'female');
});

@@ -89,12 +89,20 @@

it("should return a different username when called again", function () {
var firstUsername;
return apiRequest.then(function(obj) {
firstUsername = obj.body.results[0].user.username;
return chakram.get("http://api.randomuser.me/?gender=female");
})
.then(function(obj) {
var secondUsername = obj.body.results[0].user.username;
expect(firstUsername).not.to.equal(secondUsername);
it("should not be gzip compressed", function () {
return expect(apiRequest).not.to.be.encoded.with.gzip;
});
it("should return a different username on each request", function () {
this.timeout(10000);
var multipleRequests = [];
for(var ct = 0; ct < 5; ct++) {
multipleRequests.push(chakram.get("http://api.randomuser.me/?gender=female"));
}
return chakram.all(multipleRequests).then(function(responses) {
var returnedUsernames = responses.map(function(response) {
return response.body.results[0].user.username;
});
while (returnedUsernames.length > 0) {
var username = returnedUsernames.pop();
expect(returnedUsernames.indexOf(username)).to.equal(-1);
}
});

@@ -104,2 +112,12 @@ });

```
## Run Tests
To run Chakram tests, install the Mocha testing framework globally (or as a dev dependancy):
```
npm install -g mocha
```
Once installed, run the tests using the [Mocha command line](http://mochajs.org/#usage), which in its simplest form is:
```
mocha path/to/tests
```

@@ -82,2 +82,12 @@ var chakram = require('./../lib/chakram.js'),

it("should detect deflate compression", function () {
var deflate = chakram.get("http://httpbin.org/deflate");
return expect(deflate).to.be.encoded.with.deflate;
});
it("should detect gzip compression", function () {
var gzip = chakram.get("http://httpbin.org/gzip");
return expect(gzip).to.be.encoded.with.gzip;
});
});

@@ -22,3 +22,3 @@ var chakram = require('./../lib/chakram.js'),

it("should include email, username, password and phone number", function () {
return expect(apiRequest).to.have.schema('results.0.user', {
return expect(apiRequest).to.have.schema('results[0].user', {
"required": [

@@ -34,3 +34,3 @@ "email",

it("should return a female user", function () {
return expect(apiRequest).to.have.json('results.0.user.gender', 'female');
return expect(apiRequest).to.have.json('results[0].user.gender', 'female');
});

@@ -42,14 +42,22 @@

it("should return a different username when called again", function () {
var firstUsername;
return apiRequest.then(function(obj) {
firstUsername = obj.body.results[0].user.username;
return chakram.get("http://api.randomuser.me/?gender=female");
})
.then(function(obj) {
var secondUsername = obj.body.results[0].user.username;
expect(firstUsername).not.to.equal(secondUsername);
it("should not be gzip compressed", function () {
return expect(apiRequest).not.to.be.encoded.with.gzip;
});
it("should return a different username on each request", function () {
this.timeout(10000);
var multipleRequests = [];
for(var ct = 0; ct < 5; ct++) {
multipleRequests.push(chakram.get("http://api.randomuser.me/?gender=female"));
}
return chakram.all(multipleRequests).then(function(responses) {
var returnedUsernames = responses.map(function(response) {
return response.body.results[0].user.username;
});
while (returnedUsernames.length > 0) {
var username = returnedUsernames.pop();
expect(returnedUsernames.indexOf(username)).to.equal(-1);
}
});
});
});

@@ -8,9 +8,7 @@ var rewire = require('rewire'),

describe("User Warnings", function() {
var warningStub;
var warningStub, revertWarning;
before(function () {
var warning = chakram.__get__("warnUser");
expect(warning).to.throw(Error);
before(function () {
warningStub = sinon.stub();
chakram.__set__("warnUser", warningStub);
revertWarning = chakram.__set__("warnUser", warningStub);
});

@@ -29,2 +27,32 @@

it("should set the test as an error on warning the user", function () {
revertWarning();
var thisObj = {
test: {
error : sinon.stub()
},
currentTest: {
state : "passed"
}
};
var warning = chakram.__get__("warnUser");
warning.call(thisObj, "test error");
expect(thisObj.test.error.callCount).to.equal(1);
});
it("should not warn the user if the test has failed anyway", function () {
revertWarning();
var thisObj = {
test: {
error : sinon.stub()
},
currentTest: {
state : "failed"
}
};
var warning = chakram.__get__("warnUser");
warning.call(thisObj, "test error");
expect(thisObj.test.error.callCount).to.equal(0);
});
after(function() {

@@ -31,0 +59,0 @@ expect(warningStub.callCount).to.equal(2);

Sorry, the diff of this file is not supported yet

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