rewrite: static and serve-index tests

This commit is contained in:
Lloyd Brookes
2015-11-08 22:09:07 +00:00
parent 867275a29d
commit c7a6bd15b6
8 changed files with 101 additions and 173 deletions

1
test/static/file.txt Normal file
View File

@ -0,0 +1 @@
test

44
test/test.js Normal file
View File

@ -0,0 +1,44 @@
'use strict'
const test = require('tape')
const request = require('req-then')
const localWebServer = require('../')
const http = require('http')
test('static', function (t) {
t.plan(1)
const app = localWebServer({
static: {
root: __dirname + '/static',
options: {
index: 'file.txt'
}
}
})
const server = http.createServer(app.callback())
server.listen(8100)
request('http://localhost:8100')
.then(response => {
t.strictEqual(response.data, 'test\n')
})
.then(() => server.close())
})
test('serve-index', function (t) {
t.plan(2)
const app = localWebServer({
serveIndex: {
path: __dirname + '/static',
options: {
icons: true
}
}
})
const server = http.createServer(app.callback())
server.listen(8100)
request('http://localhost:8100/')
.then(response => {
t.ok(/listing directory/.test(response.data))
t.ok(/class="icon/.test(response.data))
})
.then(() => server.close())
})