From 1597b830bd6b5e0c332d337af46b6a6edd0975c6 Mon Sep 17 00:00:00 2001 From: Kyrylo Silin Date: Sat, 30 Jul 2016 01:46:29 +0300 Subject: [PATCH] test-notify: mock HTTP .notify request Fixes #115 (Mock HTTP requests when testing) --- circle.yml | 1 + package.json | 7 ++++--- test/common.js | 4 ++-- test/slow/test-notify.js | 10 +++++++++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/circle.yml b/circle.yml index cf79633..fadc001 100644 --- a/circle.yml +++ b/circle.yml @@ -1,5 +1,6 @@ dependencies: override: + - npm install - ? | case $CIRCLE_NODE_INDEX in 0) diff --git a/package.json b/package.json index 346d524..2d37174 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/test/common.js b/test/common.js index c1d734c..687d693 100644 --- a/test/common.js +++ b/test/common.js @@ -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 { diff --git a/test/slow/test-notify.js b/test/slow/test-notify.js index 301d221..2f16768 100644 --- a/test/slow/test-notify.js +++ b/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!' }; @@ -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) {