Skip to content

Commit

Permalink
fix(koa): Ensure .teardown works without a server (#3234)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Jul 14, 2023
1 parent d6a94d2 commit 818572d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/koa/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,16 @@ export function koa<S = any, C = any>(
},

async teardown(server?: any) {
return feathersTeardown
.call(this, server)
.then(
() => new Promise((resolve, reject) => this.server.close((e) => (e ? reject(e) : resolve(this))))
)
return feathersTeardown.call(this, server).then(
() =>
new Promise((resolve, reject) => {
if (this.server) {
this.server.close((e) => (e ? reject(e) : resolve(this)))
} else {
resolve(this)
}
})
)
}
} as Application)

Expand Down
6 changes: 6 additions & 0 deletions packages/koa/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ describe('@feathersjs/koa', () => {
assert.ok(called)
})

it('.teardown works without server (#3224)', async () => {
const app = koa(feathers())

await app.teardown()
})

restTests('Services', 'todo', 8465)
restTests('Root service', '/', 8465)
})

0 comments on commit 818572d

Please # to comment.