Socket
Socket
Sign inDemoInstall

chakram

Package Overview
Dependencies
58
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.0 to 1.5.0

lib/assertions/responsetime.js

5

CHANGELOG.md
#Changelog
###1.5.0
- Added `responsetime` assertion #58
- Added `responseTime` to `ChakramResponseObject` #60
- Introduced `del` alias #61
###1.4.0

@@ -4,0 +9,0 @@ - Added support for expect's second custom message argument #56

42

examples/spotify.js

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

describe("Spotify API", function() {
before(function () {

@@ -20,3 +20,3 @@ var spotifyErrorSchema = {

};
chakram.addProperty("spotify", function(){});

@@ -39,22 +39,22 @@ chakram.addMethod("error", function (respObj, status, message) {

});
describe("Search Endpoint", function () {
describe("Search Endpoint", function () {
var randomArtistSearch;
before(function () {
randomArtistSearch = chakram.get("https://api.spotify.com/v1/search?q=random&type=artist");
});
it("should require a search query", function () {
var missingQuery = chakram.get("https://api.spotify.com/v1/search?type=artist");
return expect(missingQuery).to.be.a.spotify.error(400, "No search query");
return expect(missingQuery).to.be.spotify.error(400, "No search query");
});
it("should require an item type", function () {
var missingType = chakram.get("https://api.spotify.com/v1/search?q=random");
return expect(missingType).to.be.a.spotify.error(400, "Missing parameter type");
return expect(missingType).to.be.spotify.error(400, "Missing parameter type");
});
var shouldSupportItemType = function (type) {

@@ -66,3 +66,3 @@ it("should support item type "+type, function () {

};
shouldSupportItemType('artist');

@@ -72,12 +72,12 @@ shouldSupportItemType('track');

shouldSupportItemType('playlist');
it("should throw an error if an unknown item type is used", function () {
var missingType = chakram.get("https://api.spotify.com/v1/search?q=random&type=invalid");
return expect(missingType).to.be.a.spotify.error(400, "Bad search type field");
return expect(missingType).to.be.spotify.error(400, "Bad search type field");
});
it("should by default return 20 search results", function () {
return expect(randomArtistSearch).to.have.limit("artists", 20);
});
it("should support a limit parameter", function () {

@@ -90,3 +90,3 @@ var one = chakram.get("https://api.spotify.com/v1/search?q=random&type=artist&limit=1");

});
it("should support an offset parameter", function () {

@@ -102,3 +102,3 @@ var first = chakram.get("https://api.spotify.com/v1/search?q=random&type=artist&limit=1");

});
it("should only support GET calls", function () {

@@ -112,3 +112,3 @@ this.timeout(4000);

});
it("should return href, id, name and popularity for all found artists", function () {

@@ -130,2 +130,2 @@ return expect(randomArtistSearch).to.have.schema('artists.items', {

});
});
});

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

require('./compression.js'),
require('./comprise.js')
];
require('./comprise.js'),
require('./responsetime.js')
];

@@ -43,3 +43,6 @@ var request = require('request'),

var reqObj = defaultedRequestObj || request;
var timer = process.hrtime();
reqObj(options, function (error, response, body) {
var elapsedTime = process.hrtime(timer);
var elapsedMilliseconds = (elapsedTime[0] * 1000) + (elapsedTime[1] / 1000000);
/**

@@ -54,2 +57,3 @@ Chakram Response Object

@property {String} url - The request's original URL
@property {Number} responseTime - The time taken to make the request (including redirects) at millisecond resolution
*/

@@ -61,3 +65,4 @@ deferred.resolve({

jar: options.jar,
url: url
url: url,
responseTime: elapsedMilliseconds
});

@@ -155,3 +160,16 @@ });

/**
Alias for chakram.delete. Perform HTTP DELETE request.
@param {string} url - fully qualified url
@param {Object} [data] - a JSON serializable object (unless json is set to false in params, in which case this should be a buffer or string)
@param {Object} [params] - additional request options, see the popular {@link https://github.com/request/request#requestoptions-callback request library} for options
@returns {Promise} Promise which will resolve to a {@link ChakramResponse} object
@alias module:chakram.del
*/
exports.del = function(url, data, params) {
return exports.delete(url, data, params);
};
/**
Sets the default options applied to all future requests.

@@ -172,2 +190,2 @@ @param {Object} [defaults] - default request options, see the popular {@link https://github.com/request/request#requestoptions-callback request library} for options

defaultedRequestObj = undefined;
};
};
{
"name": "chakram",
"version": "1.4.0",
"version": "1.5.0",
"description": "Chakram is an API testing framework designed to test JSON REST endpoints. The library offers a BDD testing style and fully exploits javascript promises",

@@ -32,10 +32,10 @@ "main": "lib/chakram.js",

"dependencies": {
"chai": "^3.5.0",
"chai-as-promised": "5.3.x",
"chai-subset": "1.2.x",
"extend-object": "1.0.x",
"q": "1.4.x",
"request": "^2.69.0",
"request-debug": "^0.2.0",
"tv4": "1.2.x"
"chai": "3.x.x",
"chai-as-promised": "5.x.x",
"chai-subset": "1.x.x",
"extend-object": "1.x.x",
"q": "1.x.x",
"request": "2.x.x",
"request-debug": "0.x.x",
"tv4": "1.x.x"
},

@@ -47,5 +47,5 @@ "devDependencies": {

"jsdoc": "latest",
"mocha": "^2.4.5",
"mocha": "3.x.x",
"rewire": "2.x.x",
"simplifyify": "^2.0.1",
"simplifyify": "2.x.x",
"sinon": "1.x.x"

@@ -52,0 +52,0 @@ },

@@ -19,16 +19,17 @@ # Chakram

+ Compression
+ Response times
- BDD formatting and hooks (e.g. beforeEach, afterEach)
- Promise based
- Extensible, allowing the defintion of custom assertions
- Plugin support
- Custom assertions
- Exports results in a variety of formats
- Debugging support
## Benefits
- **Software Quality**: Like all good applications, it’s critical that APIs are well-tested to ensure that they function correctly and deliver a consistent interface for consumers.
- **Test Driven Development**: Developers may adopt a test driven development approach to system testing. This ensures that minimal development effort is needed to achieve requirements coverage.
- **Backwards Compatibility**: Suites of Chakram tests can be developed throughout the evolution of the API, ensuring that versions behave as expected and backward compatibility is maintained.
- **Documentation**: A well-described and easily readable test can demonstrate how to make use of an API.
- **Third party testing**: Chakram’s primary use is to test APIs under development. However, it may also be exploited to test third party APIs. Tests can be written which verify the functionality required and using continuous integration platforms, tests can be run periodically so that any changes to the API can generate notifications.
## Plugins
Awesome plugins from the community:
- [Joi Schema Assertion](https://github.com/roberto/chakram-joi)
We would love to see more plugins! If you have a plugin, please add it to the list.
## Getting Started

@@ -35,0 +36,0 @@

@@ -89,2 +89,10 @@ var testsRunningInNode = (typeof global !== "undefined" ? true : false),

});
it("should record response time", function () {
this.timeout(3000);
return chakram.get("http://httpbin.org/delay/2")
.then(function (obj) {
expect(obj.responseTime).to.exist.and.to.be.at.least(2000).and.at.most(3000);
});
});
});

@@ -91,0 +99,0 @@

@@ -63,2 +63,3 @@ var testsRunningInNode = (typeof global !== "undefined" ? true : false),

testWriteMethods(chakram.delete, "http://httpbin.org/delete");
testWriteMethods(chakram.del, "http://httpbin.org/delete");
});

@@ -65,0 +66,0 @@

@@ -69,4 +69,4 @@ var testsRunningInNode = (typeof global !== "undefined" ? true : false),

return chakram.waitFor([
expect(notATeapot).to.not.be.a.teapot,
expect(aTeapot).to.be.a.teapot
expect(notATeapot).to.not.be.teapot,
expect(aTeapot).to.be.teapot
]);

@@ -73,0 +73,0 @@ });

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