Skip to content

Commit f71237f

Browse files
authored
Prevent tests from overriding port database (#3542)
1 parent 1506268 commit f71237f

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

vscode/src/test/suite/streamingRunner.test.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import os from "os";
44

55
import * as vscode from "vscode";
66
import sinon from "sinon";
7-
import { afterEach, beforeEach } from "mocha";
7+
import { after, afterEach, before, beforeEach } from "mocha";
88

99
import { StreamingRunner } from "../../streamingRunner";
1010

@@ -13,6 +13,26 @@ import { CONTEXT } from "./helpers";
1313
suite("StreamingRunner", () => {
1414
let sandbox: sinon.SinonSandbox;
1515
const tempDirUri = vscode.Uri.file(path.join(os.tmpdir(), "ruby-lsp"));
16+
const dbUri = vscode.Uri.joinPath(tempDirUri, "test_reporter_port_db.json");
17+
let currentDbContents: string | undefined;
18+
19+
before(async () => {
20+
try {
21+
const buffer = await vscode.workspace.fs.readFile(dbUri);
22+
currentDbContents = buffer.toString();
23+
} catch {
24+
// Do nothing
25+
}
26+
});
27+
28+
after(async () => {
29+
if (currentDbContents) {
30+
await vscode.workspace.fs.writeFile(
31+
dbUri,
32+
Buffer.from(currentDbContents),
33+
);
34+
}
35+
});
1636

1737
beforeEach(async () => {
1838
await vscode.workspace.fs.createDirectory(tempDirUri);
@@ -25,7 +45,6 @@ suite("StreamingRunner", () => {
2545
});
2646

2747
test("updates port DB with new values", async () => {
28-
const dbUri = vscode.Uri.joinPath(tempDirUri, "test_reporter_port_db.json");
2948
const initialDb = {
3049
// eslint-disable-next-line @typescript-eslint/naming-convention
3150
"/some/path/to/project": "1234",

0 commit comments

Comments
 (0)