Dispose config store in tests

The config store was not being disposed in tests, resulting in Chokidar
watchers being left open. This was causing tests to not exit since there
were still open file descriptors.

This commit also fixes the `DbConfigStore` to make the correct `super`
call in its `dispose` method.
This commit is contained in:
Koen Vlaswinkel
2022-11-22 11:53:21 +01:00
parent 0974700557
commit ec60f3f000
2 changed files with 11 additions and 2 deletions

View File

@@ -2,7 +2,7 @@ import * as fs from "fs-extra";
import * as path from "path";
import { cloneDbConfig, DbConfig } from "./db-config";
import * as chokidar from "chokidar";
import { DisposableObject } from "../../pure/disposable-object";
import { DisposableObject, DisposeHandler } from "../../pure/disposable-object";
import { DbConfigValidator } from "./db-config-validator";
import { ValueResult } from "../../common/value-result";
import { App } from "../../common/app";
@@ -38,7 +38,8 @@ export class DbConfigStore extends DisposableObject {
this.watchConfig();
}
public dispose(): void {
public dispose(disposeHandler?: DisposeHandler): void {
super.dispose(disposeHandler);
this.configWatcher?.unwatch(this.configPath);
}

View File

@@ -39,6 +39,8 @@ describe("db config store", () => {
expect(config.databases.local.lists).toHaveLength(0);
expect(config.databases.local.databases).toHaveLength(0);
expect(config.selected).toBeUndefined();
configStore.dispose();
});
it("should load an existing config", async () => {
@@ -85,6 +87,8 @@ describe("db config store", () => {
kind: "configDefined",
value: "path.to.database",
});
configStore.dispose();
});
it("should load an existing config without selected db", async () => {
@@ -104,6 +108,8 @@ describe("db config store", () => {
const config = configStore.getConfig().value;
expect(config.selected).toBeUndefined();
configStore.dispose();
});
it("should not allow modification of the config", async () => {
@@ -119,5 +125,7 @@ describe("db config store", () => {
const reRetrievedConfig = configStore.getConfig().value;
expect(reRetrievedConfig.databases.remote.repositoryLists).toHaveLength(1);
configStore.dispose();
});
});