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

axios-debug-log

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

axios-debug-log - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

23

index.js

@@ -6,8 +6,8 @@ 'use strict'

axios.interceptors.request.use(function (config) {
function logRequest (config) {
debug(config.method.toUpperCase() + ' ' + config.url)
return config
})
}
axios.interceptors.response.use(function (response) {
function logResponse (response) {
debug(

@@ -18,2 +18,17 @@ response.status + ' ' + response.statusText,

return response
})
}
function addLogger (instance) {
instance.interceptors.request.use(logRequest)
instance.interceptors.response.use(logResponse)
}
addLogger(axios)
axios.create = (function (originalCreate) {
return function create () {
var instance = originalCreate.apply(axios, arguments)
addLogger(instance)
return instance
}
})(axios.create)

22

package.json
{
"name": "axios-debug-log",
"version": "0.1.0",
"version": "0.2.0",
"description": "Axios interceptor of logging requests & responses by debug.",
"main": "index.js",
"scripts": {
"lint": "eslint .",
"unit": "ava",
"coverage": "nyc ava && nyc report --reporter=html",
"test": "npm run lint && npm run unit"
"lint": "standard",
"unit": "mocha --require should --require should-sinon",
"test": "npm run lint && npm run unit",
"coverage": "nyc npm test && nyc report --reporter=html"
},

@@ -31,11 +31,9 @@ "repository": {

"devDependencies": {
"ava": "^0.17.0",
"axios": "^0.15.0",
"eslint": "^3.14.1",
"eslint-config-standard": "^6.2.1",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^2.0.1",
"mocha": "^3.2.0",
"nyc": "^10.1.2",
"proxyquire": "^1.7.11",
"sinon": "^1.17.7"
"should": "^11.2.0",
"should-sinon": "0.0.5",
"sinon": "^1.17.7",
"standard": "^8.6.0"
},

@@ -42,0 +40,0 @@ "peerDependencies": {

@@ -1,12 +0,18 @@

import test from 'ava'
/* eslint-env mocha */
const proxyquire = require('proxyquire')
const axios = require('axios')
const debug = require('debug')
const sinon = require('sinon')
const spy = sinon.spy()
proxyquire('.', { debug: name => ({ axios: spy }[name]) })
before(() => {
debug.enable('axios')
debug.formatArgs = args => args
require('.')
})
const axios = require('axios')
beforeEach(() => {
debug.log = sinon.spy()
})
test('Logging request', t => axios({
it('should logging request', () => axios({
method: 'FOO',

@@ -20,8 +26,27 @@ url: 'http://example.com/',

}).then(() => {
t.is(spy.callCount, 2)
const requestLogging = spy.firstCall
t.is(requestLogging.args[0], 'FOO http://example.com/')
const responseLogging = spy.secondCall
t.is(responseLogging.args[0], '200 BAR')
t.is(responseLogging.args[1], '(FOO http://example.com/)')
debug.log.should.be.calledTwice()
debug.log.firstCall.should.be.calledWithExactly(
'FOO http://example.com/'
)
debug.log.secondCall.should.be.calledWithExactly(
'200 BAR', '(FOO http://example.com/)'
)
}))
it('should logging request of axios instance', () => axios.create()({
method: 'BAZ',
url: 'http://example.com/',
adapter: config => Promise.resolve({
status: 200,
statusText: 'QUX',
config
})
}).then(() => {
debug.log.should.be.calledTwice()
debug.log.firstCall.should.be.calledWithExactly(
'BAZ http://example.com/'
)
debug.log.secondCall.should.be.calledWithExactly(
'200 QUX', '(BAZ http://example.com/)'
)
}))
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