diff --git a/packages/feathers/src/application.ts b/packages/feathers/src/application.ts index 1346533ca7..e12af49fc5 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); @@ -156,14 +158,12 @@ export class Feathers extends EventEmitter implements Feathe return service.setup(this, path); } - }), Promise.resolve()) - .then(() => { - this._isSetup = true; - return this; - }); + }), Promise.resolve()).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 +173,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(); + } }); }); });