From 484c8bc07e259a6e2abd9b45d586d9e629c6159e Mon Sep 17 00:00:00 2001 From: daffl Date: Tue, 5 Apr 2022 16:15:55 -0700 Subject: [PATCH 1/2] fix(core): Ensure that dynamically registered services are always set up --- packages/feathers/src/application.ts | 15 ++++++--------- packages/feathers/test/application.test.ts | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/packages/feathers/src/application.ts b/packages/feathers/src/application.ts index 1346533ca7..aec69a6e2c 100644 --- a/packages/feathers/src/application.ts +++ b/packages/feathers/src/application.ts @@ -147,6 +147,8 @@ export class Feathers extends EventEmitter implements Feathe } setup () { + this._isSetup = true; + return Object.keys(this.services).reduce((current, path) => current .then(() => { const service: any = this.service(path as any); @@ -157,13 +159,12 @@ export class Feathers extends EventEmitter implements Feathe return service.setup(this, path); } }), Promise.resolve()) - .then(() => { - this._isSetup = true; - return this; - }); + .then(() => this); } teardown () { + this._isSetup = false; + return Object.keys(this.services).reduce((current, path) => current .then(() => { const service: any = this.service(path as any); @@ -173,10 +174,6 @@ export class Feathers extends EventEmitter implements Feathe return service.teardown(this, path); } - }), Promise.resolve()) - .then(() => { - this._isSetup = false; - return this; - }); + }), Promise.resolve()).then(() => this) } } diff --git a/packages/feathers/test/application.test.ts b/packages/feathers/test/application.test.ts index d2d2b7ab82..27b4a809d8 100644 --- a/packages/feathers/test/application.test.ts +++ b/packages/feathers/test/application.test.ts @@ -344,18 +344,18 @@ describe('Feathers application', () => { assert.strictEqual(teardownCount, 2); }); - it('registering a service after app.setup will be set up', done => { + it('registering app.setup but while still pending will be set up', done => { const app = feathers(); - app.setup().then(() => { - app.use('/dummy', { - async setup (appRef: any, path: any) { - assert.ok((app as any)._isSetup); - assert.strictEqual(appRef, app); - assert.strictEqual(path, 'dummy'); - done(); - } - }); + app.setup(); + + app.use('/dummy', { + async setup (appRef: any, path: any) { + assert.ok((app as any)._isSetup); + assert.strictEqual(appRef, app); + assert.strictEqual(path, 'dummy'); + done(); + } }); }); }); From 042d02f805334dae55650346b7b6fbd045c747f0 Mon Sep 17 00:00:00 2001 From: daffl Date: Tue, 5 Apr 2022 16:17:00 -0700 Subject: [PATCH 2/2] Code formatting --- packages/feathers/src/application.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/feathers/src/application.ts b/packages/feathers/src/application.ts index aec69a6e2c..e12af49fc5 100644 --- a/packages/feathers/src/application.ts +++ b/packages/feathers/src/application.ts @@ -158,8 +158,7 @@ export class Feathers extends EventEmitter implements Feathe return service.setup(this, path); } - }), Promise.resolve()) - .then(() => this); + }), Promise.resolve()).then(() => this); } teardown () {