Fixed #111 by conditionally requiring the nedb and mongo clients. #116
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I ran into #111 while developing an Electron application that is only going to use nedb. I installed camo with
npm install --no-optional camo
since my application directly depends on nedb and I did not want mongodb and its dependencies (like kerberos) to be installed. I received a similar error to what is provided in #111.I fixed this by conditionally requiring the nedb and mongo clients in lib/db.js. With this change, the aforementioned error will only be thrown if the user intentionally tries to use one of the client databases whose corresponding module is not installed.
I did not provide tests as I did not know if it matters that the unit tests fail for a --no-optional installation.
I started playing with the idea of allowing unit tests to pass if either the nedb or mongodb modules were not detected (depending on the test), but then realized this may not be wanted or needed. I tried out the idea of figuring out whether to call
describe
ordescribe.skip
based on whether a callback function that contains require calls throws an error. Before that approach, I tried callingthis.skip()
inside ofbefore()
hooks, but this did not seem to work (probably because camo's version of mocha is < 3).Example:
In test/util.js:
In test/mongoclient.test.js:
Feedback on how to go about providing unit tests if they're needed for this fix would be much appreciated.