update config programmatically and reload before and after next edit tests

This commit is contained in:
Jacob Kim 2025-06-27 19:28:16 -07:00
parent fba9d84aaf
commit 8c52642cdb
2 changed files with 49 additions and 3 deletions

View file

@ -53,4 +53,8 @@ export class NextEditActions {
return svgDecoration !== null;
}
public static async reload(): Promise<void> {
await new Workbench().executeCommand('workbench.action.reloadWindow');
}
}

View file

@ -1,13 +1,36 @@
import { expect } from "chai";
import * as fs from "fs";
import { EditorView, TextEditor } from "vscode-extension-tester";
import { GlobalActions } from "../actions/Global.actions";
import { NextEditActions } from "../actions/NextEdit.actions";
import { DEFAULT_TIMEOUT } from "../constants";
import { TestUtils } from "../TestUtils";
describe("Next Edit", () => {
let editor: TextEditor;
before(async function () {
this.timeout(DEFAULT_TIMEOUT.XL);
// Update config.json to add optInNextEditFeature.
const globalContext = fs.readFileSync(TestUtils.getGlobalContextFilePath(), "utf8");
const sharedConfig = JSON.parse(globalContext).sharedConfig;
const sharedConfigWithNextEditEnabled = {
...sharedConfig,
"optInNextEditFeature": true
};
const globalContextWithNextEditEnabled = {
...JSON.parse(globalContext),
"sharedConfig": sharedConfigWithNextEditEnabled
};
fs.writeFileSync(TestUtils.getGlobalContextFilePath(), JSON.stringify(globalContextWithNextEditEnabled, null, 2), "utf8");
await NextEditActions.reload();
});
beforeEach(async function () {
this.timeout(DEFAULT_TIMEOUT.XL);
@ -21,6 +44,25 @@ describe("Next Edit", () => {
await new EditorView().closeAllEditors();
});
after(async function () {
this.timeout(DEFAULT_TIMEOUT.XL);
// Update config.json to delete optInNextEditFeature.
const globalContext = fs.readFileSync(TestUtils.getGlobalContextFilePath(), "utf8");
const sharedConfig = JSON.parse(globalContext).sharedConfig;
const sharedConfigWithoutNextEdit = { ...sharedConfig };
delete sharedConfigWithoutNextEdit.optInNextEditFeature;
const globalContextWithNextEditEnabled = {
...JSON.parse(globalContext),
"sharedConfig": sharedConfigWithoutNextEdit
};
fs.writeFileSync(TestUtils.getGlobalContextFilePath(), JSON.stringify(globalContextWithNextEditEnabled, null, 2), "utf8");
await NextEditActions.reload();
});
// it("Should enable Next Edit feature in settings", async () => {
// expect(false).to.be.true;
// }).timeout(DEFAULT_TIMEOUT.XL);
@ -29,17 +71,17 @@ describe("Next Edit", () => {
// expect(false).to.be.true;
// }).timeout(DEFAULT_TIMEOUT.XL);
it.only("Should accept Next Edit suggestion with Tab", async () => {
it("Should accept Next Edit suggestion with Tab", async () => {
const accepted = await NextEditActions.acceptNextEditSuggestion(editor);
expect (accepted).to.be.true;
}).timeout(DEFAULT_TIMEOUT.XL);
it.only("Should reject Next Edit suggestion with Esc", async () => {
it("Should reject Next Edit suggestion with Esc", async () => {
const rejected = await NextEditActions.rejectNextEditSuggestion(editor);
expect(rejected).to.be.true;
}).timeout(DEFAULT_TIMEOUT.XL);
it.only("Should force a Next Edit", async () => {
it("Should force a Next Edit", async () => {
const hasDecoration = await NextEditActions.forceNextEdit(editor);
expect(hasDecoration).to.be.true;
}).timeout(DEFAULT_TIMEOUT.XL);