From 818572df98456bc3e1a300e879329aa8f849be64 Mon Sep 17 00:00:00 2001 From: David Luecke Date: Fri, 14 Jul 2023 11:10:47 -0700 Subject: [PATCH] fix(koa): Ensure .teardown works without a server (#3234) --- packages/koa/src/index.ts | 15 ++++++++++----- packages/koa/test/index.test.ts | 6 ++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/koa/src/index.ts b/packages/koa/src/index.ts index b3edc858cd..8969ec7ebc 100644 --- a/packages/koa/src/index.ts +++ b/packages/koa/src/index.ts @@ -53,11 +53,16 @@ export function koa( }, 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) diff --git a/packages/koa/test/index.test.ts b/packages/koa/test/index.test.ts index e836e1682f..445b140230 100644 --- a/packages/koa/test/index.test.ts +++ b/packages/koa/test/index.test.ts @@ -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) })