Skip to content

Commit

Permalink
add linting to test files
Browse files Browse the repository at this point in the history
  • Loading branch information
radiovisual committed Feb 10, 2016
1 parent 924812e commit 66f449b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 42 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
"esnext": true,
"ignores": [
"dist/**",
"test/**",
"local-config.js"
],
"rules" : {
Expand Down
18 changes: 8 additions & 10 deletions test/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ const Birdwatch = require('./../dist/');
const testData = require('./testTweets.json');

const settings = {
testData:testData,
refreshTime:600,
testData,
refreshTime: 600,
port: 0
};

const bw = new Birdwatch(settings)
.feed('birdwatchnpm')
.feed('justinbieber', {filterTags: ['believe']})
.feed('taylorswift13')
.start()
.then(tweets => {
new Birdwatch(settings)
.feed('birdwatchnpm')
.feed('justinbieber', {filterTags: ['believe']})
.feed('taylorswift13')
.start()
.then(tweets => {
console.log('\nbirdwatch is ready to serve %s tweets', tweets.length);
});


64 changes: 33 additions & 31 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import configuration from './../birdwatch-config.js';
import Birdwatch from '../dist';
import test from 'ava';
import condense from 'selective-whitespace';
import fs from 'fs';


import testData from './testTweets.json';
import rm from 'rimraf';
import got from 'got';
import getPort from 'get-port';

const tempDir = `${__dirname}/custom/location/test`;

test.before('setup', () => {
rm.sync(`${__dirname}/custom`);
});
Expand All @@ -33,55 +31,55 @@ test('should fail when a screenname is not supplied to .feed()', async t => {
});

test('should add a feed with options', t => {
const birdwatch = new Birdwatch({server: false}).feed('testfeed', { filterTags:/test/i });
const birdwatch = new Birdwatch({server: false}).feed('testfeed', {filterTags: /test/i});
t.true(birdwatch._feed[0].options.hasOwnProperty('filterTags'));
});

test('should fail if no feed is supplied', async t => {
const birdwatch = new Birdwatch({server: false});
await t.throws(birdwatch.start(), "You must supply at least one feed to Birdwatch");
await t.throws(birdwatch.start(), 'You must supply at least one feed to Birdwatch');
});

test('should get tweet data returned', async t => {
await new Birdwatch({testData:testData, server: true, port:0})
await new Birdwatch({testData, server: true, port: 0})
.feed('test', {})
.start().then(tweets => {
t.is(typeof tweets[0].text, 'string');
});
});

test('should fail when filterTags is not a valid regex', async t => {
const bw = await new Birdwatch({testData:testData, server:false}).feed('test', {filterTags: 'a'});
const bw = await new Birdwatch({testData, server: false}).feed('test', {filterTags: 'a'});
t.throws(bw.start(), 'Invalid regex: a for test');
});

test('should filter hashtags', async t => {
await new Birdwatch({testData:testData, server:false})
await new Birdwatch({testData, server: false})
.feed('test', {filterTags: /#01|#02|#03/})
.start().then(tweets => {
t.is(tweets.length, 3);
});
});

test('should remove retweets with removeRetweets:true', async t => {
await new Birdwatch({testData:testData, server:false})
.feed('test', {removeRetweets:true})
await new Birdwatch({testData, server: false})
.feed('test', {removeRetweets: true})
.start().then(tweets => {
t.is(tweets.length, 5);
});
});

test('should allow multiple feeds with options', async t => {
await new Birdwatch({testData:testData, server:false})
.feed('noretweets', {removeRetweets:true})
await new Birdwatch({testData, server: false})
.feed('noretweets', {removeRetweets: true})
.feed('specifichashtags', {filterTags: /#01|#02|#03/})
.start().then(tweets => {
t.is(tweets.length, 8);
});
});

test('should sort the tweets', async t => {
await new Birdwatch({testData:testData, server:false})
await new Birdwatch({testData, server: false})
.feed('test')
.start().then(tweets => {
t.is(tweets.length, 10);
Expand All @@ -91,7 +89,7 @@ test('should sort the tweets', async t => {
});

test('should sort tweets from multiple feeds', async t => {
const bw = await new Birdwatch({testData:testData, server:false})
await new Birdwatch({testData, server: false})
.feed('test1', {filterTags: /#01|#02/})
.feed('test2', {filterTags: /#01|#02/})
.start().then(tweets => {
Expand All @@ -102,8 +100,11 @@ test('should sort tweets from multiple feeds', async t => {
});

test('should allow custom sorting', async t => {
const fn = function(x,y) { var n = parseInt(x.text.substring(12)); if (n % 2 === 0) { return 1; } return -1 };
const bw = await new Birdwatch({testData:testData, sortBy:fn, server:false})
const fn = function (x) {
const n = parseInt(x.text.substring(12), 10);
return n % 2 === 0 ? 1 : -1;
};
await new Birdwatch({testData, sortBy: fn, server: false})
.feed('test1')
.start().then(tweets => {
t.is(tweets[0].text, 'test tweet #09');
Expand All @@ -113,56 +114,57 @@ test('should allow custom sorting', async t => {

test('should fail if custom sorting function is not a valid function', async t => {
t.throws(() => {
new Birdwatch({testData:testData, sortBy:[], server:false }).feed('test1').start();
new Birdwatch({testData, sortBy: [], server: false}).feed('test1').start();
}, TypeError, 'sortBy value must be a function.');
});

test('should not expose private keys in birdwatch-config.js', t => {
t.true(
configuration.consumerKey === 'YOUR_CONSUMER_KEY' &&
configuration.consumerSecret === 'YOUR_CONSUMER_SECRET' &&
configuration.accessToken === 'YOUR_ACCESS_TOKEN' &&
configuration.accessTokenSecret === 'YOUR_ACCESS_TOKEN_SECRET'
configuration.consumerKey === 'YOUR_CONSUMER_KEY' &&
configuration.consumerSecret === 'YOUR_CONSUMER_SECRET' &&
configuration.accessToken === 'YOUR_ACCESS_TOKEN' &&
configuration.accessTokenSecret === 'YOUR_ACCESS_TOKEN_SECRET'
);
});

test('filterTags should accept an array of strings', async t => {
await new Birdwatch({testData:testData, server:false})
.feed('test', {filterTags:['01','02']})
.start().then(tweets => {
await new Birdwatch({testData, server: false})
.feed('test', {filterTags: ['01', '02']})
.start()
.then(tweets => {
t.is(tweets.length, 2);
});
});

test('should set a limit', async t => {
await new Birdwatch({testData:testData, server:false})
.feed('test', {filterTags:['01','02', '03', '04'], limit: 2})
await new Birdwatch({testData, server: false})
.feed('test', {filterTags: ['01', '02', '03', '04'], limit: 2})
.start().then(tweets => {
t.is(tweets.length, 2);
});
});

test('should set custom cache directory', async t => {
const birdwatch = new Birdwatch({server: false, cacheDir:'/custom/location'}).feed('testfeed');
const birdwatch = new Birdwatch({server: false, cacheDir: '/custom/location'}).feed('testfeed');
t.is(birdwatch.options.cacheDir, '/custom/location');
});

test('should set custom url', async t => {
const birdwatch = new Birdwatch({server: false, url:'/custom/url'}).feed('testfeed');
const birdwatch = new Birdwatch({server: false, url: '/custom/url'}).feed('testfeed');
t.is(birdwatch.options.url, '/custom/url');
});

test('should launch server', async t => {
await getPort().then(async port => {
const bw = await new Birdwatch({testData:testData, port:port}).feed('testfeed').start();
await new Birdwatch({testData, port}).feed('testfeed').start();
t.true((await got(`http://localhost:${port}/birdwatch/tweets`)).body.length > 0);
t.true(JSON.parse((await got(`http://localhost:${port}/birdwatch/tweets`)).body)[0].hasOwnProperty('created_at'));
});
});

test('should set custom url', async t => {
await getPort().then(async port => {
const bw = await new Birdwatch({testData:testData, port:port, url:'/custom/url'}).feed('testfeed').start();
await new Birdwatch({testData, port, url: '/custom/url'}).feed('testfeed').start();
t.true((await got(`http://localhost:${port}/custom/url`)).body.length > 0);
t.true(JSON.parse((await got(`http://localhost:${port}/custom/url`)).body)[0].hasOwnProperty('created_at'));
});
Expand Down

0 comments on commit 66f449b

Please sign in to comment.