@marimo-team/frontend 0.20.5-dev51 → 0.20.5-dev53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/__mocks__/common.ts +41 -8
- package/src/components/chat/__tests__/useFileState.test.tsx +2 -3
- package/src/components/chat/acp/__tests__/context-utils.test.ts +2 -6
- package/src/components/editor/__tests__/data-attributes.test.tsx +2 -11
- package/src/components/editor/file-tree/__tests__/requesting-tree.test.ts +2 -3
- package/src/components/editor/navigation/__tests__/clipboard.test.ts +2 -4
- package/src/components/editor/output/console/__tests__/ConsoleOutput.test.tsx +2 -12
- package/src/core/cells/__tests__/session.test.ts +2 -7
- package/src/core/codemirror/compat/__tests__/jupyter.test.ts +2 -3
- package/src/core/codemirror/markdown/__tests__/commands.test.ts +2 -3
- package/src/core/export/__tests__/hooks.test.ts +3 -10
- package/src/core/runtime/__tests__/runtime.test.ts +2 -8
- package/src/plugins/impl/__tests__/DataTablePlugin.test.tsx +2 -11
- package/src/plugins/impl/__tests__/DropdownPlugin.test.tsx +2 -11
- package/src/utils/__tests__/download.test.tsx +12 -14
package/package.json
CHANGED
package/src/__mocks__/common.ts
CHANGED
|
@@ -3,9 +3,19 @@
|
|
|
3
3
|
import { type Mock, vi } from "vitest";
|
|
4
4
|
import { invariant } from "@/utils/invariant";
|
|
5
5
|
|
|
6
|
+
interface MockLogger {
|
|
7
|
+
debug: Mock;
|
|
8
|
+
log: Mock;
|
|
9
|
+
warn: Mock;
|
|
10
|
+
error: Mock;
|
|
11
|
+
trace: Mock;
|
|
12
|
+
get: Mock;
|
|
13
|
+
disabled: Mock;
|
|
14
|
+
}
|
|
15
|
+
|
|
6
16
|
// Common mock factories
|
|
7
17
|
export const Mocks = {
|
|
8
|
-
quietLogger: () => ({
|
|
18
|
+
quietLogger: (): MockLogger => ({
|
|
9
19
|
debug: vi.fn(),
|
|
10
20
|
log: vi.fn(),
|
|
11
21
|
warn: vi.fn(),
|
|
@@ -15,7 +25,7 @@ export const Mocks = {
|
|
|
15
25
|
disabled: vi.fn(),
|
|
16
26
|
}),
|
|
17
27
|
|
|
18
|
-
logger: () => ({
|
|
28
|
+
logger: (): MockLogger => ({
|
|
19
29
|
debug: vi.fn().mockImplementation(console.debug),
|
|
20
30
|
log: vi.fn().mockImplementation(console.log),
|
|
21
31
|
warn: vi.fn().mockImplementation(console.warn),
|
|
@@ -70,8 +80,33 @@ export const Mocks = {
|
|
|
70
80
|
},
|
|
71
81
|
};
|
|
72
82
|
|
|
83
|
+
// Common mock modules for vi.mock() calls
|
|
84
|
+
export const MockModules = {
|
|
85
|
+
toast: () => ({ toast: vi.fn() }),
|
|
86
|
+
toastWithControls: () => {
|
|
87
|
+
const dismiss = vi.fn();
|
|
88
|
+
const update = vi.fn();
|
|
89
|
+
return {
|
|
90
|
+
mock: { toast: vi.fn(() => ({ dismiss, update })) },
|
|
91
|
+
dismiss,
|
|
92
|
+
update,
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
|
|
73
97
|
// Global mock setup functions
|
|
74
98
|
export const SetupMocks = {
|
|
99
|
+
resizeObserver: () => {
|
|
100
|
+
const observe = vi.fn();
|
|
101
|
+
const unobserve = vi.fn();
|
|
102
|
+
const disconnect = vi.fn();
|
|
103
|
+
global.ResizeObserver = class MockResizeObserver {
|
|
104
|
+
observe = observe;
|
|
105
|
+
unobserve = unobserve;
|
|
106
|
+
disconnect = disconnect;
|
|
107
|
+
} as unknown as typeof ResizeObserver;
|
|
108
|
+
return { observe, unobserve, disconnect };
|
|
109
|
+
},
|
|
75
110
|
clipboard: (mockClipboard = Mocks.clipboard()) => {
|
|
76
111
|
Object.defineProperty(navigator, "clipboard", {
|
|
77
112
|
value: mockClipboard,
|
|
@@ -79,12 +114,10 @@ export const SetupMocks = {
|
|
|
79
114
|
});
|
|
80
115
|
|
|
81
116
|
// Mock ClipboardItem
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
.fn()
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
global.ClipboardItem.supports = vi.fn().mockReturnValue(true);
|
|
117
|
+
global.ClipboardItem = Object.assign(
|
|
118
|
+
vi.fn().mockImplementation((data) => Mocks.clipboardItem(data)),
|
|
119
|
+
{ supports: vi.fn().mockReturnValue(true) },
|
|
120
|
+
) as unknown as typeof ClipboardItem;
|
|
88
121
|
|
|
89
122
|
// Mock Blob
|
|
90
123
|
global.Blob = vi
|
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import { act, renderHook } from "@testing-library/react";
|
|
4
4
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { MockModules } from "@/__mocks__/common";
|
|
5
6
|
import { toast } from "@/components/ui/use-toast";
|
|
6
7
|
import { useFileState } from "../chat-utils";
|
|
7
8
|
|
|
8
|
-
vi.mock("@/components/ui/use-toast", () => (
|
|
9
|
-
toast: vi.fn(),
|
|
10
|
-
}));
|
|
9
|
+
vi.mock("@/components/ui/use-toast", () => MockModules.toast());
|
|
11
10
|
|
|
12
11
|
describe("useFileState", () => {
|
|
13
12
|
beforeEach(() => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
3
|
import { beforeEach, describe, expect, it, type Mocked, vi } from "vitest";
|
|
4
|
+
import { Mocks } from "@/__mocks__/common";
|
|
4
5
|
import {
|
|
5
6
|
convertFilesToResourceLinks,
|
|
6
7
|
parseContextFromPrompt,
|
|
@@ -19,12 +20,7 @@ vi.mock("@/core/state/jotai", () => ({
|
|
|
19
20
|
store: {},
|
|
20
21
|
}));
|
|
21
22
|
|
|
22
|
-
vi.mock("@/utils/Logger", () => ({
|
|
23
|
-
Logger: {
|
|
24
|
-
error: vi.fn(),
|
|
25
|
-
debug: vi.fn(),
|
|
26
|
-
},
|
|
27
|
-
}));
|
|
23
|
+
vi.mock("@/utils/Logger", () => ({ Logger: Mocks.quietLogger() }));
|
|
28
24
|
|
|
29
25
|
import { getAIContextRegistry } from "@/core/ai/context/context";
|
|
30
26
|
import type {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { render } from "@testing-library/react";
|
|
3
3
|
import { createStore, Provider } from "jotai";
|
|
4
4
|
import { beforeAll, describe, expect, it } from "vitest";
|
|
5
|
+
import { SetupMocks } from "@/__mocks__/common";
|
|
5
6
|
import { MockNotebook } from "@/__mocks__/notebook";
|
|
6
7
|
import { MockRequestClient } from "@/__mocks__/requests";
|
|
7
8
|
import { TooltipProvider } from "@/components/ui/tooltip";
|
|
@@ -25,17 +26,7 @@ function createTestWrapper() {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
beforeAll(() => {
|
|
28
|
-
|
|
29
|
-
observe() {
|
|
30
|
-
// do nothing
|
|
31
|
-
}
|
|
32
|
-
unobserve() {
|
|
33
|
-
// do nothing
|
|
34
|
-
}
|
|
35
|
-
disconnect() {
|
|
36
|
-
// do nothing
|
|
37
|
-
}
|
|
38
|
-
};
|
|
29
|
+
SetupMocks.resizeObserver();
|
|
39
30
|
global.HTMLDivElement.prototype.scrollIntoView = () => {
|
|
40
31
|
// do nothing
|
|
41
32
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
|
3
|
+
import { MockModules } from "@/__mocks__/common";
|
|
3
4
|
import { toast } from "@/components/ui/use-toast";
|
|
4
5
|
import type { FilePath } from "@/utils/paths";
|
|
5
6
|
import { RequestingTree } from "../requesting-tree";
|
|
@@ -9,9 +10,7 @@ const sendCreateFileOrFolder = vi.fn();
|
|
|
9
10
|
const sendDeleteFileOrFolder = vi.fn();
|
|
10
11
|
const sendRenameFileOrFolder = vi.fn();
|
|
11
12
|
|
|
12
|
-
vi.mock("@/components/ui/use-toast", () => (
|
|
13
|
-
toast: vi.fn(),
|
|
14
|
-
}));
|
|
13
|
+
vi.mock("@/components/ui/use-toast", () => MockModules.toast());
|
|
15
14
|
|
|
16
15
|
describe("RequestingTree", () => {
|
|
17
16
|
let requestingTree: RequestingTree;
|
|
@@ -3,15 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
import { act, renderHook } from "@testing-library/react";
|
|
5
5
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
|
-
import { asMock, Mocks, SetupMocks } from "@/__mocks__/common";
|
|
6
|
+
import { asMock, MockModules, Mocks, SetupMocks } from "@/__mocks__/common";
|
|
7
7
|
import type { CellActions, NotebookState } from "@/core/cells/cells";
|
|
8
8
|
import type { CellId } from "@/core/cells/ids";
|
|
9
9
|
import { useCellClipboard } from "../clipboard";
|
|
10
10
|
|
|
11
11
|
// Mock dependencies
|
|
12
|
-
vi.mock("@/components/ui/use-toast", () => (
|
|
13
|
-
toast: vi.fn(),
|
|
14
|
-
}));
|
|
12
|
+
vi.mock("@/components/ui/use-toast", () => MockModules.toast());
|
|
15
13
|
|
|
16
14
|
vi.mock("@/core/cells/cells", () => ({
|
|
17
15
|
getNotebook: vi.fn(),
|
|
@@ -2,24 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
import { fireEvent, render, screen } from "@testing-library/react";
|
|
4
4
|
import { describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { SetupMocks } from "@/__mocks__/common";
|
|
5
6
|
import { TooltipProvider } from "@/components/ui/tooltip";
|
|
6
7
|
import type { CellId } from "@/core/cells/ids";
|
|
7
8
|
import type { WithResponse } from "@/core/cells/types";
|
|
8
9
|
import type { OutputMessage } from "@/core/kernel/messages";
|
|
9
10
|
import { ConsoleOutput } from "../ConsoleOutput";
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
global.ResizeObserver = class ResizeObserver {
|
|
13
|
-
observe() {
|
|
14
|
-
// noop
|
|
15
|
-
}
|
|
16
|
-
unobserve() {
|
|
17
|
-
// noop
|
|
18
|
-
}
|
|
19
|
-
disconnect() {
|
|
20
|
-
// noop
|
|
21
|
-
}
|
|
22
|
-
};
|
|
12
|
+
SetupMocks.resizeObserver();
|
|
23
13
|
|
|
24
14
|
const renderWithProvider = (ui: React.ReactElement) => {
|
|
25
15
|
return render(<TooltipProvider>{ui}</TooltipProvider>);
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import type * as api from "@marimo-team/marimo-api";
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
5
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { Mocks } from "@/__mocks__/common";
|
|
6
7
|
import { parseOutline } from "@/core/dom/outline";
|
|
7
8
|
import { MultiColumn, visibleForTesting } from "@/utils/id-tree";
|
|
8
9
|
import { invariant } from "@/utils/invariant";
|
|
@@ -11,13 +12,7 @@ import { type CellId, SETUP_CELL_ID } from "../ids";
|
|
|
11
12
|
import { notebookStateFromSession } from "../session";
|
|
12
13
|
|
|
13
14
|
// Mock dependencies
|
|
14
|
-
vi.mock("@/utils/Logger", () => ({
|
|
15
|
-
Logger: {
|
|
16
|
-
error: vi.fn(),
|
|
17
|
-
warn: vi.fn(),
|
|
18
|
-
debug: vi.fn(),
|
|
19
|
-
},
|
|
20
|
-
}));
|
|
15
|
+
vi.mock("@/utils/Logger", () => ({ Logger: Mocks.quietLogger() }));
|
|
21
16
|
|
|
22
17
|
vi.mock("@/core/dom/outline", () => ({
|
|
23
18
|
parseOutline: vi.fn(),
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { EditorState } from "@codemirror/state";
|
|
4
4
|
import { EditorView } from "@codemirror/view";
|
|
5
5
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { MockModules } from "@/__mocks__/common";
|
|
6
7
|
import { MockRequestClient } from "@/__mocks__/requests";
|
|
7
8
|
import { toast } from "@/components/ui/use-toast";
|
|
8
9
|
import { store } from "@/core/state/jotai";
|
|
@@ -16,9 +17,7 @@ vi.mock("@/core/state/jotai", () => ({
|
|
|
16
17
|
},
|
|
17
18
|
}));
|
|
18
19
|
|
|
19
|
-
vi.mock("@/components/ui/use-toast", () => (
|
|
20
|
-
toast: vi.fn(),
|
|
21
|
-
}));
|
|
20
|
+
vi.mock("@/components/ui/use-toast", () => MockModules.toast());
|
|
22
21
|
|
|
23
22
|
// Mock the helper to get request client
|
|
24
23
|
const mockRequestClient = MockRequestClient.create();
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
test,
|
|
10
10
|
vi,
|
|
11
11
|
} from "vitest";
|
|
12
|
+
import { MockModules } from "@/__mocks__/common";
|
|
12
13
|
import { MockRequestClient } from "@/__mocks__/requests";
|
|
13
14
|
import { requestClientAtom } from "@/core/network/requests";
|
|
14
15
|
import { filenameAtom } from "@/core/saving/file-state";
|
|
@@ -25,9 +26,7 @@ import {
|
|
|
25
26
|
insertUL,
|
|
26
27
|
} from "../commands";
|
|
27
28
|
|
|
28
|
-
vi.mock("@/components/ui/use-toast", () => (
|
|
29
|
-
toast: vi.fn(),
|
|
30
|
-
}));
|
|
29
|
+
vi.mock("@/components/ui/use-toast", () => MockModules.toast());
|
|
31
30
|
|
|
32
31
|
import { toast } from "@/components/ui/use-toast";
|
|
33
32
|
|
|
@@ -5,6 +5,7 @@ import { createStore, Provider } from "jotai";
|
|
|
5
5
|
import type { ReactNode } from "react";
|
|
6
6
|
import * as React from "react";
|
|
7
7
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
8
|
+
import { MockModules, Mocks } from "@/__mocks__/common";
|
|
8
9
|
import type { CellId } from "@/core/cells/ids";
|
|
9
10
|
import { CellOutputId } from "@/core/cells/ids";
|
|
10
11
|
import type { CellRuntimeState } from "@/core/cells/types";
|
|
@@ -20,17 +21,9 @@ vi.mock("html-to-image", () => ({
|
|
|
20
21
|
toPng: vi.fn(),
|
|
21
22
|
}));
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
vi.mock("@/utils/Logger", () => ({
|
|
25
|
-
Logger: {
|
|
26
|
-
error: vi.fn(),
|
|
27
|
-
},
|
|
28
|
-
}));
|
|
24
|
+
vi.mock("@/utils/Logger", () => ({ Logger: Mocks.quietLogger() }));
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
vi.mock("@/components/ui/use-toast", () => ({
|
|
32
|
-
toast: vi.fn(),
|
|
33
|
-
}));
|
|
26
|
+
vi.mock("@/components/ui/use-toast", () => MockModules.toast());
|
|
34
27
|
|
|
35
28
|
// Mock cellsRuntimeAtom - must be defined inline in the factory function
|
|
36
29
|
vi.mock("@/core/cells/cells", async () => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
3
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { Mocks } from "@/__mocks__/common";
|
|
4
5
|
import type { SessionId } from "@/core/kernel/session";
|
|
5
6
|
import { Logger } from "@/utils/Logger";
|
|
6
7
|
import { RuntimeManager } from "../runtime";
|
|
@@ -11,14 +12,7 @@ vi.mock("@/core/kernel/session", () => ({
|
|
|
11
12
|
getSessionId: () => "test-session-id" as SessionId,
|
|
12
13
|
}));
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
vi.mock("@/utils/Logger", () => ({
|
|
16
|
-
Logger: {
|
|
17
|
-
debug: vi.fn(),
|
|
18
|
-
error: vi.fn(),
|
|
19
|
-
warn: vi.fn(),
|
|
20
|
-
},
|
|
21
|
-
}));
|
|
15
|
+
vi.mock("@/utils/Logger", () => ({ Logger: Mocks.quietLogger() }));
|
|
22
16
|
|
|
23
17
|
describe("RuntimeManager", () => {
|
|
24
18
|
const mockConfig: RuntimeConfig = {
|
|
@@ -4,6 +4,7 @@ import { TooltipProvider } from "@radix-ui/react-tooltip";
|
|
|
4
4
|
import { act, render, screen, waitFor } from "@testing-library/react";
|
|
5
5
|
import { Provider } from "jotai";
|
|
6
6
|
import { beforeAll, describe, expect, it, vi } from "vitest";
|
|
7
|
+
import { SetupMocks } from "@/__mocks__/common";
|
|
7
8
|
import type { DownloadAsArgs } from "@/components/data-table/schemas";
|
|
8
9
|
import type { FieldTypesWithExternalType } from "@/components/data-table/types";
|
|
9
10
|
import { store } from "@/core/state/jotai";
|
|
@@ -14,17 +15,7 @@ import {
|
|
|
14
15
|
} from "../DataTablePlugin";
|
|
15
16
|
|
|
16
17
|
beforeAll(() => {
|
|
17
|
-
|
|
18
|
-
observe() {
|
|
19
|
-
// do nothing
|
|
20
|
-
}
|
|
21
|
-
unobserve() {
|
|
22
|
-
// do nothing
|
|
23
|
-
}
|
|
24
|
-
disconnect() {
|
|
25
|
-
// do nothing
|
|
26
|
-
}
|
|
27
|
-
};
|
|
18
|
+
SetupMocks.resizeObserver();
|
|
28
19
|
});
|
|
29
20
|
|
|
30
21
|
describe("LoadingDataTableComponent", () => {
|
|
@@ -3,23 +3,14 @@
|
|
|
3
3
|
import { fireEvent, render, screen } from "@testing-library/react";
|
|
4
4
|
import { beforeAll, describe, expect, it, vi } from "vitest";
|
|
5
5
|
import type { z } from "zod";
|
|
6
|
+
import { SetupMocks } from "@/__mocks__/common";
|
|
6
7
|
import { initialModeAtom } from "@/core/mode";
|
|
7
8
|
import { store } from "@/core/state/jotai";
|
|
8
9
|
import type { IPluginProps } from "../../types";
|
|
9
10
|
import { DropdownPlugin } from "../DropdownPlugin";
|
|
10
11
|
|
|
11
12
|
beforeAll(() => {
|
|
12
|
-
|
|
13
|
-
observe() {
|
|
14
|
-
// do nothing
|
|
15
|
-
}
|
|
16
|
-
unobserve() {
|
|
17
|
-
// do nothing
|
|
18
|
-
}
|
|
19
|
-
disconnect() {
|
|
20
|
-
// do nothing
|
|
21
|
-
}
|
|
22
|
-
};
|
|
13
|
+
SetupMocks.resizeObserver();
|
|
23
14
|
global.HTMLDivElement.prototype.scrollIntoView = () => {
|
|
24
15
|
// do nothing
|
|
25
16
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { Mocks } from "@/__mocks__/common";
|
|
3
4
|
import type { CellId } from "@/core/cells/ids";
|
|
4
5
|
import { CellOutputId } from "@/core/cells/ids";
|
|
5
6
|
import {
|
|
@@ -27,26 +28,23 @@ vi.mock("@/core/network/requests", () => ({
|
|
|
27
28
|
}));
|
|
28
29
|
|
|
29
30
|
// Mock the toast module
|
|
30
|
-
const mockDismiss = vi.
|
|
31
|
-
const
|
|
32
|
-
vi.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
31
|
+
const { mockDismiss, mockUpdate, toastMock } = vi.hoisted(() => {
|
|
32
|
+
const dismiss = vi.fn();
|
|
33
|
+
const update = vi.fn();
|
|
34
|
+
return {
|
|
35
|
+
mockDismiss: dismiss,
|
|
36
|
+
mockUpdate: update,
|
|
37
|
+
toastMock: { toast: vi.fn(() => ({ dismiss, update })) },
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
vi.mock("@/components/ui/use-toast", () => toastMock);
|
|
38
41
|
|
|
39
42
|
// Mock the Spinner component
|
|
40
43
|
vi.mock("@/components/icons/spinner", () => ({
|
|
41
44
|
Spinner: () => "MockSpinner",
|
|
42
45
|
}));
|
|
43
46
|
|
|
44
|
-
|
|
45
|
-
vi.mock("@/utils/Logger", () => ({
|
|
46
|
-
Logger: {
|
|
47
|
-
error: vi.fn(),
|
|
48
|
-
},
|
|
49
|
-
}));
|
|
47
|
+
vi.mock("@/utils/Logger", () => ({ Logger: Mocks.quietLogger() }));
|
|
50
48
|
|
|
51
49
|
// Mock Filenames
|
|
52
50
|
vi.mock("@/utils/filenames", () => ({
|