Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

blitz

Package Overview
Dependencies
Maintainers
1
Versions
541
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blitz - npm Package Compare versions

Comparing version 0.3.2 to 0.4.0

.npmignore

42

lib/blitz.js

@@ -9,3 +9,3 @@ /*jslint

Rush = require('./blitz/rush'),
Parser = require('./blitz/parser');
Runner = require('./blitz/runner');

@@ -23,5 +23,12 @@ function Blitz(username, apiKey, host, port, apiAuthenticated) {

function run(options, module) {
self.authenticate(
function () { module.create(self.credentials, options).execute(); },
function (message) { module.emit('error', message); }
);
}
self.authenticate = function(success, error) {
//verifies authentication
if (self.authenticated) {
module.create(self.credentials, options).execute();
success();
}

@@ -34,10 +41,10 @@ else {

self.credentials.apiKey = result.api_key;
module.create(self.credentials, options).execute();
success();
}
else {
module.emit('error', result);
error(result);
}
}).on('error', function (response) {
//propagates the api error thorugh the module
module.emit('error', response);
error(response);
});

@@ -60,6 +67,7 @@ }

self.execute = function (text) {
var parser = new Parser();
var options = parser.parse(text);
var runner = options.pattern ? new Rush() : new Sprint();
run(options, runner);
var runner = new Runner(self.credentials);
self.authenticate(
function () { runner.execute(text); },
function (message) { runner.emit('error', message); }
);
return runner;

@@ -70,14 +78,6 @@ };

var client = new api.Client(username, apiKey, host, port);
if (self.authenticated) {
client.about(callback);
}
else {
client.login().on('login', function (result) {
self.authenticated = true;
self.credentials.apiKey = result.api_key;
client.about(callback);
}).on('error', function (response) {
throw response.reason;
});
}
self.authenticate(
function () { client.about(callback); },
function (message) { throw message.reason; }
);
};

@@ -84,0 +84,0 @@ }

@@ -11,3 +11,3 @@ /*jslint

EventEmitter = require('events').EventEmitter,
Sys = require('sys'),
Util = require('util'),
api = {};

@@ -157,8 +157,29 @@

self.parse = function (text) {
var request = null,
jsonData = JSON.stringify({command: text}),
options = requestOptions();
options.path = '/api/1/parse';
options.headers['content-length'] = jsonData.length;
request = http.request(options, function (response) {
responseHandler(response, function (jsonData) {
// only emmited on complete
var event = 'parse';
if (jsonData.error) {
event = 'error';
}
self.emit(event, jsonData);
});
});
// sends the data and closes the request
request.write(jsonData);
request.end();
return self;
};
return self;
};
Sys.inherits(api.Client, EventEmitter);
Util.inherits(api.Client, EventEmitter);
module.exports = api;
}());

@@ -9,3 +9,3 @@ /*jslint

validate = require('./validate'),
Sys = require('sys');
Util = require('util');

@@ -63,10 +63,9 @@ /**

function Rush() {
var self = this;
/**
* Responsable for the Rushes. Uses api.client to make the requests and
* Responsible for the Rushes. Uses api.client to make the requests and
* return a formatted Rush response
*/
self.create = function (credentials, options) {
var user = credentials.username,
this.create = function (credentials, options) {
var self = this,
user = credentials.username,
pass = credentials.apiKey,

@@ -152,6 +151,4 @@ host = credentials.host,

}
Sys.inherits(Rush, EventEmitter);
Util.inherits(Rush, EventEmitter);
module.exports = Rush;
}());

@@ -9,3 +9,3 @@ /*jslint

validate = require('./validate'),
Sys = require('sys');
Util = require('util');

@@ -75,4 +75,2 @@ /**

function Sprint() {
var self = this;
/**

@@ -82,4 +80,5 @@ * Responsable for the Sprints. Uses api.client to make the requests

*/
self.create = function (credentials, options) {
var user = credentials.username,
this.create = function (credentials, options) {
var self = this,
user = credentials.username,
pass = credentials.apiKey,

@@ -119,2 +118,3 @@ host = credentials.host,

self.emit('error', result);
clearTimeout(timeout);
return;

@@ -164,6 +164,4 @@ }

}
Sys.inherits(Sprint, EventEmitter);
Util.inherits(Sprint, EventEmitter);
module.exports = Sprint;
}());

