Skip to content

Commit 27cc7d0

Browse files
authored
fix(core): Ensure that dynamically registered services are always set up (#2593)
1 parent a268f86 commit 27cc7d0

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

packages/feathers/src/application.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ export class Feathers<Services, Settings> extends EventEmitter implements Feathe
147147
}
148148

149149
setup () {
150+
this._isSetup = true;
151+
150152
return Object.keys(this.services).reduce((current, path) => current
151153
.then(() => {
152154
const service: any = this.service(path as any);
@@ -156,14 +158,12 @@ export class Feathers<Services, Settings> extends EventEmitter implements Feathe
156158

157159
return service.setup(this, path);
158160
}
159-
}), Promise.resolve())
160-
.then(() => {
161-
this._isSetup = true;
162-
return this;
163-
});
161+
}), Promise.resolve()).then(() => this);
164162
}
165163

166164
teardown () {
165+
this._isSetup = false;
166+
167167
return Object.keys(this.services).reduce((current, path) => current
168168
.then(() => {
169169
const service: any = this.service(path as any);
@@ -173,10 +173,6 @@ export class Feathers<Services, Settings> extends EventEmitter implements Feathe
173173

174174
return service.teardown(this, path);
175175
}
176-
}), Promise.resolve())
177-
.then(() => {
178-
this._isSetup = false;
179-
return this;
180-
});
176+
}), Promise.resolve()).then(() => this)
181177
}
182178
}

packages/feathers/test/application.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -344,18 +344,18 @@ describe('Feathers application', () => {
344344
assert.strictEqual(teardownCount, 2);
345345
});
346346

347-
it('registering a service after app.setup will be set up', done => {
347+
it('registering app.setup but while still pending will be set up', done => {
348348
const app = feathers();
349349

350-
app.setup().then(() => {
351-
app.use('/dummy', {
352-
async setup (appRef: any, path: any) {
353-
assert.ok((app as any)._isSetup);
354-
assert.strictEqual(appRef, app);
355-
assert.strictEqual(path, 'dummy');
356-
done();
357-
}
358-
});
350+
app.setup();
351+
352+
app.use('/dummy', {
353+
async setup (appRef: any, path: any) {
354+
assert.ok((app as any)._isSetup);
355+
assert.strictEqual(appRef, app);
356+
assert.strictEqual(path, 'dummy');
357+
done();
358+
}
359359
});
360360
});
361361
});

0 commit comments

Comments
 (0)