Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Ensure that dynamically registered services are always set up #2593

Merged
merged 2 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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