8000 fix(core): Ensure that dynamically registered services are always set up by daffl · Pull Request #2593 · feathersjs/feathers · GitHub
[go: up one dir, main page]

Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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. 8000 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
8753 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