Convert flaky API tests to unit tests (#273398)

Convert flaky API test to unit test (#253863 , #254041)

I maintain my conviction that there is an unrelated run-away API test which steals focus while these tests execute which then leads to these tests failing, since the undo command is sensitive to the current focused editor.
This commit is contained in:
Alexandru Dima
2025-10-26 15:11:46 +01:00
committed by GitHub
parent 547c05a522
commit 65b22997d7
3 changed files with 147 additions and 93 deletions

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { commands, env, Position, Range, Selection, SnippetString, TextDocument, TextEditor, TextEditorCursorStyle, TextEditorLineNumbersStyle, Uri, window, workspace } from 'vscode';
import { env, Position, Range, Selection, SnippetString, TextDocument, TextEditor, TextEditorCursorStyle, TextEditorLineNumbersStyle, Uri, window, workspace } from 'vscode';
import { assertNoRpc, closeAllEditors, createRandomFile, deleteFile } from '../utils';
suite('vscode API - editors', () => {
@@ -167,53 +167,6 @@ suite('vscode API - editors', () => {
});
});
function executeReplace(editor: TextEditor, range: Range, text: string, undoStopBefore: boolean, undoStopAfter: boolean): Thenable<boolean> {
return editor.edit((builder) => {
builder.replace(range, text);
}, { undoStopBefore: undoStopBefore, undoStopAfter: undoStopAfter });
}
test.skip('TextEditor.edit can control undo/redo stack 1', () => {
return withRandomFileEditor('Hello world!', async (editor, doc) => {
const applied1 = await executeReplace(editor, new Range(0, 0, 0, 1), 'h', false, false);
assert.ok(applied1);
assert.strictEqual(doc.getText(), 'hello world!');
assert.ok(doc.isDirty);
const applied2 = await executeReplace(editor, new Range(0, 1, 0, 5), 'ELLO', false, false);
assert.ok(applied2);
assert.strictEqual(doc.getText(), 'hELLO world!');
assert.ok(doc.isDirty);
await commands.executeCommand('undo');
if (doc.getText() === 'hello world!') {
// see https://github.com/microsoft/vscode/issues/109131
// it looks like an undo stop was inserted in between these two edits
// it is unclear why this happens, but it can happen for a multitude of reasons
await commands.executeCommand('undo');
}
assert.strictEqual(doc.getText(), 'Hello world!');
});
});
test.skip('TextEditor.edit can control undo/redo stack 2', () => {
return withRandomFileEditor('Hello world!', (editor, doc) => {
return executeReplace(editor, new Range(0, 0, 0, 1), 'h', false, false).then(applied => {
assert.ok(applied);
assert.strictEqual(doc.getText(), 'hello world!');
assert.ok(doc.isDirty);
return executeReplace(editor, new Range(0, 1, 0, 5), 'ELLO', true, false);
}).then(applied => {
assert.ok(applied);
assert.strictEqual(doc.getText(), 'hELLO world!');
assert.ok(doc.isDirty);
return commands.executeCommand('undo');
}).then(_ => {
assert.strictEqual(doc.getText(), 'hello world!');
});
});
});
test('issue #16573: Extension API: insertSpaces and tabSize are undefined', () => {
return withRandomFileEditor('Hello world!\n\tHello world!', (editor, _doc) => {

View File

@@ -1179,40 +1179,6 @@ suite('vscode API - workspace', () => {
});
test.skip('issue #110141 - TextEdit.setEndOfLine applies an edit and invalidates redo stack even when no change is made', async () => {
const file = await createRandomFile('hello\nworld');
const document = await vscode.workspace.openTextDocument(file);
await vscode.window.showTextDocument(document);
// apply edit
{
const we = new vscode.WorkspaceEdit();
we.insert(file, new vscode.Position(0, 5), '2');
await vscode.workspace.applyEdit(we);
}
// check the document
{
assert.strictEqual(document.getText(), 'hello2\nworld');
assert.strictEqual(document.isDirty, true);
}
// apply no-op edit
{
const we = new vscode.WorkspaceEdit();
we.set(file, [vscode.TextEdit.setEndOfLine(vscode.EndOfLine.LF)]);
await vscode.workspace.applyEdit(we);
}
// undo
{
await vscode.commands.executeCommand('undo');
assert.strictEqual(document.getText(), 'hello\nworld');
assert.strictEqual(document.isDirty, false);
}
});
test('SnippetString in WorkspaceEdit', async function (): Promise<any> {
const file = await createRandomFile('hello\nworld');