Skip to content

Commit

Permalink
add travis
Browse files Browse the repository at this point in the history
  • Loading branch information
gridsane committed Mar 27, 2017
1 parent a4c23cb commit 43257b4
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 46 deletions.
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: node_js
node_js:
- "6"
- "7"
services:
- mongodb
before_script:
- sleep 15
- mongo chdb_test --eval 'db.addUser("travis", "test");'
env:
global:
- MONGO_URI=mongodb://travis:test@127.0.0.1:27017/chdb_test
- MONGO_URI_TEST=mongodb://travis:test@127.0.0.1:27017/chdb_test
- YOUTUBE_KEY=dummy-key
install:
- npm install
script:
- npm run lint
- npm test
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"classnames": "^2.2.5",
"color": "^0.11.3",
"css-loader": "^0.23.1",
"dotenv": "^4.0.0",
"express": "^4.14.0",
"extract-text-webpack-plugin": "^1.0.1",
"mongodb": "^2.1.20",
Expand Down
41 changes: 2 additions & 39 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,3 @@
import fs from 'fs';
import dotenv from 'dotenv';

// @todo its a shameless plug. Find another way to store YOUTUBE_API when
// running locally
let dotEnvVars = null;

function getVars() {
if (!fs.existsSync('.env')) {
return {};
}

return fs.readFileSync('.env')
.toString()
.split("\n")
.reduce((p, str) => {
const [key, val] = str.split('=');
if (key) {
p[key] = val;
}

return p;
}, {});
}

function resolveVar(varName) {
if (process.env[varName]) {
return process.env[varName];
}

if (!dotEnvVars) {
dotEnvVars = getVars();
}

return dotEnvVars[varName] || null;
}

export const MONGO_URL = resolveVar('MONGO_URL');
export const MONGO_URL_TEST = resolveVar('MONGO_URL_TEST');
export const YOUTUBE_KEY = resolveVar('YOUTUBE_KEY');
export const ANALYTICS_ID = resolveVar('ANALYTICS_ID');
export default dotenv.config().parsed;
4 changes: 2 additions & 2 deletions src/server/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import Storage from './storage';
import RedditAPI from '../api/reddit';
import YoutubeAPI from '../api/youtube';
import CompositeAPI from '../api/composite';
import * as config from '../config';
import config from '../config';

const storage = new Storage(config.MONGO_URL);
const storage = new Storage(config.MONGO_URI);
const api = new CompositeAPI({
reddit: new RedditAPI(),
youtube: new YoutubeAPI(config.YOUTUBE_KEY),
Expand Down
4 changes: 2 additions & 2 deletions src/server/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import Storage from './storage';
import RedditAPI from '../api/reddit';
import YoutubeAPI from '../api/youtube';
import CompositeAPI from '../api/composite';
import * as config from '../config';
import config from '../config';

const storage = new Storage(config.MONGO_URL);
const storage = new Storage(config.MONGO_URI);
const api = new CompositeAPI({
youtube: new YoutubeAPI(config.YOUTUBE_KEY),
reddit: new RedditAPI(),
Expand Down
6 changes: 3 additions & 3 deletions test/server/storage_test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import mongo from 'mongodb';
import Storage from '../../src/server/storage';
import {MONGO_URL_TEST} from '../../src/config.js';
import {MONGO_URI_TEST} from '../../src/config';

describe('Storage @database', () => {
const storage = new Storage(MONGO_URL_TEST);
const storage = new Storage(MONGO_URI_TEST);

beforeEach((done) => {
mongo.connect(MONGO_URL_TEST, (err, db) => {
mongo.connect(MONGO_URI_TEST, (err, db) => {
db.collection('channels').deleteMany({}, done);
});
});
Expand Down

0 comments on commit 43257b4

Please sign in to comment.