Skip to content

Commit

Permalink
Make @everymundo/simple-logr an optional Dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSanEM committed Nov 3, 2023
1 parent 6662c3b commit e2445ce
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 33 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const lazy = require('@danielsan/node-lazy-loader')(module)
const { Endpoint, GetEndpoint, PostEndpoint } = require('./classes/Endpoint.class.js')
const Headers = require('./classes/Headers.class.js')
const Response = require('./classes/Response.class.js')
const { parseEndpoints } = require('./lib/parse-endpoints.js')

const urlToEndpoint = (url, headers, agent) => new Endpoint(url, headers || null, agent)

Expand All @@ -11,7 +11,7 @@ module.exports = {
PostEndpoint,
Headers,
Response,
get parseEndpoints () { return lazy('parseEndpoints', './lib/parse-endpoints', 'parseEndpoints') },
parseEndpoints,
urlToEndpoint,
promiseDataTo: Endpoint.post,
promiseGet: Endpoint.get,
Expand Down
14 changes: 14 additions & 0 deletions lib/logr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const logr = (() => {
try {
return require('@everymundo/simple-logr')
} catch (error) {
return {
info: console.log,
error: console.error,
debug: console.log,
warn: console.warn
}
}
})()

module.exports = logr
2 changes: 1 addition & 1 deletion lib/promise-data-to-refactored.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const Endpoint = require('../classes/Endpoint.class')
const Headers = require('../classes/Headers.class')
const RequestError = require('../classes/Headers.class')
const logr = require('@everymundo/simple-logr')
const logr = require('../lib/logr.js')
// const { addQueryToPath } = require('../lib/add-query-to-path')
const { simulatedResponse } = require('../lib/simulate-response')
// const { setResTxt } = require('../lib/set-response-text')
Expand Down
2 changes: 1 addition & 1 deletion lib/promise-data-to.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict'
const logr = require('@everymundo/simple-logr')
const logr = require('../lib/logr.js')

const BasicEndpoint = require('../classes/BasicEndpoint.class.js')
const Headers = require('../classes/Headers.class.js')
Expand Down
2 changes: 1 addition & 1 deletion lib/simulate-response.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const logr = require('@everymundo/simple-logr')
const logr = require('../lib/logr.js')
const Response = require('../classes/Response.class.js')

function simulatedResponse (endpoint, inputData, headers, compress, start) {
Expand Down
46 changes: 31 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
"sinon": "^17.0.1",
"standard": "^17.1.0"
},
"dependencies": {
"@danielsan/node-lazy-loader": "*",
"optionalDependencies": {
"@everymundo/simple-logr": "*"
}
}
11 changes: 0 additions & 11 deletions test/lib/promise-data-to.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@ describe('lib/promise-data-to', () => {
httpEmitter = newHttpEmitter(httpResponse)
})

/* const config = {
http,
host: 'localhost',
port: 80,
path: '/path',
endpoint: 'http://localhost:80/path',
headers: { Authorization: 'Authorization' }
} */

const endpoint = new Endpoint('http://Authorization@localhost:80/path')

describe('When response is a simple statusCode 200', () => {
Expand Down Expand Up @@ -94,8 +85,6 @@ describe('lib/promise-data-to', () => {

const res = await lib.promiseDataTo(customConfig, data)

// expect(libSetHeaders.setHeaders).to.have.property('calledOnce', true)
console.log(res.requestHeaders)
expect(res.requestHeaders).to.deep.equal(expectedHeaders)
expect(httpEmitter.write).to.have.property('calledOnce', true)
expect(httpEmitter.write.args[0][0]).to.equal(expectedData)
Expand Down

0 comments on commit e2445ce

Please sign in to comment.