Skip to content

Commit

Permalink
test: add test for application state
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jul 30, 2019
1 parent 31ea269 commit 2e47664
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions test/ignitor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* file that was distributed with this source code.
*/

/// <reference path="../adonis-typings/index.ts" />

import { join } from 'path'
import * as test from 'japa'
import { createServer } from 'http'
Expand Down Expand Up @@ -260,7 +262,7 @@ test.group('Ignitor', (group) => {
assert.isTrue(server.hookCalled)
})

test('start http server to accept incoming requests', async (assert) => {
test('start http server to accept incoming requests', async (assert, done) => {
await fs.fsExtra.ensureDir(join(fs.basePath, 'config'))
await fs.add('.adonisrc.json', JSON.stringify({
autoloads: {
Expand Down Expand Up @@ -289,12 +291,17 @@ test.group('Ignitor', (group) => {
ignitor.application.container.use('Adonis/Core/Route').get('/', () => 'handled')

await ignitor.startHttpServer((handler) => createServer(handler))
const server = ignitor.application.container.use('Adonis/Core/Server')
assert.isTrue(ignitor.application.isReady)

const server = ignitor.application.container.use('Adonis/Core/Server')
const { text } = await supertest(server.instance).get('/').expect(200)
server.instance.close()

assert.equal(text, 'handled')
setTimeout(() => {
assert.isFalse(ignitor.application.isReady)
assert.equal(text, 'handled')
done()
}, 100)
})

test('forward errors to app error handler', async (assert) => {
Expand Down

0 comments on commit 2e47664

Please sign in to comment.