Fix excalidraw tests

This commit is contained in:
Marcel Mraz 2025-03-18 20:04:29 +01:00
parent e1ea33836e
commit a9b4b758cf
No known key found for this signature in database
GPG key ID: 4EBD6E62DC830CD2
34 changed files with 231 additions and 156 deletions

View file

@ -1,5 +1,4 @@
import { KEYS } from "@excalidraw/common"; import { KEYS, reseed } from "@excalidraw/common";
import { reseed } from "@excalidraw/common";
import { Excalidraw } from "@excalidraw/excalidraw"; import { Excalidraw } from "@excalidraw/excalidraw";

View file

@ -1,28 +1,34 @@
import { pointFrom } from "@excalidraw/math"; import { pointFrom } from "@excalidraw/math";
import React from "react"; import React from "react";
import { getElementPointsCoords } from "@excalidraw/element/bounds";
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import { resizeSingleElement } from "@excalidraw/element/resizeElements";
import { isLinearElement } from "@excalidraw/element/typeChecks";
import { Excalidraw } from "@excalidraw/excalidraw";
import {
KEYS,
getSizeFromPoints,
reseed,
arrayToMap,
} from "@excalidraw/common";
import { API } from "@excalidraw/excalidraw/tests/helpers/api";
import { UI, Keyboard, Pointer } from "@excalidraw/excalidraw/tests/helpers/ui";
import {
render,
unmountComponent,
} from "@excalidraw/excalidraw/tests/test-utils";
import type { LocalPoint } from "@excalidraw/math"; import type { LocalPoint } from "@excalidraw/math";
import { getElementPointsCoords } from "../element/bounds"; import type { Bounds } from "@excalidraw/element/bounds";
import { LinearElementEditor } from "../element/linearElementEditor";
import { resizeSingleElement } from "../element/resizeElements";
import { isLinearElement } from "../element/typeChecks";
import { Excalidraw } from "../index";
import { KEYS } from "../keys";
import { getSizeFromPoints } from "../points";
import { reseed } from "../random";
import { arrayToMap } from "../utils";
import { API } from "./helpers/api";
import { UI, Keyboard, Pointer } from "./helpers/ui";
import { render, unmountComponent } from "./test-utils";
import type { Bounds } from "../element/bounds";
import type { import type {
ExcalidrawElbowArrowElement, ExcalidrawElbowArrowElement,
ExcalidrawFreeDrawElement, ExcalidrawFreeDrawElement,
ExcalidrawLinearElement, ExcalidrawLinearElement,
} from "../element/types"; } from "@excalidraw/element/types";
unmountComponent(); unmountComponent();

View file

