-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #213 from reportportal/feature/update-work-with-axios
Keep axios instance between requests. Update work with headers
- Loading branch information
Showing
18 changed files
with
195 additions
and
191 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
node_modules | ||
build | ||
spec/**/*.json | ||
__tests__/**/*.json |
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
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
File renamed without changes.
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 |
---|---|---|
@@ -1,8 +1,15 @@ | ||
module.exports = { | ||
moduleFileExtensions: ['js'], | ||
"testMatch": [ | ||
"<rootDir>/spec/**/*[sS]pec.js" | ||
], | ||
coverageReporters: ["lcov", "text-summary"], | ||
testRegex: '/__tests__/.*\\.(test|spec).js$', | ||
testEnvironment: 'node', | ||
collectCoverageFrom: ['lib/**/*.js', '!lib/logger.js'], | ||
coverageThreshold: { | ||
global: { | ||
branches: 80, | ||
functions: 75, | ||
lines: 80, | ||
statements: 80, | ||
}, | ||
}, | ||
bail: false, | ||
}; |
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
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 @@ | ||
const addLogger = (axiosInstance) => { | ||
axiosInstance.interceptors.request.use((config) => { | ||
const startDate = new Date(); | ||
// eslint-disable-next-line no-param-reassign | ||
config.startTime = startDate.valueOf(); | ||
|
||
console.log(`Request method=${config.method} url=${config.url} [${startDate.toISOString()}]`); | ||
|
||
return config; | ||
}); | ||
|
||
axiosInstance.interceptors.response.use( | ||
(response) => { | ||
const date = new Date(); | ||
const { status, config } = response; | ||
|
||
console.log( | ||
`Response status=${status} url=${config.url} time=${ | ||
date.valueOf() - config.startTime | ||
}ms [${date.toISOString()}]`, | ||
); | ||
|
||
return response; | ||
}, | ||
(error) => { | ||
const date = new Date(); | ||
const { response, config } = error; | ||
const status = response ? response.status : null; | ||
|
||
console.log( | ||
`Response ${status ? `status=${status}` : `message='${error.message}'`} url=${ | ||
config.url | ||
} time=${date.valueOf() - config.startTime}ms [${date.toISOString()}]`, | ||
); | ||
|
||
return Promise.reject(error); | ||
}, | ||
); | ||
}; | ||
|
||
module.exports = { addLogger }; |
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
Oops, something went wrong.