Skip to content

Commit 8a45dcc

Browse files
fix(core): ensure all components are properly closed
1 parent e848eaf commit 8a45dcc

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

packages/core/src/App.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export class App {
146146
app.close = () => {
147147
debug("closing all components");
148148
return Promise.all(
149-
components.map((component) => component.close()),
149+
allComponents.map((component) => component.close()),
150150
).then();
151151
};
152152

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { describe, it } from "node:test";
2+
import * as assert from "node:assert";
3+
import { App, type AppInit, Component } from "../../src";
4+
import { createTestDB } from "../setup.js";
5+
6+
describe("App", () => {
7+
it("should initialize and close components", async () => {
8+
let initCalled = false;
9+
let closeCalled = false;
10+
11+
class TestComponent extends Component {
12+
override async init() {
13+
initCalled = true;
14+
}
15+
16+
override async close() {
17+
closeCalled = true;
18+
}
19+
}
20+
21+
const app = await App.create({
22+
components: [createTestDB()],
23+
modules: [
24+
{
25+
name: "test",
26+
version: "0.0.1",
27+
init(app: AppInit) {
28+
app.component(TestComponent);
29+
},
30+
},
31+
],
32+
});
33+
34+
assert.equal(initCalled, true);
35+
assert.equal(closeCalled, false);
36+
37+
await app.close();
38+
39+
assert.equal(closeCalled, true);
40+
});
41+
});

0 commit comments

Comments
 (0)