@ -13,6 +13,11 @@ import {
isTextElement, isTextElement,
} from "@excalidraw/element/typeChecks"; } from "@excalidraw/element/typeChecks";
import {
getSelectedGroupIds,
getElementsInGroup,
} from "@excalidraw/element/groups";
import type { Radians } from "@excalidraw/math"; import type { Radians } from "@excalidraw/math";
import type { import type {
@ -22,8 +27,6 @@ import type {
NonDeletedSceneElementsMap, NonDeletedSceneElementsMap,
} from "@excalidraw/element/types"; } from "@excalidraw/element/types";
import { getSelectedGroupIds, getElementsInGroup } from "../../groups";
import type Scene from "../../scene/Scene"; import type Scene from "../../scene/Scene";
import type { AppState } from "../../types"; import type { AppState } from "../../types";

View file

@ -1,8 +1,9 @@
import React from "react"; import React from "react";
import { vi } from "vitest"; import { vi } from "vitest";
import { reseed } from "@excalidraw/common";
import { Excalidraw } from "../index"; import { Excalidraw } from "../index";
import { reseed } from "../random";
import * as StaticScene from "../renderer/staticScene"; import * as StaticScene from "../renderer/staticScene";
import { render, queryByTestId, unmountComponent } from "../tests/test-utils"; import { render, queryByTestId, unmountComponent } from "../tests/test-utils";

View file

@ -1,8 +1,9 @@
import React from "react"; import React from "react";
import { CODES } from "@excalidraw/common";
import { copiedStyles } from "../actions/actionStyles"; import { copiedStyles } from "../actions/actionStyles";
import { Excalidraw } from "../index"; import { Excalidraw } from "../index";
import { CODES } from "../keys";
import { API } from "../tests/helpers/api"; import { API } from "../tests/helpers/api";
import { Keyboard, Pointer, UI } from "../tests/helpers/ui"; import { Keyboard, Pointer, UI } from "../tests/helpers/ui";
import { import {

View file

@ -1,5 +1,7 @@
import React from "react"; import React from "react";
import { KEYS } from "@excalidraw/common";
import { import {
actionAlignVerticallyCentered, actionAlignVerticallyCentered,
actionAlignHorizontallyCentered, actionAlignHorizontallyCentered,
@ -11,7 +13,6 @@ import {
} from "../actions"; } from "../actions";
import { defaultLang, setLanguage } from "../i18n"; import { defaultLang, setLanguage } from "../i18n";
import { Excalidraw } from "../index"; import { Excalidraw } from "../index";
import { KEYS } from "../keys";
import { API } from "./helpers/api"; import { API } from "./helpers/api";
import { UI, Pointer, Keyboard } from "./helpers/ui"; import { UI, Pointer, Keyboard } from "./helpers/ui";

View file

@ -1,15 +1,16 @@
import React from "react"; import React from "react";
import { EXPORT_DATA_TYPES, MIME_TYPES } from "@excalidraw/common";
import type { ExcalidrawTextElement } from "@excalidraw/element/types";
import { getDefaultAppState } from "../appState"; import { getDefaultAppState } from "../appState";
import { EXPORT_DATA_TYPES, MIME_TYPES } from "../constants";
import { Excalidraw } from "../index"; import { Excalidraw } from "../index";
import { API } from "./helpers/api"; import { API } from "./helpers/api";
import { Pointer, UI } from "./helpers/ui"; import { Pointer, UI } from "./helpers/ui";
import { fireEvent, queryByTestId, render, waitFor } from "./test-utils"; import { fireEvent, queryByTestId, render, waitFor } from "./test-utils";
import type { ExcalidrawTextElement } from "../element/types";
const { h } = window; const { h } = window;
describe("appState", () => { describe("appState", () => {

View file

@ -1,13 +1,16 @@
import React from "react"; import React from "react";
import { vi } from "vitest"; import { vi } from "vitest";
import { getElementBounds } from "@excalidraw/element";
import { getLineHeightInPx } from "@excalidraw/element/textMeasurements";
import { KEYS, arrayToMap } from "@excalidraw/common";
import { createPasteEvent, serializeAsClipboardJSON } from "../clipboard"; import { createPasteEvent, serializeAsClipboardJSON } from "../clipboard";
import { getElementBounds } from "../element";
import { getLineHeightInPx } from "../element/textMeasurements"; import { getLineHeight } from "../fonts/FontMetadata";
import { getLineHeight } from "../fonts";
import { Excalidraw } from "../index"; import { Excalidraw } from "../index";
import { KEYS } from "../keys";
import { arrayToMap } from "../utils";
import { API } from "./helpers/api"; import { API } from "./helpers/api";
import { mockMermaidToExcalidraw } from "./helpers/mocks"; import { mockMermaidToExcalidraw } from "./helpers/mocks";

View file

@ -1,12 +1,13 @@
import React from "react"; import React from "react";
import { vi } from "vitest"; import { vi } from "vitest";
import { KEYS, reseed } from "@excalidraw/common";
import { setDateTimeForTests } from "@excalidraw/common";
import { copiedStyles } from "../actions/actionStyles"; import { copiedStyles } from "../actions/actionStyles";
import { Excalidraw } from "../index"; import { Excalidraw } from "../index";
import { KEYS } from "../keys";
import { reseed } from "../random";
import * as StaticScene from "../renderer/staticScene"; import * as StaticScene from "../renderer/staticScene";
import { setDateTimeForTests } from "../utils";
import { API } from "./helpers/api"; import { API } from "./helpers/api";
import { UI, Pointer, Keyboard } from "./helpers/ui"; import { UI, Pointer, Keyboard } from "./helpers/ui";

View file

@ -1,17 +1,22 @@
import React from "react"; import React from "react";
import { vi } from "vitest"; import { vi } from "vitest";
import { KEYS, cloneJSON } from "@excalidraw/common";
import { duplicateElement } from "@excalidraw/element/newElement";
import type {
ExcalidrawImageElement,
ImageCrop,
} from "@excalidraw/element/types";
import { Excalidraw, exportToCanvas, exportToSvg } from ".."; import { Excalidraw, exportToCanvas, exportToSvg } from "..";
import { actionFlipHorizontal, actionFlipVertical } from "../actions"; import { actionFlipHorizontal, actionFlipVertical } from "../actions";
import { duplicateElement } from "../element";
import { KEYS } from "../keys";
import { cloneJSON } from "../utils";
import { API } from "./helpers/api"; import { API } from "./helpers/api";
import { Keyboard, Pointer, UI } from "./helpers/ui"; import { Keyboard, Pointer, UI } from "./helpers/ui";
import { act, GlobalTestState, render, unmountComponent } from "./test-utils"; import { act, GlobalTestState, render, unmountComponent } from "./test-utils";
import type { ExcalidrawImageElement, ImageCrop } from "../element/types";
import type { NormalizedZoomValue } from "../types"; import type { NormalizedZoomValue } from "../types";
const { h } = window; const { h } = window;

View file

@ -1,14 +1,16 @@
import { syncInvalidIndices } from "@excalidraw/element/fractionalIndex"; import { syncInvalidIndices } from "@excalidraw/element/fractionalIndex";
import { reconcileElements } from "../../data/reconcile"; import { randomInteger, cloneJSON } from "@excalidraw/common";
import { randomInteger } from "../../random";
import { cloneJSON } from "../../utils";
import type { RemoteExcalidrawElement } from "../../data/reconcile";
import type { import type {
ExcalidrawElement, ExcalidrawElement,
OrderedExcalidrawElement, OrderedExcalidrawElement,
} from "../../element/types"; } from "@excalidraw/element/types";
import { reconcileElements } from "../../data/reconcile";
import type { RemoteExcalidrawElement } from "../../data/reconcile";
import type { AppState } from "../../types"; import type { AppState } from "../../types";
type Id = string; type Id = string;

View file

@ -1,9 +1,11 @@
import React from "react"; import React from "react";
import { vi } from "vitest"; import { vi } from "vitest";
import { KEYS, reseed } from "@excalidraw/common";
import type { ExcalidrawLinearElement } from "@excalidraw/element/types";
import { Excalidraw } from "../index"; import { Excalidraw } from "../index";
import { KEYS } from "../keys";
import { reseed } from "../random";
import * as InteractiveScene from "../renderer/interactiveScene"; import * as InteractiveScene from "../renderer/interactiveScene";
import * as StaticScene from "../renderer/staticScene"; import * as StaticScene from "../renderer/staticScene";
@ -15,8 +17,6 @@ import {
unmountComponent, unmountComponent,
} from "./test-utils"; } from "./test-utils";
import type { ExcalidrawLinearElement } from "../element/types";
unmountComponent(); unmountComponent();
const renderInteractiveScene = vi.spyOn( const renderInteractiveScene = vi.spyOn(

View file

@ -1,10 +1,13 @@
import React from "react"; import React from "react";
import { mutateElement } from "@excalidraw/element/mutateElement";
import { KEYS } from "@excalidraw/common";
import { actionSelectAll } from "../actions"; import { actionSelectAll } from "../actions";
import { mutateElement } from "../element/mutateElement";
import { t } from "../i18n"; import { t } from "../i18n";
import { Excalidraw } from "../index"; import { Excalidraw } from "../index";
import { KEYS } from "../keys";
import { API } from "../tests/helpers/api"; import { API } from "../tests/helpers/api";
import { Keyboard, Pointer, UI } from "../tests/helpers/ui"; import { Keyboard, Pointer, UI } from "../tests/helpers/ui";
import { render, unmountComponent } from "../tests/test-utils"; import { render, unmountComponent } from "../tests/test-utils";

View file

@ -2,7 +2,8 @@ import { queryByText, queryByTestId } from "@testing-library/react";
import React from "react"; import React from "react";
import { useMemo } from "react"; import { useMemo } from "react";
import { THEME } from "../constants"; import { THEME } from "@excalidraw/common";
import { t } from "../i18n"; import { t } from "../i18n";
import { Excalidraw, Footer, MainMenu } from "../index"; import { Excalidraw, Footer, MainMenu } from "../index";

View file

@ -1,7 +1,10 @@
import React from "react"; import React from "react";
import { SVG_NS } from "@excalidraw/common";
import type { FileId } from "@excalidraw/element/types";
import { getDefaultAppState } from "../appState"; import { getDefaultAppState } from "../appState";
import { SVG_NS } from "../constants";
import { getDataURL } from "../data/blob"; import { getDataURL } from "../data/blob";
import { encodePngMetadata } from "../data/image"; import { encodePngMetadata } from "../data/image";
import { serializeAsJSON } from "../data/json"; import { serializeAsJSON } from "../data/json";
@ -15,8 +18,6 @@ import {
import { API } from "./helpers/api"; import { API } from "./helpers/api";
import { render, waitFor } from "./test-utils"; import { render, waitFor } from "./test-utils";
import type { FileId } from "../element/types";
const { h } = window; const { h } = window;
const testElements = [ const testElements = [

View file

@ -2,17 +2,24 @@ import { pointFrom, type Radians } from "@excalidraw/math";
import React from "react"; import React from "react";
import { vi } from "vitest"; import { vi } from "vitest";
import { ROUNDNESS, KEYS, arrayToMap, cloneJSON } from "@excalidraw/common";
import { getElementAbsoluteCoords } from "@excalidraw/element";
import { newLinearElement } from "@excalidraw/element";
import { getBoundTextElementPosition } from "@excalidraw/element/textElement";
import type { LocalPoint } from "@excalidraw/math"; import type { LocalPoint } from "@excalidraw/math";
import type {
ExcalidrawElement,
ExcalidrawImageElement,
ExcalidrawLinearElement,
ExcalidrawTextElementWithContainer,
FileId,
} from "@excalidraw/element/types";
import { actionFlipHorizontal, actionFlipVertical } from "../actions"; import { actionFlipHorizontal, actionFlipVertical } from "../actions";
import { createPasteEvent } from "../clipboard"; import { createPasteEvent } from "../clipboard";
import { ROUNDNESS } from "../constants";
import { getElementAbsoluteCoords } from "../element";
import { newLinearElement } from "../element";
import { getBoundTextElementPosition } from "../element/textElement";
import { Excalidraw } from "../index"; import { Excalidraw } from "../index";
import { KEYS } from "../keys";
import { arrayToMap, cloneJSON } from "../utils";
import { API } from "./helpers/api"; import { API } from "./helpers/api";
import { UI, Pointer, Keyboard } from "./helpers/ui"; import { UI, Pointer, Keyboard } from "./helpers/ui";
@ -25,13 +32,6 @@ import {
waitFor, waitFor,
} from "./test-utils"; } from "./test-utils";
import type {
ExcalidrawElement,
ExcalidrawImageElement,
ExcalidrawLinearElement,
ExcalidrawTextElementWithContainer,
FileId,
} from "../element/types";
import type { NormalizedZoomValue } from "../types"; import type { NormalizedZoomValue } from "../types";
const { h } = window; const { h } = window;

View file

@ -8,8 +8,32 @@ import {
import { vi } from "vitest"; import { vi } from "vitest";
import { pointFrom } from "@excalidraw/math"; import { pointFrom } from "@excalidraw/math";
import { newElementWith } from "@excalidraw/element/mutateElement";
import {
EXPORT_DATA_TYPES,
MIME_TYPES,
ORIG_ID,
KEYS,
arrayToMap,
COLOR_PALETTE,
DEFAULT_ELEMENT_BACKGROUND_COLOR_INDEX,
DEFAULT_ELEMENT_STROKE_COLOR_INDEX,
} from "@excalidraw/common";
import type { LocalPoint, Radians } from "@excalidraw/math"; import type { LocalPoint, Radians } from "@excalidraw/math";
import type {
ExcalidrawElbowArrowElement,
ExcalidrawFrameElement,
ExcalidrawGenericElement,
ExcalidrawLinearElement,
ExcalidrawTextElement,
FixedPointBinding,
FractionalIndex,
SceneElementsMap,
} from "@excalidraw/element/types";
import "../global.d.ts"; import "../global.d.ts";
import "../../utils/test-utils"; import "../../utils/test-utils";
@ -23,17 +47,8 @@ import { actionToggleViewMode } from "../actions/actionToggleViewMode";
import { getDefaultAppState } from "../appState"; import { getDefaultAppState } from "../appState";
import { HistoryEntry } from "../history"; import { HistoryEntry } from "../history";
import { Excalidraw } from "../index"; import { Excalidraw } from "../index";
import { KEYS } from "../keys";
import * as StaticScene from "../renderer/staticScene"; import * as StaticScene from "../renderer/staticScene";
import { EXPORT_DATA_TYPES, MIME_TYPES, ORIG_ID } from "../constants";
import { Snapshot, CaptureUpdateAction } from "../store"; import { Snapshot, CaptureUpdateAction } from "../store";
import { arrayToMap } from "../utils";
import {
COLOR_PALETTE,
DEFAULT_ELEMENT_BACKGROUND_COLOR_INDEX,
DEFAULT_ELEMENT_STROKE_COLOR_INDEX,
} from "../colors";
import { newElementWith } from "../element/mutateElement";
import { AppStateChange, ElementsChange } from "../change"; import { AppStateChange, ElementsChange } from "../change";
import { API } from "./helpers/api"; import { API } from "./helpers/api";
@ -47,16 +62,6 @@ import {
getCloneByOrigId, getCloneByOrigId,
} from "./test-utils"; } from "./test-utils";
import type {
ExcalidrawElbowArrowElement,
ExcalidrawFrameElement,
ExcalidrawGenericElement,
ExcalidrawLinearElement,
ExcalidrawTextElement,
FixedPointBinding,
FractionalIndex,
SceneElementsMap,
} from "../element/types";
import type { AppState } from "../types"; import type { AppState } from "../types";
const { h } = window; const { h } = window;

View file

@ -2,18 +2,21 @@ import { act, queryByTestId } from "@testing-library/react";
import React from "react"; import React from "react";
import { vi } from "vitest"; import { vi } from "vitest";
import { MIME_TYPES, ORIG_ID } from "../constants"; import { MIME_TYPES, ORIG_ID } from "@excalidraw/common";
import { getCommonBoundingBox } from "@excalidraw/element/bounds";
import type { ExcalidrawGenericElement } from "@excalidraw/element/types";
import { parseLibraryJSON } from "../data/blob"; import { parseLibraryJSON } from "../data/blob";
import { serializeLibraryAsJSON } from "../data/json"; import { serializeLibraryAsJSON } from "../data/json";
import { distributeLibraryItemsOnSquareGrid } from "../data/library"; import { distributeLibraryItemsOnSquareGrid } from "../data/library";
import { getCommonBoundingBox } from "../element/bounds";
import { Excalidraw } from "../index"; import { Excalidraw } from "../index";
import { API } from "./helpers/api"; import { API } from "./helpers/api";
import { UI } from "./helpers/ui"; import { UI } from "./helpers/ui";
import { fireEvent, getCloneByOrigId, render, waitFor } from "./test-utils"; import { fireEvent, getCloneByOrigId, render, waitFor } from "./test-utils";
import type { ExcalidrawGenericElement } from "../element/types";
import type { LibraryItem, LibraryItems } from "../types"; import type { LibraryItem, LibraryItems } from "../types";
const { h } = window; const { h } = window;

View file

@ -3,23 +3,35 @@ import { act, queryByTestId, queryByText } from "@testing-library/react";
import React from "react"; import React from "react";
import { vi } from "vitest"; import { vi } from "vitest";
import type { GlobalPoint } from "@excalidraw/math"; import {
ROUNDNESS,
VERTICAL_ALIGN,
KEYS,
reseed,
arrayToMap,
} from "@excalidraw/common";
import { ROUNDNESS, VERTICAL_ALIGN } from "../constants"; import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import { LinearElementEditor } from "../element/linearElementEditor";
import { import {
getBoundTextElementPosition, getBoundTextElementPosition,
getBoundTextMaxWidth, getBoundTextMaxWidth,
} from "../element/textElement"; } from "@excalidraw/element/textElement";
import * as textElementUtils from "../element/textElement"; import * as textElementUtils from "@excalidraw/element/textElement";
import { wrapText } from "../element/textWrapping"; import { wrapText } from "@excalidraw/element/textWrapping";
import type { GlobalPoint } from "@excalidraw/math";
import type {
ExcalidrawElement,
ExcalidrawLinearElement,
ExcalidrawTextElementWithContainer,
FontString,
} from "@excalidraw/element/types";
import { Excalidraw, mutateElement } from "../index"; import { Excalidraw, mutateElement } from "../index";
import { KEYS } from "../keys";
import { reseed } from "../random";
import * as InteractiveCanvas from "../renderer/interactiveScene"; import * as InteractiveCanvas from "../renderer/interactiveScene";
import * as StaticScene from "../renderer/staticScene"; import * as StaticScene from "../renderer/staticScene";
import { API } from "../tests/helpers/api"; import { API } from "../tests/helpers/api";
import { arrayToMap } from "../utils";
import { Keyboard, Pointer, UI } from "./helpers/ui"; import { Keyboard, Pointer, UI } from "./helpers/ui";
import { import {
@ -30,13 +42,6 @@ import {
unmountComponent, unmountComponent,
} from "./test-utils"; } from "./test-utils";
import type {
ExcalidrawElement,
ExcalidrawLinearElement,
ExcalidrawTextElementWithContainer,
FontString,
} from "../element/types";
const renderInteractiveScene = vi.spyOn( const renderInteractiveScene = vi.spyOn(
InteractiveCanvas, InteractiveCanvas,
"renderInteractiveScene", "renderInteractiveScene",

View file

@ -1,23 +1,24 @@
import React from "react"; import React from "react";
import { vi } from "vitest"; import { vi } from "vitest";
import "../../utils/test-utils"; import { bindOrUnbindLinearElement } from "@excalidraw/element/binding";
import { bindOrUnbindLinearElement } from "../element/binding";
import { Excalidraw } from "../index";
import { KEYS } from "../keys";
import { reseed } from "../random";
import * as InteractiveCanvas from "../renderer/interactiveScene";
import * as StaticScene from "../renderer/staticScene";
import { UI, Pointer, Keyboard } from "./helpers/ui"; import { KEYS, reseed } from "@excalidraw/common";
import { render, fireEvent, act, unmountComponent } from "./test-utils";
import type { import type {
ExcalidrawLinearElement, ExcalidrawLinearElement,
NonDeleted, NonDeleted,
ExcalidrawRectangleElement, ExcalidrawRectangleElement,
} from "../element/types"; } from "@excalidraw/element/types";
import type Scene from "../scene/Scene";
import type Scene from "@excalidraw/excalidraw/scene/Scene";
import { Excalidraw } from "../index";
import * as InteractiveCanvas from "../renderer/interactiveScene";
import * as StaticScene from "../renderer/staticScene";
import { UI, Pointer, Keyboard } from "./helpers/ui";
import { render, fireEvent, act, unmountComponent } from "./test-utils";
unmountComponent(); unmountComponent();

View file

@ -1,9 +1,12 @@
import React from "react"; import React from "react";
import { vi } from "vitest"; import { vi } from "vitest";
import { KEYS, reseed } from "@excalidraw/common";
import type { ExcalidrawLinearElement } from "@excalidraw/element/types";
import { Excalidraw } from "../index"; import { Excalidraw } from "../index";
import { KEYS } from "../keys";
import { reseed } from "../random";
import * as InteractiveCanvas from "../renderer/interactiveScene"; import * as InteractiveCanvas from "../renderer/interactiveScene";
import * as StaticScene from "../renderer/staticScene"; import * as StaticScene from "../renderer/staticScene";
@ -15,8 +18,6 @@ import {
unmountComponent, unmountComponent,
} from "./test-utils"; } from "./test-utils";
import type { ExcalidrawLinearElement } from "../element/types";
unmountComponent(); unmountComponent();
const renderInteractiveScene = vi.spyOn( const renderInteractiveScene = vi.spyOn(

View file

@ -1,8 +1,9 @@
import React from "react"; import React from "react";
import { vi } from "vitest"; import { vi } from "vitest";
import { resolvablePromise } from "@excalidraw/common";
import { Excalidraw, CaptureUpdateAction } from "../../index"; import { Excalidraw, CaptureUpdateAction } from "../../index";
import { resolvablePromise } from "../../utils";
import { API } from "../helpers/api"; import { API } from "../helpers/api";
import { Pointer } from "../helpers/ui"; import { Pointer } from "../helpers/ui";
import { render } from "../test-utils"; import { render } from "../test-utils";

View file

@ -1,12 +1,14 @@
import React from "react"; import React from "react";
import { vi } from "vitest"; import { vi } from "vitest";
import { FONT_FAMILY } from "../constants"; import { FONT_FAMILY, CODES, KEYS, reseed } from "@excalidraw/common";
import { setDateTimeForTests } from "@excalidraw/common";
import type { ExcalidrawElement } from "@excalidraw/element/types";
import { Excalidraw } from "../index"; import { Excalidraw } from "../index";
import { CODES, KEYS } from "../keys";
import { reseed } from "../random";
import * as StaticScene from "../renderer/staticScene"; import * as StaticScene from "../renderer/staticScene";
import { setDateTimeForTests } from "../utils";
import { API } from "./helpers/api"; import { API } from "./helpers/api";
import { Keyboard, Pointer, UI } from "./helpers/ui"; import { Keyboard, Pointer, UI } from "./helpers/ui";
@ -19,8 +21,6 @@ import {
unmountComponent, unmountComponent,
} from "./test-utils"; } from "./test-utils";
import type { ExcalidrawElement } from "../element/types";
const { h } = window; const { h } = window;
const renderStaticScene = vi.spyOn(StaticScene, "renderStaticScene"); const renderStaticScene = vi.spyOn(StaticScene, "renderStaticScene");

View file

@ -1,8 +1,9 @@
import React from "react"; import React from "react";
import { expect } from "vitest"; import { expect } from "vitest";
import { reseed } from "@excalidraw/common";
import { Excalidraw } from "../index"; import { Excalidraw } from "../index";
import { reseed } from "../random";
import { UI } from "./helpers/ui"; import { UI } from "./helpers/ui";
import { render, unmountComponent } from "./test-utils"; import { render, unmountComponent } from "./test-utils";

View file

@ -1,6 +1,13 @@
import { exportToCanvas, exportToSvg } from "@excalidraw/utils"; import { exportToCanvas, exportToSvg } from "@excalidraw/utils";
import { FONT_FAMILY, FRAME_STYLE } from "../../constants"; import { FONT_FAMILY, FRAME_STYLE } from "@excalidraw/common";
import type {
ExcalidrawTextElement,
FractionalIndex,
NonDeletedExcalidrawElement,
} from "@excalidraw/element/types";
import { prepareElementsForExport } from "../../data"; import { prepareElementsForExport } from "../../data";
import * as exportUtils from "../../scene/export"; import * as exportUtils from "../../scene/export";
import { import {
@ -11,12 +18,6 @@ import {
} from "../fixtures/elementFixture"; } from "../fixtures/elementFixture";
import { API } from "../helpers/api"; import { API } from "../helpers/api";
import type {
ExcalidrawTextElement,
FractionalIndex,
NonDeletedExcalidrawElement,
} from "../../element/types";
describe("exportToSvg", () => { describe("exportToSvg", () => {
const ELEMENT_HEIGHT = 100; const ELEMENT_HEIGHT = 100;
const ELEMENT_WIDTH = 100; const ELEMENT_WIDTH = 100;

View file

@ -1,7 +1,8 @@
import React from "react"; import React from "react";
import { KEYS } from "@excalidraw/common";
import { Excalidraw } from "../index"; import { Excalidraw } from "../index";
import { KEYS } from "../keys";
import { API } from "./helpers/api"; import { API } from "./helpers/api";
import { Keyboard } from "./helpers/ui"; import { Keyboard } from "./helpers/ui";

View file

@ -1,16 +1,21 @@
import React from "react"; import React from "react";
import { CANVAS_SEARCH_TAB, CLASSES, DEFAULT_SIDEBAR } from "../constants"; import {
CANVAS_SEARCH_TAB,
CLASSES,
DEFAULT_SIDEBAR,
KEYS,
} from "@excalidraw/common";
import type { ExcalidrawTextElement } from "@excalidraw/element/types";
import { Excalidraw } from "../index"; import { Excalidraw } from "../index";
import { KEYS } from "../keys";
import { API } from "./helpers/api"; import { API } from "./helpers/api";
import { Keyboard } from "./helpers/ui"; import { Keyboard } from "./helpers/ui";
import { updateTextEditor } from "./queries/dom"; import { updateTextEditor } from "./queries/dom";
import { act, render, waitFor } from "./test-utils"; import { act, render, waitFor } from "./test-utils";
import type { ExcalidrawTextElement } from "../element/types";
const { h } = window; const { h } = window;
const querySearchInput = async () => { const querySearchInput = async () => {

View file

@ -1,12 +1,13 @@
import React from "react"; import React from "react";
import { vi } from "vitest"; import { vi } from "vitest";
import { KEYS, reseed } from "@excalidraw/common";
import { SHAPES } from "../components/shapes";
import { Excalidraw } from "../index"; import { Excalidraw } from "../index";
import { KEYS } from "../keys";
import { reseed } from "../random";
import * as InteractiveCanvas from "../renderer/interactiveScene"; import * as InteractiveCanvas from "../renderer/interactiveScene";
import * as StaticScene from "../renderer/staticScene"; import * as StaticScene from "../renderer/staticScene";
import { SHAPES } from "../shapes";
import { API } from "./helpers/api"; import { API } from "./helpers/api";
import { Keyboard, Pointer, UI } from "./helpers/ui"; import { Keyboard, Pointer, UI } from "./helpers/ui";

View file

@ -1,7 +1,8 @@
import React from "react"; import React from "react";
import { KEYS } from "@excalidraw/common";
import { Excalidraw } from "../index"; import { Excalidraw } from "../index";
import { KEYS } from "../keys";
import { API } from "./helpers/api"; import { API } from "./helpers/api";
import { Keyboard } from "./helpers/ui"; import { Keyboard } from "./helpers/ui";

View file

@ -1,7 +1,8 @@
import React from "react"; import React from "react";
import { resolvablePromise } from "@excalidraw/common";
import { Excalidraw } from "../index"; import { Excalidraw } from "../index";
import { resolvablePromise } from "../utils";
import { Pointer } from "./helpers/ui"; import { Pointer } from "./helpers/ui";
import { act, render } from "./test-utils"; import { act, render } from "./test-utils";

View file

@ -1,4 +1,4 @@
import { isTransparent } from "../utils"; import { isTransparent } from "@excalidraw/common";
describe("Test isTransparent", () => { describe("Test isTransparent", () => {
it("should return true when color is rgb transparent", () => { it("should return true when color is rgb transparent", () => {

View file

@ -1,8 +1,8 @@
import React from "react"; import React from "react";
import { CURSOR_TYPE } from "../constants"; import { CURSOR_TYPE, KEYS } from "@excalidraw/common";
import { Excalidraw } from "../index"; import { Excalidraw } from "../index";
import { KEYS } from "../keys";
import { API } from "./helpers/api"; import { API } from "./helpers/api";
import { Keyboard, Pointer, UI } from "./helpers/ui"; import { Keyboard, Pointer, UI } from "./helpers/ui";

View file

@ -1,5 +1,15 @@
import React from "react"; import React from "react";
import { selectGroupsForSelectedElements } from "@excalidraw/element/groups";
import { reseed } from "@excalidraw/common";
import type {
ExcalidrawElement,
ExcalidrawFrameElement,
ExcalidrawSelectionElement,
} from "@excalidraw/element/types";
import { import {
actionSendBackward, actionSendBackward,
actionBringForward, actionBringForward,
@ -7,18 +17,12 @@ import {
actionSendToBack, actionSendToBack,
actionDuplicateSelection, actionDuplicateSelection,
} from "../actions"; } from "../actions";
import { selectGroupsForSelectedElements } from "../groups";
import { Excalidraw } from "../index"; import { Excalidraw } from "../index";
import { reseed } from "../random";
import { API } from "./helpers/api"; import { API } from "./helpers/api";
import { act, getCloneByOrigId, render, unmountComponent } from "./test-utils"; import { act, getCloneByOrigId, render, unmountComponent } from "./test-utils";
import type {
ExcalidrawElement,
ExcalidrawFrameElement,
ExcalidrawSelectionElement,
} from "../element/types";
import type { AppState } from "../types"; import type { AppState } from "../types";
unmountComponent(); unmountComponent();

View file

@ -5,6 +5,22 @@ import { defineConfig } from "vitest/config";
export default defineConfig({ export default defineConfig({
resolve: { resolve: {
alias: [ alias: [
{
find: /^@excalidraw\/common$/,
replacement: path.resolve(__dirname, "./packages/common/src/index.ts"),
},
{
find: /^@excalidraw\/common\/(.*?)/,
replacement: path.resolve(__dirname, "./packages/common/src/$1"),
},
{
find: /^@excalidraw\/element$/,
replacement: path.resolve(__dirname, "./packages/element/src/index.ts"),
},
{
find: /^@excalidraw\/element\/(.*?)/,
replacement: path.resolve(__dirname, "./packages/element/src/$1"),
},
{ {
find: /^@excalidraw\/excalidraw$/, find: /^@excalidraw\/excalidraw$/,
replacement: path.resolve(__dirname, "./packages/excalidraw/index.tsx"), replacement: path.resolve(__dirname, "./packages/excalidraw/index.tsx"),
@ -23,11 +39,11 @@ export default defineConfig({
}, },
{ {
find: /^@excalidraw\/math$/, find: /^@excalidraw\/math$/,
replacement: path.resolve(__dirname, "./packages/math/index.ts"), replacement: path.resolve(__dirname, "./packages/math/src/index.ts"),
}, },
{ {
find: /^@excalidraw\/math\/(.*?)/, find: /^@excalidraw\/math\/(.*?)/,
replacement: path.resolve(__dirname, "./packages/math/$1"), replacement: path.resolve(__dirname, "./packages/math/src/$1"),
}, },
], ],
}, },