Skip to content

Commit

Permalink
test-notify: mock HTTP .notify request
Browse files Browse the repository at this point in the history
Fixes #115 (Mock HTTP requests when testing)
  • Loading branch information
kyrylo committed Jul 29, 2016
1 parent b06f61a commit 1597b83
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions circle.yml
@@ -1,5 +1,6 @@
dependencies:
override:
- npm install
- ? |
case $CIRCLE_NODE_INDEX in
0)
Expand Down
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -44,12 +44,13 @@
"eslint-config-airbnb-base": "~1.0.3",
"eslint-plugin-import": "~1.6.1",
"express": "~4.13.4",
"hapi": "~13.5.0",
"far": "~0.0.4",
"hapi": "~13.5.0",
"mockery": "~1.4.0",
"nock": "^8.0.0",
"nsp": "~2.2.0",
"sinon": "~1.7.2",
"semver": "~5.3.0"
"semver": "~5.3.0",
"sinon": "~1.7.2"
},
"optionalDependencies": {},
"license": "MIT"
Expand Down
4 changes: 2 additions & 2 deletions test/common.js
Expand Up @@ -6,8 +6,8 @@ var path = require('path');
var merge = require('lodash.merge');

// An account on the free plan specifically for testing this module.
exports.key = '96979331ec7e18bbe7ec1529da2ed083';
exports.projectId = '122374';
exports.key = '81bbff95d52f8856c770bb39e827f3f6';
exports.projectId = '113743';

// Use custom config if available instead
try {
Expand Down
10 changes: 9 additions & 1 deletion test/slow/test-notify.js
@@ -1,7 +1,10 @@
var common = require('../common');
var airbrake = require(common.dir.root).createClient(null, common.key, 'production');
var airbrake = require(common.dir.root).createClient(common.projectId, common.key, 'production');
var sinon = require('sinon');
var assert = require('assert');
var nock = require('nock');

nock.disableNetConnect();

var err = new Error('Node.js just totally exploded on me');
err.env = { protect: 'the environment!' };
Expand All @@ -19,10 +22,15 @@ airbrake.on('vars', function(type, vars) {
});

var spy = sinon.spy();
var endpoint = nock('https://api.airbrake.io').
post('/api/v3/projects/' + common.projectId + '/notices?key=' + common.key).
reply(201, '{"url":"https://airbrake.io/locate/123"}');

airbrake.notify(err, spy);

process.on('exit', function() {
assert.ok(spy.called);
endpoint.done();

var error = spy.args[0][0];
if (error) {
Expand Down

0 comments on commit 1597b83

Please sign in to comment.