Skip to content

Commit

Permalink
test: mocha -> tape
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuawuyts committed Dec 23, 2014
1 parent e36f0f4 commit 7623287
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 101 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
node_js:
- "0.10"
- "0.11"
sudo: false
language: node_js
install: "npm install"
script:
- ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha --report lcovonly --recursive -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
script: "npm run test-cov"
after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "A simple router built for minimalism and speed",
"main": "index.js",
"scripts": {
"test": "NODE_ENV=test ./node_modules/mocha/bin/mocha --recursive --harmony-generators -R spec",
"coverage": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha --report text --recursive -- -R spec && rm -rf ./coverage/"
"test": "NODE_ENV=test tape test.js | tap-bail | tap-spec",
"test-cov": "NODE_ENV=test istanbul cover test.js"
},
"repository": {
"type": "git",
Expand All @@ -30,6 +30,9 @@
"coveralls": "^2.10.0",
"istanbul": "^0.2.11",
"mocha": "^1.20.1",
"should": "^4.0.4"
"should": "^4.0.4",
"tap-bail": "0.0.0",
"tap-spec": "^2.1.2",
"tape": "^3.0.3"
}
}
166 changes: 71 additions & 95 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,96 +1,72 @@
/**
* Module dependencies
*/

var should = require('should');
var wayfarer = require('./index.js');

/**
* Test
*/

describe('wayfarer()', function () {
it('should initialize with empty properties', function() {
var router = wayfarer();
router.defaultPath.should.be.empty;
});
});

describe('.on()', function () {
it('should catch type errors', function () {
var router = wayfarer();
router.on.bind(router, 123)
.should.throw('Path should be a string');
router.on.bind(router, '/hi', 123)
.should.throw('Callback should be a function');
router.on.bind(router, '/hi', function(){})
.should.not.throw();
});
it('should set a default path', function() {
var router = wayfarer({ default: '/404' });
router.defaultPath.should.eql('/404');
});
});

describe('.match()', function () {
it('should match simple routes', function (done) {
var router = wayfarer();
router
.on('/hello', function(){done()})
.on('/hi', function(){});

router.match('/hello');
});

it('should match dynamic routes', function (done) {
var router = wayfarer();
router
.on('/hello', function() {})
.on('/:user', function() {done()});

router.match('/tobi');
});

it('should provide param object on dynamic routes', function (done) {
var router = wayfarer();
router
.path('/:user', function(uri, param) {
param.should.have.property('user', 'tobi');
done();
});

router.match('/tobi');
});

it('should match the default path if no other paths match', function (done) {
var router = wayfarer({ default: '/404' });
router
.on('/hello', function() {})
.on('/howdy', function() {})
.on('/404', function() {done()})

router.match('/anotherPath');
});

it('should not match queryStrings', function(done) {
var router = wayfarer({ default: '/404' });
router
.on('/hello', function() {done()})
.on('/howdy', function() {})
.on('/404', function() {});

router.match('/hello?hello=false');
});
});

describe('aliases', function() {
it('.route == .on', function() {
var router = wayfarer()
router.route.should.eql(router.on)
});

it('.path == .on', function() {
var router = wayfarer()
router.path.should.eql(router.on)
});
});
const test = require('tape')
const should = require('should')
const wayfarer = require('./index.js')

test('wayfarer() should initialize with empty properties', function(t) {
t.plan(1)
const router = wayfarer()
t.equal(router.defaultPath, '')
})

test('wayfarer should set accept a default path', function(t) {
t.plan(1)
const router = wayfarer({ default: '/404' })
t.equal(router.defaultPath, '/404')
})

test('.on() should catch type errors', function(t) {
t.plan(2)
const router = wayfarer()
t.throws(router.on.bind(router, 123), /string/)
t.throws(router.on.bind(router, '/hi', 123), /function/)
})

test('.match() should match simple routes', function(t) {
t.plan(1)
const router = wayfarer()
router.on('/hello', function() { t.ok(true, 'correct path called') })
router.on('/hi', function() { t.ok(false, 'incorrect path called') })
router.match('/hello')
})

test('.match() should match dynamic routes', function(t) {
t.plan(1)
const router = wayfarer()
router.on('/hi', function() { t.ok(false, 'incorrect path called') })
router.on('/:user', function() { t.ok(true, 'correct path called') })
router.match('/tobi')
})

test('.match() should provide param object on dynamic routes', function(t) {
t.plan(1)
const router = wayfarer()
router.on('/hi', function() { t.ok(false, 'incorrect path called') })
router.on('/:user', function(uri, param) { t.equal(param.user, 'tobi') })
router.match('/tobi')
})

test('.match() should match the default path if no matches found', function(t) {
t.plan(1)
const router = wayfarer({ default: '/404' })
router.on('/hi', function() { t.ok(false, 'incorrect path called') })
router.on('/howdy', function() { t.ok(false, 'incorrect path called') })
router.on('/404', function() { t.ok(true, 'correct path called') })
router.match('/derpderp')
})

test('.match() should not match queryStrings', function(t) {
t.plan(1)
const router = wayfarer()
router.on('/hi', function() { t.ok(false, 'incorrect path called') })
router.on('/howdy', function() { t.ok(false, 'incorrect path called') })
router.on('/404', function() { t.ok(true, 'correct path called') })
router.match('/404?derp=darp')
})

test('aliases', function(t) {
t.plan(2)
const router = wayfarer()
t.equal(router.route, router.on, '.route() == .on()')
t.equal(router.path, router.on, '.path() == .on()')
})

0 comments on commit 7623287

Please sign in to comment.