Skip to content

Commit

Permalink
tests: add browserify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Sep 7, 2015
1 parent 5a29862 commit 2830125
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -15,6 +15,7 @@ before_install:
# Setup Node.js version-specific dependencies
- "test $TRAVIS_NODE_VERSION != '0.6' || npm rm --save-dev istanbul"
- "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul"
- "test $TRAVIS_NODE_VERSION = '0.6' -o $TRAVIS_NODE_VERSION = '0.8' || npm install browserify"
script:
# Run test script, depending on istanbul install
- "test ! -z $(npm -ps ls istanbul) || npm test"
Expand Down
46 changes: 46 additions & 0 deletions test/browserify.js
@@ -0,0 +1,46 @@
var assert = require('assert')
var browserify = tryRequire('browserify')
var http = require('http')
var methods = null
var path = require('path')
var run = browserify ? describe : describe.skip

run('when browserified', function () {
before(function (done) {
var b = browserify()

// require methods
b.require(path.join(__dirname, '..'), {
expose: 'methods'
})

// bundle and eval
b.bundle(function (err, buf) {
var require = eval(buf.toString())
methods = require('methods')
done()
})
})

describe('methods', function () {
['get', 'post', 'put', 'patch', 'delete'].forEach(function (method) {
it('should contain "' + method + '"', function () {
assert.notEqual(methods.indexOf(method), -1)
})
})

it('should only have lower-case entries', function() {
for (var i = 0; i < methods.length; i ++) {
assert(methods[i], methods[i].toLowerCase(), methods[i] + ' is lower-case');
}
})
})
})

function tryRequire(name) {
try {
return require(name)
} catch (e) {
return undefined
}
}

0 comments on commit 2830125

Please sign in to comment.