-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.ts
37 lines (32 loc) · 1.45 KB
/
index.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { beforeEach, describe, it } from "vitest";
import * as assert from "assert";
import * as fs from "fs";
import * as os from "os";
import { promisify } from "util";
import { exec } from "child_process";
const vscodeSettingsPath = `${os.homedir()}/Library/Application Support/Code/User/settings.json`;
const vscodeInsidersSettingsPath = `${os.homedir()}/Library/Application Support/Code - Insiders/User/settings.json`;
describe("VSCode settings importer", () => {
beforeEach(async () => {
// Make sure the VSCode Insiders settings file is deleted before each test
try {
await promisify(fs.unlink)(vscodeInsidersSettingsPath);
} catch (err: unknown) {
if ((err as NodeJS.ErrnoException).code !== "ENOENT") {
throw err;
}
}
});
it("should import VSCode settings to VSCode Insiders", async () => {
// Copy the VSCode settings file to a temporary file
const tmpFile = `${os.tmpdir()}/vscode-settings.json`;
await promisify(fs.copyFile)(vscodeSettingsPath, tmpFile);
// Run the script with the temporary file as input
const cmd = `node index.js ${tmpFile}`;
await promisify(exec)(cmd);
// Check that the VSCode Insiders settings file was created and has the same content as the temporary file
const data = await promisify(fs.readFile)(vscodeInsidersSettingsPath, "utf8");
const expectedData = await promisify(fs.readFile)(tmpFile, "utf8");
assert.strictEqual(data, expectedData);
});
});