@@ -5,3 +5,3 @@ {

"description": "Blitz node.js client API",
"version": "0.3.2",
"version": "0.4.0",
"homepage": "http://blitz.io",

@@ -8,0 +8,0 @@ "repository": {

@@ -24,3 +24,3 @@ ### ![blitz.io](http://blitz.io/images/logo2.png)

```javascript
var Blitz = require('../blitz-node/lib/blitz.js');
var Blitz = require('blitz-node');

@@ -37,7 +37,8 @@ console.log('Starting Sprint...');

}).on('complete', function (data) {
var steps, i, step;
console.log('region: ' + data.region);
console.log('duration: ' + data.duration);
var steps = data.steps;
for(var i in steps) {
var step = steps[i];
steps = data.steps;
for(i in steps) {
step = steps[i];
console.log("> Step " + i);

@@ -63,3 +64,3 @@ console.log("\tstatus: " + step.response.status);

{url: 'http://your.cool.app'},
{url: 'http://your.cool.ap/page1'}
{url: 'http://your.cool.app/page1'}
],

@@ -71,7 +72,8 @@ region: 'california',

}).on('complete', function (data) {
var steps, i, step;
console.log('region: ' + data.region);
console.log('duration: ' + data.duration);
var steps = data.steps;
for(var i in steps) {
var step = steps[i];
steps = data.steps;
for(i in steps) {
step = steps[i];
console.log("> Step " + i);

@@ -86,2 +88,34 @@ console.log("\tstatus: " + step.response.status);

});
```
```
**or using the API parser**
The parser expects a text and will recognize the type of test at runtime.
```javascript
var Blitz = require('blitz');
console.log('Starting Test...');
new Blitz('<email>','<api-key>').execute('-p 1-100:60 http://your.cool.app').on('status', function (data) {
process.stdout.write('.');
}).on('complete', function (data) {
var steps, i, step;
console.log('region: ' + data.region);
console.log('duration: ' + data.duration);
steps = data.steps;
for(i in steps) {
step = steps[i];
console.log("> Step " + i);
console.log("\tstatus: " + step.response.status);
console.log("\tduration: " + step.duration);
console.log("\tconnect: " + step.connect);
}
}).on('error', function (response) {
console.log("error: " + response.error);
console.log("reason: " + response.reason);
});
```
var testServerPort = 9295,
helper = require('./helper'),
Blitz = require('../lib/blitz.js');
//needed by the mock server to compare usernames
process.env['BLITZ_API_USER'] = 'user';
describe("Blitz", function () {

@@ -11,5 +9,14 @@ var blitz;

beforeEach(function () {
// Test server. Will be handling the requests sent by the tests.
helper.mockServer.listen(testServerPort);
//needed by the mock server to compare usernames
process.env['BLITZ_API_USER'] = 'user';
blitz = new Blitz('user', 'key', 'localhost', 9295);
});
afterEach(function () {
helper.mockServer.close();
});
it("should return a Rush Result object", function () {

@@ -76,2 +83,4 @@ var finished = false;

it('should execute a Rush', function () {
process.env['BLITZ_API_USER'] = 'user2';
blitz = new Blitz('user2', 'key', 'localhost', 9295);
var finished = false;

@@ -78,0 +87,0 @@ runs (function() {

@@ -9,5 +9,2 @@ var testServerPort = 9295,

// Test server. Will be handling the requests sent by the tests.
helper.mockServer.listen(testServerPort);
describe("API Client", function () {

@@ -17,2 +14,5 @@ var client;

beforeEach(function () {
// Test server. Will be handling the requests sent by the tests.
helper.mockServer.listen(testServerPort);
client = new api.Client(credentials['username'], credentials['apiKey'],

@@ -22,2 +22,6 @@ 'localhost', testServerPort);

afterEach(function () {
helper.mockServer.close();
});
describe("execute", function () {

@@ -24,0 +28,0 @@ it("should receive ok on queue event", function () {

var testServerPort = 9295,
helper = require('../helper'),
Rush = require('../../lib/blitz/rush'),

@@ -9,5 +10,12 @@ credentials = {username: 'user', apiKey: 'key', host: 'localhost', port: 9295};

beforeEach(function() {
// Test server. Will be handling the requests sent by the tests.
helper.mockServer.listen(testServerPort);
rush = new Rush();
});
afterEach(function () {
helper.mockServer.close();
});
it("should have a Result object", function () {

@@ -14,0 +22,0 @@ var finished = false;

var testServerPort = 9295,
helper = require('../helper'),
Sprint = require('../../lib/blitz/sprint'),

@@ -9,5 +10,12 @@ credentials = {username: 'user', apiKey: 'key', host: 'localhost', port: 9295};

beforeEach(function() {
// Test server. Will be handling the requests sent by the tests.
helper.mockServer.listen(testServerPort);
sprint = new Sprint();
});
afterEach(function () {
helper.mockServer.close();
});
it("should have a Result object", function () {

@@ -14,0 +22,0 @@ var finished = false;

@@ -21,2 +21,11 @@ var http = require('http'),

},
parseSprint = {ok: true, command: {
steps: [{ url: 'http://127.0.0.1'}, { url: 'http://127.0.0.1/2'}]
}
},
parseRush = {ok: true, command: {
steps: [{ url: 'http://127.0.0.1', user: 'c123'}, { url: 'http://127.0.0.1/2'}],
pattern: {iterations: 1, intervals: [{iterations: 1, start: 1, end: 100, duration: 60}]}
}
},
status = {

@@ -127,2 +136,14 @@ _id: 'a123',

}
else if (request.url === '/api/1/parse') {
response.writeHead(200, {'content-type': 'application/json'});
if(process.env['BLITZ_API_USER'] === 'user') {
response.end(JSON.stringify(parseSprint));
}
else if (process.env['BLITZ_API_USER'] === 'user2') {
response.end(JSON.stringify(parseRush));
}
else {
response.end(JSON.stringify({error: 'parse', reason: 'test'}));
}
}
else if (request.url === '/api/1/jobs/a123/status') {

@@ -129,0 +150,0 @@ status.status = 'completed';

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc