Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add http2 test
Browse files Browse the repository at this point in the history
sogaani committed Jul 30, 2018
1 parent 3bed452 commit 105393b
Showing 4 changed files with 14 additions and 5 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@ node_js:
- "5.12"
- "6.12"
- "7.10"
- "8.9"
- "9.3"
- "8.11"
- "10.7"
sudo: false
cache:
directories:
@@ -23,6 +23,7 @@ before_install:
# Setup Node.js version-specific dependencies
- "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul"
- "test $(echo $TRAVIS_NODE_VERSION | cut -d. -f1) -ge 4 || npm rm --save-dev $(grep -E '\"eslint\\S*\"' package.json | cut -d'\"' -f2)"
- "test $(echo $TRAVIS_NODE_VERSION | cut -d. -f1) -le 7 || npm install --only=dev https://github.com/sogaani/supertest.git#http2"

# Update Node.js modules
- "test ! -d node_modules || npm prune"
@@ -32,5 +33,7 @@ script:
- "test ! -z $(npm -ps ls istanbul) || npm test"
- "test -z $(npm -ps ls istanbul) || npm run-script test-travis"
- "test -z $(npm -ps ls eslint ) || npm run-script lint"
# Run test script with http2
- "test $(echo $TRAVIS_NODE_VERSION | cut -d. -f1) -le 7 || npm run-script test-http2-travis"
after_script:
- "test -e ./coverage/lcov.info && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ function vhost (hostname, handle) {
*/

function hostnameof (req) {
var host = req.host
var host = req.headers.host ? req.headers.host : req.headers[':authority']

if (!host) {
return
@@ -137,7 +137,7 @@ function hostregexp (val) {
*/

function vhostof (req, regexp) {
var host = req.host
var host = req.headers.host ? req.headers.host : req.headers[':authority']
var hostname = hostnameof(req)

if (!hostname) {
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -31,7 +31,9 @@
"scripts": {
"lint": "eslint --plugin markdown --ext js,md .",
"test": "mocha --reporter spec --bail --check-leaks test/",
"test-http2": "EXPOSE_HTTP2=1 mocha --reporter spec --bail --check-leaks test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/",
"test-http2-travis": "EXPOSE_HTTP2=1 istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
}
}
4 changes: 4 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -4,6 +4,10 @@ var http = require('http')
var request = require('supertest')
var vhost = require('..')

if (process.env.EXPOSE_HTTP2) {
http = require('http2')
}

describe('vhost(hostname, server)', function () {
it('should route by Host', function (done) {
var vhosts = []

0 comments on commit 105393b

Please sign in to comment.