Skip to content

Commit

Permalink
fix(core): Ensure that dynamically registered services are always set…
Browse files Browse the repository at this point in the history
… up (#2593)
  • Loading branch information
daffl authored Apr 6, 2022
1 parent a268f86 commit 27cc7d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
16 changes: 6 additions & 10 deletions packages/feathers/src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ export class Feathers<Services, Settings> 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);
Expand All @@ -156,14 +158,12 @@ export class Feathers<Services, Settings> 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);
Expand All @@ -173,10 +173,6 @@ export class Feathers<Services, Settings> extends EventEmitter implements Feathe

return service.teardown(this, path);
}
}), Promise.resolve())
.then(() => {
this._isSetup = false;
return this;
});
}), Promise.resolve()).then(() => this)
}
}
20 changes: 10 additions & 10 deletions packages/feathers/test/application.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
});
});
Expand Down

0 comments on commit 27cc7d0

Please sign in to comment.