more SPA tests
This commit is contained in:
26
test/test.js
26
test/test.js
@ -42,21 +42,27 @@ test('serve-index', function (t) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('single page app', function (t) {
|
test('single page app', function (t) {
|
||||||
t.plan(4)
|
t.plan(6)
|
||||||
const app = localWebServer({
|
const app = localWebServer({
|
||||||
log: { format: 'none' },
|
log: { format: 'none' },
|
||||||
static: { root: __dirname + '/fixture/spa' },
|
static: { root: __dirname + '/fixture/spa' },
|
||||||
spa: 'one.txt'
|
spa: 'one.txt'
|
||||||
})
|
})
|
||||||
const server = launchServer(app, { leaveOpen: true })
|
const server = http.createServer(app.callback())
|
||||||
request('http://localhost:8100/test').then(response => {
|
server.listen(8100, () => {
|
||||||
t.strictEqual(response.res.statusCode, 200)
|
/* text/html requests for missing files redirect to spa */
|
||||||
t.ok(/one/.test(response.data))
|
request('http://localhost:8100/asdf', { headers: { accept: 'text/html' } })
|
||||||
request('http://localhost:8100/two.txt').then(response => {
|
.then(checkResponse(t, 200, /one/))
|
||||||
t.strictEqual(response.res.statusCode, 200)
|
/* html requests for missing files with extensions do not redirect to spa */
|
||||||
t.ok(/two/.test(response.data))
|
.then(() => request('http://localhost:8100/asdf.txt', { headers: { accept: 'text/html' } }))
|
||||||
server.close()
|
.then(checkResponse(t, 404))
|
||||||
})
|
/* existing static file */
|
||||||
|
.then(() => request('http://localhost:8100/two.txt'))
|
||||||
|
.then(checkResponse(t, 200, /two/))
|
||||||
|
/* not a text/html request - does not redirect to spa */
|
||||||
|
.then(() => request('http://localhost:8100/asdf'))
|
||||||
|
.then(checkResponse(t, 404))
|
||||||
|
.then(server.close.bind(server))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user