Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(core): Ensure that dynamically registered services are always set up
  • Loading branch information
daffl committed Apr 5, 2022
commit 484c8bc07e259a6e2abd9b45d586d9e629c6159e
15 changes: 6 additions & 9 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 @@ -157,13 +159,12 @@ export class Feathers<Services, Settings> 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);
Expand All @@ -173,10 +174,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