Fix flaky test: avoid file watcher in db manager tests (#1951)

This commit is contained in:
Shati Patel
2023-01-12 10:51:46 +00:00
committed by GitHub
parent 4f588d9def
commit b54dfe9b58
4 changed files with 25 additions and 18 deletions

View File

@@ -42,7 +42,10 @@ export class DbConfigStore extends DisposableObject {
private configErrors: DbConfigValidationError[];
private configWatcher: chokidar.FSWatcher | undefined;
public constructor(private readonly app: App) {
public constructor(
private readonly app: App,
private readonly shouldWatchConfig = true,
) {
super();
const storagePath = app.workspaceStoragePath || app.globalStoragePath;
@@ -58,7 +61,9 @@ export class DbConfigStore extends DisposableObject {
public async initialize(): Promise<void> {
await this.loadConfig();
this.watchConfig();
if (this.shouldWatchConfig) {
this.watchConfig();
}
}
public dispose(disposeHandler?: DisposeHandler): void {

View File

@@ -44,7 +44,7 @@ describe("db config store", () => {
"workspace-databases.json",
);
const configStore = new DbConfigStore(app);
const configStore = new DbConfigStore(app, false);
await configStore.initialize();
expect(await pathExists(configPath)).toBe(true);
@@ -65,7 +65,7 @@ describe("db config store", () => {
extensionPath,
workspaceStoragePath: testDataStoragePath,
});
const configStore = new DbConfigStore(app);
const configStore = new DbConfigStore(app, false);
await configStore.initialize();
const config = configStore.getConfig().value;
@@ -120,7 +120,7 @@ describe("db config store", () => {
workspaceStoragePath: testDataStoragePathWithout,
});
const configStore = new DbConfigStore(app);
const configStore = new DbConfigStore(app, false);
await configStore.initialize();
const config = configStore.getConfig().value;
@@ -134,7 +134,7 @@ describe("db config store", () => {
extensionPath,
workspaceStoragePath: testDataStoragePath,
});
const configStore = new DbConfigStore(app);
const configStore = new DbConfigStore(app, false);
await configStore.initialize();
const config = configStore.getConfig().value;
@@ -155,7 +155,7 @@ describe("db config store", () => {
extensionPath,
workspaceStoragePath: testDataStoragePathInvalid,
});
const configStore = new DbConfigStore(app);
const configStore = new DbConfigStore(app, false);
await configStore.initialize();
expect(app.executeCommand).toBeCalledWith(
@@ -171,7 +171,7 @@ describe("db config store", () => {
extensionPath,
workspaceStoragePath: testDataStoragePath,
});
const configStore = new DbConfigStore(app);
const configStore = new DbConfigStore(app, false);
await configStore.initialize();
expect(app.executeCommand).toBeCalledWith(
@@ -215,7 +215,7 @@ describe("db config store", () => {
await writeJSON(configPath, dbConfig);
const configStore = new DbConfigStore(app);
const configStore = new DbConfigStore(app, false);
await configStore.initialize();
// Rename
@@ -262,7 +262,7 @@ describe("db config store", () => {
await writeJSON(configPath, dbConfig);
const configStore = new DbConfigStore(app);
const configStore = new DbConfigStore(app, false);
await configStore.initialize();
// Rename
@@ -309,7 +309,7 @@ describe("db config store", () => {
await writeJSON(configPath, dbConfig);
const configStore = new DbConfigStore(app);
const configStore = new DbConfigStore(app, false);
await configStore.initialize();
// Rename
@@ -353,7 +353,7 @@ describe("db config store", () => {
await writeJSON(configPath, dbConfig);
const configStore = new DbConfigStore(app);
const configStore = new DbConfigStore(app, false);
await configStore.initialize();
// Rename
@@ -393,7 +393,7 @@ describe("db config store", () => {
await writeJSON(configPath, dbConfig);
const configStore = new DbConfigStore(app);
const configStore = new DbConfigStore(app, false);
await configStore.initialize();
// Remove
@@ -432,7 +432,7 @@ describe("db config store", () => {
await writeJSON(configPath, dbConfig);
const configStore = new DbConfigStore(app);
const configStore = new DbConfigStore(app, false);
await configStore.initialize();
// Remove
@@ -471,7 +471,7 @@ describe("db config store", () => {
await writeJSON(configPath, dbConfig);
const configStore = new DbConfigStore(app);
const configStore = new DbConfigStore(app, false);
await configStore.initialize();
// Remove

View File

@@ -20,7 +20,7 @@ import { createMockApp } from "../../__mocks__/appMock";
// Note: Although these are "unit tests" (i.e. not integrating with VS Code), they do
// test the interaction/"integration" between the DbManager and the DbConfigStore.
describe.skip("db manager", () => {
describe("db manager", () => {
let dbManager: DbManager;
let dbConfigStore: DbConfigStore;
let tempWorkspaceStoragePath: string;
@@ -35,7 +35,9 @@ describe.skip("db manager", () => {
workspaceStoragePath: tempWorkspaceStoragePath,
});
dbConfigStore = new DbConfigStore(app);
// We don't need to watch changes to the config file in these tests, so we
// pass `false` to the dbConfigStore constructor.
dbConfigStore = new DbConfigStore(app, false);
dbManager = new DbManager(app, dbConfigStore);
await ensureDir(tempWorkspaceStoragePath);

View File

@@ -43,7 +43,7 @@ describe("db panel", () => {
const app = new ExtensionApp(extensionContext);
dbConfigStore = new DbConfigStore(app);
dbConfigStore = new DbConfigStore(app, false);
dbManager = new DbManager(app, dbConfigStore);
});