Skip to content

Commit 810ad4f

Browse files
Make notebook tests more reliable (#2899)
1 parent e5e9929 commit 810ad4f

File tree

6 files changed

+207
-174
lines changed

6 files changed

+207
-174
lines changed

packages/cursorless-vscode-e2e/src/suite/crossCellsSetSelection.vscode.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from "@cursorless/vscode-common";
66
import assert from "assert";
77
import { window } from "vscode";
8-
import { endToEndTestSetup, sleepWithBackoff } from "../endToEndTestSetup";
8+
import { endToEndTestSetup } from "../endToEndTestSetup";
99

1010
// Check that setSelection is able to focus the correct cell
1111
suite("Cross-cell set selection", async function () {
@@ -19,10 +19,6 @@ async function runTest() {
1919

2020
await openNewNotebookEditor(['"hello"', '"world"']);
2121

22-
// FIXME: There seems to be some timing issue when you create a notebook
23-
// editor
24-
await sleepWithBackoff(1000);
25-
2622
await hatTokenMap.allocateHats();
2723

2824
await runCursorlessCommand({

packages/cursorless-vscode-e2e/src/suite/editNewCell.vscode.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ async function runTest(
2828
const { hatTokenMap } = (await getCursorlessApi()).testHelpers!;
2929
const notebook = await openNewNotebookEditor(["hello"]);
3030

31-
// FIXME: There seems to be some timing issue when you create a notebook
32-
// editor
33-
await sleepWithBackoff(500);
34-
3531
await hatTokenMap.allocateHats();
3632

3733
assert.equal(notebook.cellCount, 1);

packages/cursorless-vscode-e2e/src/suite/intraCellSetSelection.vscode.test.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {
22
getCursorlessApi,
33
openNewNotebookEditor,
4+
runCursorlessCommand,
45
} from "@cursorless/vscode-common";
56
import assert from "assert";
67
import { window } from "vscode";
7-
import { endToEndTestSetup, sleepWithBackoff } from "../endToEndTestSetup";
8-
import { runCursorlessCommand } from "@cursorless/vscode-common";
8+
import { endToEndTestSetup } from "../endToEndTestSetup";
99

1010
// Check that setSelection is able to focus the correct cell
1111
suite("Within cell set selection", async function () {
@@ -19,10 +19,6 @@ async function runTest() {
1919

2020
await openNewNotebookEditor(['"hello world"']);
2121

22-
// FIXME: There seems to be some timing issue when you create a notebook
23-
// editor
24-
await sleepWithBackoff(1000);
25-
2622
await hatTokenMap.allocateHats();
2723

2824
await runCursorlessCommand({
@@ -40,7 +36,7 @@ async function runTest() {
4036
],
4137
});
4238

43-
const editor = window.activeTextEditor; // eslint-disable-line no-restricted-properties
39+
const editor = window.activeTextEditor;
4440

4541
if (editor == null) {
4642
assert(false, "No editor was focused");

packages/test-harness/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"@types/glob": "^8.1.0",
4040
"@types/mocha": "^10.0.9",
4141
"@types/tail": "2.2.3",
42-
"@vscode/test-electron": "^2.4.1",
42+
"@vscode/test-electron": "^2.5.2",
4343
"cross-spawn": "7.0.5",
4444
"mocha": "^10.7.3"
4545
},

packages/vscode-common/src/testUtil/openNewEditor.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,27 @@ export async function openNewNotebookEditor(
9696

9797
await (await getParseTreeApi()).loadLanguage(language);
9898

99+
// FIXME: There seems to be some timing issue when you create a notebook
100+
// editor
101+
await waitForEditorToOpen();
102+
99103
return document;
100104
}
105+
106+
function waitForEditorToOpen() {
107+
return new Promise<void>((resolve, reject) => {
108+
let count = 0;
109+
const interval = setInterval(() => {
110+
if (vscode.window.activeTextEditor != null) {
111+
clearInterval(interval);
112+
resolve();
113+
} else {
114+
count++;
115+
if (count === 20) {
116+
clearInterval(interval);
117+
reject("Timed out waiting for editor to open");
118+
}
119+
}
120+
}, 100);
121+
});
122+
}

0 commit comments

Comments
 (0)