-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Igor Drobiazko
committed
Sep 15, 2014
0 parents
commit b605041
Showing
7 changed files
with
263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
node_modules | ||
*.gz | ||
.idea | ||
lib-cov | ||
reports | ||
/*.png | ||
.DS_Store | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
module.exports = function (grunt) { | ||
|
||
// Project configuration. | ||
grunt.initConfig({ | ||
clean: { | ||
all: ["coverage"] | ||
}, | ||
"jasmine_node": { | ||
options:{ | ||
forceExit: true | ||
}, | ||
instrumented: ["./coverage/instrument/spec"], | ||
specs: ["./spec"] | ||
}, | ||
|
||
// start - code coverage settings | ||
|
||
env: { | ||
coverage: { | ||
APP_DIR_FOR_CODE_COVERAGE: '../coverage/instrument/lib/' | ||
} | ||
}, | ||
|
||
|
||
clean: { | ||
coverage: { | ||
src: ['coverage/'] | ||
} | ||
}, | ||
|
||
|
||
instrument: { | ||
files: ['lib/*.js', 'spec/*.js'], | ||
options: { | ||
lazy: true, | ||
basePath: 'coverage/instrument/' | ||
} | ||
}, | ||
|
||
|
||
storeCoverage: { | ||
options: { | ||
dir: 'coverage/reports' | ||
} | ||
}, | ||
|
||
|
||
makeReport: { | ||
src: 'coverage/reports/**/*.json', | ||
options: { | ||
type: 'lcov', | ||
dir: 'coverage/reports', | ||
print: 'detail' | ||
} | ||
}, | ||
|
||
// end - code coverage settings | ||
|
||
coveralls: { | ||
test: { | ||
// LCOV coverage file relevant to every target | ||
src: 'coverage/reports/lcov.info', | ||
|
||
// When true, grunt-coveralls will only print a warning rather than | ||
// an error, to prevent CI builds from failing unnecessarily (e.g. if | ||
// coveralls.io is down). Optional, defaults to false. | ||
force: false | ||
} | ||
} | ||
}); | ||
|
||
grunt.loadNpmTasks('grunt-contrib-clean'); | ||
|
||
grunt.loadNpmTasks('grunt-jasmine-node'); | ||
|
||
grunt.loadNpmTasks('grunt-istanbul'); | ||
|
||
grunt.loadNpmTasks('grunt-env'); | ||
|
||
grunt.loadNpmTasks('grunt-coveralls'); | ||
|
||
// Default task(s). | ||
grunt.registerTask('default', ['clean', 'jasmine_node:specs']); | ||
|
||
grunt.registerTask('heroku', 'default'); | ||
|
||
grunt.registerTask('coverage', ['clean', 'env:coverage', | ||
'instrument', 'jasmine_node:instrumented', 'storeCoverage', 'makeReport', 'coveralls:test']); | ||
}; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
var request = require("request"); | ||
var Q = require("q"); | ||
var messages = require('./messages.js'); | ||
|
||
exports.simpleHttpRequestComponent = simpleHttpRequestComponent; | ||
|
||
function simpleHttpRequestComponent(method, requestOptions, handleResponse) { | ||
var self = this; | ||
|
||
Q.nfcall(request[method], requestOptions) | ||
.then(transformArrayToObject) | ||
.then(handleResponse) | ||
.then(emitMessage) | ||
.fail(handleError) | ||
.done(done); | ||
|
||
function transformArrayToObject(output) { | ||
return Q({ | ||
response : output[0], | ||
body : output[1] | ||
}); | ||
} | ||
|
||
function emitMessage(msg) { | ||
self.emit('data', msg); | ||
} | ||
|
||
function handleError(err) { | ||
console.log(err); | ||
self.emit('error', err); | ||
} | ||
|
||
function done() { | ||
self.emit('end'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
var uuid = require('node-uuid'); | ||
var Q = require('q'); | ||
|
||
exports.newEmptyMessage = newEmptyMessage; | ||
exports.newMessageWithBody = newMessageWithBody; | ||
|
||
function newEmptyMessage() { | ||
|
||
var msg = { | ||
id: uuid.v1(), | ||
attachments: {}, | ||
body: {}, | ||
headers: {}, | ||
metadata: {} | ||
}; | ||
|
||
return msg; | ||
} | ||
|
||
function newMessageWithBody(body) { | ||
|
||
var msg = newEmptyMessage(); | ||
|
||
msg.body = body; | ||
|
||
return msg; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "elasticio", | ||
"description": "Node.js API for the elastic.io integration platform", | ||
"version": "0.0.1", | ||
"author": { | ||
"name": "elastic.io GmbH", | ||
"email": "info@elastic.io" | ||
}, | ||
"keywords": [ | ||
"elasticio", | ||
"integration", | ||
"restful", | ||
"webservice", | ||
"http" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/elasticio/nodejs-api" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/elasticio/nodejs-api/issues" | ||
}, | ||
"homepage": "http://www.elastic.io", | ||
"dependencies": { | ||
"request": "2.9.x", | ||
"node-uuid": "1.3.3", | ||
"q": "1.0.0" | ||
}, | ||
"devDependencies": { | ||
"nock": "0.27.2", | ||
"grunt": "~0.4.5", | ||
"grunt-cli": "~0.1.9", | ||
"grunt-contrib-clean": "~0.5.0", | ||
"grunt-jasmine-node": "0.2.1", | ||
"grunt-istanbul": "0.3.0", | ||
"grunt-env": "~0.4.1", | ||
"grunt-coveralls": "0.3.0", | ||
"grunt-contrib-jshint": "~0.7.2", | ||
"grunt-contrib-copy": "~0.5.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
describe('component.js', function () { | ||
|
||
var Q = require('q'); | ||
var nock = require('nock'); | ||
var component = require('../lib/component.js'); | ||
var messages = require('../lib/messages.js'); | ||
|
||
it('should work', function () { | ||
|
||
nock('http://foobarbazbarney.com') | ||
.get('/api') | ||
.reply(200, JSON.stringify({ | ||
foo: 'bar', | ||
baz: 'barney' | ||
})); | ||
|
||
|
||
var emitter = jasmine.createSpyObj('emitter', ['emit']); | ||
|
||
var options = { | ||
url: 'http://foobarbazbarney.com/api', | ||
json: true | ||
}; | ||
|
||
function handleResponse(response) { | ||
return Q(messages.newMessageWithBody(response.body)); | ||
} | ||
|
||
runAndExpect( | ||
function () { | ||
component.simpleHttpRequestComponent.bind(emitter)('get', options, handleResponse); | ||
}, | ||
function () { | ||
return emitter.emit.callCount === 2; | ||
}, | ||
function () { | ||
var emitCalls = emitter.emit.calls; | ||
|
||
var emitDataArgs = emitCalls[0].args; | ||
|
||
expect(emitDataArgs[0]).toEqual('data'); | ||
expect(emitDataArgs[1].body).toEqual({ | ||
foo: 'bar', | ||
baz: 'barney' | ||
}); | ||
|
||
expect(emitCalls[1].args).toEqual(['end']); | ||
}); | ||
}); | ||
|
||
function runAndExpect(runner, waiter, expector) { | ||
|
||
var next = jasmine.createSpy('next'); | ||
|
||
runs(runner); | ||
|
||
waitsFor(waiter, 5000); | ||
|
||
runs(expector); | ||
} | ||
}); |