Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

tests: fix flakey codemirror test (#8550)

Myles Scolnick912563132d7a
diff --git a/frontend/src/core/codemirror/__tests__/format.test.ts b/frontend/src/core/codemirror/__tests__/format.test.ts
index ab456fbd47..2028298873 100644
--- a/frontend/src/core/codemirror/__tests__/format.test.ts
+++ b/frontend/src/core/codemirror/__tests__/format.test.ts
@@ -4,7 +4,7 @@ import { python } from "@codemirror/lang-python";
import { EditorState } from "@codemirror/state";
import { EditorView } from "@codemirror/view";
import { atom } from "jotai";
-import { beforeEach, describe, expect, it, vi } from "vitest";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { MockRequestClient } from "@/__mocks__/requests";
import type { NotebookState } from "@/core/cells/cells";
import { getNotebook } from "@/core/cells/cells";
@@ -44,6 +44,7 @@ vi.mock("@/core/config/config", () => ({
}));
const updateCellCode = vi.fn();
+const createdViews: EditorView[] = [];
function createEditor(content: string, cellId: CellId) {
const state = EditorState.create({
@@ -74,6 +75,7 @@ function createEditor(content: string, cellId: CellId) {
parent: document.body,
});
+ createdViews.push(view);
return view;
}
@@ -88,6 +90,12 @@ beforeEach(() => {
store.set(requestClientAtom, mockRequestClient);
});
+afterEach(() => {
+ for (const view of createdViews) {
+ view.destroy();
+ }
+});
+
describe("format", () => {
describe("formatEditorViews", () => {
it("should format code in editor views", async () => {