Skip to content

Commit

Permalink
test: fixing tests after recent update of http-server
Browse files Browse the repository at this point in the history
The HTTP server uses the trustProxy config value on every request
and hence we need to setup config for same
  • Loading branch information
thetutlage committed Nov 11, 2019
1 parent 2864d5e commit 9f86897
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/HttpExceptionHandler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export abstract class HttpExceptionHandler {
*/
if (ctx['view'] && this.statusPages[error.status]) {
ctx['view'].render(this.statusPages[error.status], { error })
return
}

ctx.response.status(error.status).send(`<h1> ${error.message} </h1>`)
Expand Down
33 changes: 25 additions & 8 deletions test/ignitor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,14 @@ test.group('Ignitor | Http', (group) => {
},
}))

await fs.add(`config/app.ts`, `export const appKey = '${SECRET}'`)
await fs.add(`config/app.ts`, `
export const appKey = '${SECRET}'
export const http = {
trustProxy () {
return true
}
}
`)

await fs.add(`start/app.ts`, `export const providers = [
'${join(__dirname, '../providers/AppProvider.ts')}',
Expand Down Expand Up @@ -164,7 +171,14 @@ test.group('Ignitor | Http', (group) => {
'App': './app',
},
}))
await fs.add(`config/app.ts`, `export const appKey = '${SECRET}'`)
await fs.add(`config/app.ts`, `
export const appKey = '${SECRET}'
export const http = {
trustProxy () {
return true
}
}
`)

await fs.add(`start/app.ts`, `export const providers = [
'${join(__dirname, '../providers/AppProvider.ts')}'
Expand All @@ -180,7 +194,7 @@ test.group('Ignitor | Http', (group) => {

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

setTimeout(() => {
assert.isFalse(ignitor.application.isReady)
Expand All @@ -190,8 +204,14 @@ test.group('Ignitor | Http', (group) => {
})

test('forward errors to app error handler', async (assert) => {
await fs.fsExtra.ensureDir(join(fs.basePath, 'config'))
await fs.add(`config/app.ts`, `export const appKey = '${SECRET}'`)
await fs.add(`config/app.ts`, `
export const appKey = '${SECRET}'
export const http = {
trustProxy () {
return true
}
}
`)

await fs.add(`start/app.ts`, `export const providers = [
'${join(__dirname, '../providers/AppProvider.ts')}'
Expand Down Expand Up @@ -228,7 +248,6 @@ test.group('Ignitor | Http', (group) => {
test('kill app when server receives error', async (assert) => {
assert.plan(1)

await fs.fsExtra.ensureDir(join(fs.basePath, 'config'))
await fs.add(`config/app.ts`, `export const appKey = '${SECRET}'`)

await fs.add(`start/app.ts`, `export const providers = [
Expand Down Expand Up @@ -258,7 +277,6 @@ test.group('Ignitor | Http', (group) => {
test('close http server gracefully when closing the app', async (assert, done) => {
assert.plan(2)

await fs.fsExtra.ensureDir(join(fs.basePath, 'config'))
await fs.add(`config/app.ts`, `export const appKey = '${SECRET}'`)

await fs.add(`start/app.ts`, `export const providers = [
Expand Down Expand Up @@ -292,7 +310,6 @@ test.group('Ignitor | Http', (group) => {
},
}))

await fs.fsExtra.ensureDir(join(fs.basePath, 'config'))
await fs.add(`config/app.ts`, `export const appKey = '${SECRET}'`)

await fs.add(`start/app.ts`, `export const providers = [
Expand Down

0 comments on commit 9f86897

Please sign in to comment.