From 8c52642cdb2629b22e6a2562465a138366bc15ee Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Fri, 27 Jun 2025 19:28:16 -0700 Subject: [PATCH] update config programmatically and reload before and after next edit tests --- .../vscode/e2e/actions/NextEdit.actions.ts | 4 ++ extensions/vscode/e2e/tests/NextEdit.test.ts | 48 +++++++++++++++++-- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/extensions/vscode/e2e/actions/NextEdit.actions.ts b/extensions/vscode/e2e/actions/NextEdit.actions.ts index 03cecc542..2795992a7 100644 --- a/extensions/vscode/e2e/actions/NextEdit.actions.ts +++ b/extensions/vscode/e2e/actions/NextEdit.actions.ts @@ -53,4 +53,8 @@ export class NextEditActions { return svgDecoration !== null; } + + public static async reload(): Promise { + await new Workbench().executeCommand('workbench.action.reloadWindow'); + } } diff --git a/extensions/vscode/e2e/tests/NextEdit.test.ts b/extensions/vscode/e2e/tests/NextEdit.test.ts index 9a83055ed..c4b9540dc 100644 --- a/extensions/vscode/e2e/tests/NextEdit.test.ts +++ b/extensions/vscode/e2e/tests/NextEdit.test.ts @@ -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);