Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to tape and refactor out babel #17

Merged
merged 4 commits into from
Mar 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules/
/coverage
lib/
1 change: 0 additions & 1 deletion .npmignore

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
node_js:
- '0.12'
- '4'
- '6'
branches:
only:
- master
Expand Down
File renamed without changes.
File renamed without changes.
18 changes: 6 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
"description": "A Node.js helper library for swapi.co",
"main": "index.js",
"scripts": {
"test": "./node_modules/mocha/bin/mocha --compilers js:babel-core/register",
"compile": "babel -d lib/ src/",
"prepublish": "./node_modules/nsp/bin/nsp check && npm run compile",
"coverage": "babel-node ./node_modules/.bin/isparta cover _mocha",
"coveralls": "npm run coverage -- --report lcovonly && cat ./coverage/lcov.info | coveralls"
"test": "tape test/*.js",
"prepublish": "nsp check",
"coverage": "istanbul cover tape -- test/*.js",
"coveralls": "npm run coverage && cat ./coverage/lcov.info | coveralls"
},
"author": {
"name": "Lucas Holmquist",
Expand All @@ -24,16 +23,11 @@
],
"license": "BSD",
"devDependencies": {
"babel-cli": "^6.2.0",
"babel-core": "^6.2.1",
"babel-preset-es2015": "^6.1.18",
"coveralls": "^2.11.4",
"isparta": "^4.0.0",
"mocha": "^3.2.0",
"mocha-lcov-reporter": "^1.0.0",
"istanbul": "^0.4.5",
"nock": "^9.0.2",
"nsp": "^2.0.2",
"should": "^11.2.0"
"tape": "^4.6.3"
},
"dependencies": {
"request": "^2.67.0"
Expand Down
226 changes: 226 additions & 0 deletions test/swapi-api-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
'use strict';

const nock = require('nock');
const swapi = require('../lib/swapi-node.js');
const version = require('../package.json').version;
const test = require('tape');

nock.disableNetConnect();

test('GET a resource', (t) => {
nock('http://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/people/?page=2')
.reply(200, {});

swapi.get('http://swapi.co/api/people/?page=2').then((result) => {
t.pass('return success');
t.end();
});
});

test('GET People - Return a Promise', (t) => {
nock('http://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/people/1')
.reply(200, {});

const request = swapi.getPerson(1).then((result) => {
t.pass('success return');
t.end();
});

t.equal(request instanceof Promise, true, 'should return a Promise');
});

test('GET People - using options', (t) => {
nock('http://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/people/1')
.reply(200, {});

const request = swapi.getPerson({id: 1}).then((result) => {
t.pass('success return');
t.end();
});
});

test('GET People - error returned', (t) => {
nock('http://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/people/1')
.reply(400, {});

const request = swapi.getPerson({id: 1}).then(null, (result) => {
t.pass('error return');
t.end();
});
});

test('GET films', (t) => {
nock('http://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/films/1')
.reply(200, {});

const request = swapi.getFilm(1).then((result) => {
t.pass('success return');
t.end();
});

t.equal(request instanceof Promise, true, 'should return a Promise');
});

test('GET films - with options', (t) => {
nock('http://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/films/1')
.reply(200, {});

const request = swapi.getFilm({id: 1}).then((result) => {
t.pass('success return');
t.end();
});
});

test('GET films - with error', (t) => {
nock('http://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/films/1')
.reply(400, {});

const request = swapi.getFilm({id: 1}).then(null, (result) => {
t.pass('error return');
t.end();
});
});

test('GET starship', (t) => {
nock('http://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/starship/1')
.reply(200, {});

const request = swapi.getStarship(1).then((result) => {
t.pass('success return');
t.end();
});

t.equal(request instanceof Promise, true, 'should return a Promise');
});

test('GET starship - with options', (t) => {
nock('http://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/starship/1')
.reply(200, {});

const request = swapi.getStarship({id: 1}).then((result) => {
t.pass('success return');
t.end();
});
});

test('GET starship - with error', (t) => {
nock('http://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/starship/1')
.reply(400, {});

const request = swapi.getStarship({id: 1}).then(null, (result) => {
t.pass('error return');
t.end();
});
});

test('GET vehicles', (t) => {
nock('http://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/vehicles/1')
.reply(200, {});

const request = swapi.getVehicle(1).then((result) => {
t.pass('success return');
t.end();
});

t.equal(request instanceof Promise, true, 'should return a Promise');
});

test('GET vehicles - with options', (t) => {
nock('http://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/vehicles/1')
.reply(200, {});

const request = swapi.getVehicle({id: 1}).then((result) => {
t.pass('success return');
t.end();
});
});

test('GET vehicles - with error', (t) => {
nock('http://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/vehicles/1')
.reply(400, {});

const request = swapi.getVehicle({id: 1}).then(null, (result) => {
t.pass('error return');
t.end();
});
});

test('GET species', (t) => {
nock('http://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/species/1')
.reply(200, {});

const request = swapi.getSpecies(1).then((result) => {
t.pass('success return');
t.end();
});

t.equal(request instanceof Promise, true, 'should return a Promise');
});

test('GET species - with options', (t) => {
nock('http://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/species/1')
.reply(200, {});

const request = swapi.getSpecies({id: 1}).then((result) => {
t.pass('success return');
t.end();
});
});

test('GET species - with error', (t) => {
nock('http://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/species/1')
.reply(400, {});

const request = swapi.getSpecies({id: 1}).then(null, (result) => {
t.pass('error return');
t.end();
});
});
68 changes: 68 additions & 0 deletions test/swapi-paging-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use strict';

const nock = require('nock');
const swapi = require('../lib/swapi-node.js');
const version = require('../package.json').version;
const test = require('tape');

nock.disableNetConnect();

test('returned value should have a nextPage added', (t) => {
nock('http://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/people/')
.reply(200, {
count: 82,
next: 'http://swapi.co/api/people/?page=2',
previous: null
});

swapi.get('http://swapi.co/api/people/').then((result) => {
t.equal(typeof result.nextPage, 'function', 'should be a next function');

nock('http://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/people/?page=2')
.reply(200, {
count: 82,
next: 'http://swapi.co/api/people/?page=3',
previous: null
});

result.nextPage().then((result) => {
t.pass('success returned');
t.end();
});
});
});

test('returned value should have a previousPage added', (t) => {
nock('http://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/people/')
.reply(200, {
count: 82,
previous: 'http://swapi.co/api/people/?page=2'
});

swapi.get('http://swapi.co/api/people/').then((result) => {
t.equal(typeof result.previousPage, 'function', 'should be a next function');

nock('http://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/people/?page=2')
.reply(200, {
count: 82,
previous: 'http://swapi.co/api/people/?page=1'
});

result.nextPage().then((result) => {
t.pass('success returned');
t.end();
});
});
});
Loading