Closed francisbrito closed 9 years ago
This sounds like a good idea - however this will break the setup tool for people who want to auto-generate their modules.json file. I'll think about the tradeoffs a bit more.
Also, before I merge anything else in, I'll build out testing using mocha/standard/etc so that I can merge and update with confidence.
About setup tool: require
allows loading JSON files too, so the JSON file produced by the tool could be loaded as-is. (I might have misunderstood your point, so please let me know so)
About testing: mind if I give you a hand?
PS: Excuse my English.
Sure - what do you recommend we use for testing? I've never worked with Mocha specifically before. How do we test all endpoints given that we wouldn't put any auth/api keys in the repo?
And the require() method sounds great then, this might end up looking more like Gruntfile.js then. I was thinking users might eventually be able to put their own beforeSend() functions (to control what is passed through the API).
For example:
{
path: "/code",
modules": [{
github: {
me: "username"
}
],
beforeSend: function(responseData) {
return responseData.github.filter(function(commit) {
return (commit.repo.name != "repoName");
});
})
}
We could load them from system environment like this:
describe('me-api-twitter', function () {
beforeEach(function () {
this.client = new Client({
consumerKey: process.env.TWITTER_CONSUMER_KEY,
consumerSecret: process.env.TWITTER_CONSUMER_SECRET,
//...
});
});
it('should work', function () {
this.client.getProfileInfoSomehow();
});
});
This makes it possible to commit tests to version control without exposing sensitive information. If users find setting ENV variables by hand cumbersome, we could use the dotenv
module so all variables are defined on a single text file. This .env
file should not be committed to version control.
Here's a sample .env file:
TWITTER_CONSUMER_KEY='my consumer key'
TWITTER_CONSUMER_SECRET='my consumer secret'
In order to use .env, we need to load into our JavaScript files like so:
require('dotenv').load();
describe('...', function () {
//...
beforeEach(function () {
this.client = new Client({
consumeKey: process.env.TWITTER_CONSUMER_KEY
//...
})
});
});
This enables configuring middlewares programmatically, like so:
Notice how keys/secrets are being loaded from the environment at runtime.