mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
replaced env.test checks also
This commit is contained in:
parent
16ccca3855
commit
e4d3d29fb8
8 changed files with 23 additions and 29 deletions
|
@ -25,6 +25,7 @@ import { withBatchedUpdates } from "@excalidraw/excalidraw/reactUtils";
|
||||||
import {
|
import {
|
||||||
assertNever,
|
assertNever,
|
||||||
isDevEnv,
|
isDevEnv,
|
||||||
|
isTestEnv,
|
||||||
preventUnload,
|
preventUnload,
|
||||||
resolvablePromise,
|
resolvablePromise,
|
||||||
throttleRAF,
|
throttleRAF,
|
||||||
|
@ -241,7 +242,7 @@ class Collab extends PureComponent<CollabProps, CollabState> {
|
||||||
|
|
||||||
appJotaiStore.set(collabAPIAtom, collabAPI);
|
appJotaiStore.set(collabAPIAtom, collabAPI);
|
||||||
|
|
||||||
if (import.meta.env.MODE === ENV.TEST || isDevEnv()) {
|
if (isTestEnv() || isDevEnv()) {
|
||||||
window.collab = window.collab || ({} as Window["collab"]);
|
window.collab = window.collab || ({} as Window["collab"]);
|
||||||
Object.defineProperties(window, {
|
Object.defineProperties(window, {
|
||||||
collab: {
|
collab: {
|
||||||
|
@ -1014,7 +1015,7 @@ declare global {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (import.meta.env.MODE === ENV.TEST || isDevEnv()) {
|
if (isTestEnv() || isDevEnv()) {
|
||||||
window.collab = window.collab || ({} as Window["collab"]);
|
window.collab = window.collab || ({} as Window["collab"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ import {
|
||||||
assertNever,
|
assertNever,
|
||||||
isDevEnv,
|
isDevEnv,
|
||||||
isShallowEqual,
|
isShallowEqual,
|
||||||
|
isTestEnv,
|
||||||
toBrandedType,
|
toBrandedType,
|
||||||
} from "./utils";
|
} from "./utils";
|
||||||
|
|
||||||
|
@ -515,7 +516,7 @@ export class AppStateChange implements Change<AppState> {
|
||||||
// shouldn't really happen, but just in case
|
// shouldn't really happen, but just in case
|
||||||
console.error(`Couldn't apply appstate change`, e);
|
console.error(`Couldn't apply appstate change`, e);
|
||||||
|
|
||||||
if (isDevEnv() || import.meta.env.MODE === ENV.TEST) {
|
if (isTestEnv() || isDevEnv()) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -553,7 +554,7 @@ export class AppStateChange implements Change<AppState> {
|
||||||
// if postprocessing fails it does not make sense to bubble up, but let's make sure we know about it
|
// if postprocessing fails it does not make sense to bubble up, but let's make sure we know about it
|
||||||
console.error(`Couldn't postprocess appstate change deltas.`);
|
console.error(`Couldn't postprocess appstate change deltas.`);
|
||||||
|
|
||||||
if (isDevEnv() || import.meta.env.MODE === ENV.TEST) {
|
if (isTestEnv() || isDevEnv()) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -843,7 +844,7 @@ export class ElementsChange implements Change<SceneElementsMap> {
|
||||||
change = new ElementsChange(added, removed, updated);
|
change = new ElementsChange(added, removed, updated);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDevEnv() || import.meta.env.MODE === ENV.TEST) {
|
if (isTestEnv() || isDevEnv()) {
|
||||||
ElementsChange.validate(change, "added", this.satisfiesAddition);
|
ElementsChange.validate(change, "added", this.satisfiesAddition);
|
||||||
ElementsChange.validate(change, "removed", this.satisfiesRemoval);
|
ElementsChange.validate(change, "removed", this.satisfiesRemoval);
|
||||||
ElementsChange.validate(change, "updated", this.satisfiesUpdate);
|
ElementsChange.validate(change, "updated", this.satisfiesUpdate);
|
||||||
|
@ -1107,7 +1108,7 @@ export class ElementsChange implements Change<SceneElementsMap> {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`Couldn't apply elements change`, e);
|
console.error(`Couldn't apply elements change`, e);
|
||||||
|
|
||||||
if (isDevEnv() || import.meta.env.MODE === ENV.TEST) {
|
if (isTestEnv() || isDevEnv()) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1138,7 +1139,7 @@ export class ElementsChange implements Change<SceneElementsMap> {
|
||||||
e,
|
e,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isDevEnv() || import.meta.env.MODE === ENV.TEST) {
|
if (isTestEnv() || isDevEnv()) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -1552,7 +1553,7 @@ export class ElementsChange implements Change<SceneElementsMap> {
|
||||||
// if postprocessing fails, it does not make sense to bubble up, but let's make sure we know about it
|
// if postprocessing fails, it does not make sense to bubble up, but let's make sure we know about it
|
||||||
console.error(`Couldn't postprocess elements change deltas.`);
|
console.error(`Couldn't postprocess elements change deltas.`);
|
||||||
|
|
||||||
if (isDevEnv() || import.meta.env.MODE === ENV.TEST) {
|
if (isTestEnv() || isDevEnv()) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -2435,7 +2435,7 @@ class App extends React.Component<AppProps, AppState> {
|
||||||
this.excalidrawContainerValue.container =
|
this.excalidrawContainerValue.container =
|
||||||
this.excalidrawContainerRef.current;
|
this.excalidrawContainerRef.current;
|
||||||
|
|
||||||
if (import.meta.env.MODE === ENV.TEST || isDevEnv()) {
|
if (isTestEnv() || isDevEnv()) {
|
||||||
const setState = this.setState.bind(this);
|
const setState = this.setState.bind(this);
|
||||||
Object.defineProperties(window.h, {
|
Object.defineProperties(window.h, {
|
||||||
state: {
|
state: {
|
||||||
|
@ -11061,7 +11061,7 @@ declare global {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createTestHook = () => {
|
export const createTestHook = () => {
|
||||||
if (import.meta.env.MODE === ENV.TEST || isDevEnv()) {
|
if (isTestEnv() || isDevEnv()) {
|
||||||
window.h = window.h || ({} as Window["h"]);
|
window.h = window.h || ({} as Window["h"]);
|
||||||
|
|
||||||
Object.defineProperties(window.h, {
|
Object.defineProperties(window.h, {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import {
|
||||||
syncInvalidIndices,
|
syncInvalidIndices,
|
||||||
validateFractionalIndices,
|
validateFractionalIndices,
|
||||||
} from "../fractionalIndex";
|
} from "../fractionalIndex";
|
||||||
import { arrayToMap, isDevEnv } from "../utils";
|
import { arrayToMap, isDevEnv, isTestEnv } from "../utils";
|
||||||
|
|
||||||
import type { OrderedExcalidrawElement } from "../element/types";
|
import type { OrderedExcalidrawElement } from "../element/types";
|
||||||
import type { AppState } from "../types";
|
import type { AppState } from "../types";
|
||||||
|
@ -47,11 +47,7 @@ const validateIndicesThrottled = throttle(
|
||||||
localElements: readonly OrderedExcalidrawElement[],
|
localElements: readonly OrderedExcalidrawElement[],
|
||||||
remoteElements: readonly RemoteExcalidrawElement[],
|
remoteElements: readonly RemoteExcalidrawElement[],
|
||||||
) => {
|
) => {
|
||||||
if (
|
if (isDevEnv() || isTestEnv() || window?.DEBUG_FRACTIONAL_INDICES) {
|
||||||
isDevEnv() ||
|
|
||||||
import.meta.env.MODE === ENV.TEST ||
|
|
||||||
window?.DEBUG_FRACTIONAL_INDICES
|
|
||||||
) {
|
|
||||||
// create new instances due to the mutation
|
// create new instances due to the mutation
|
||||||
const elements = syncInvalidIndices(
|
const elements = syncInvalidIndices(
|
||||||
orderedElements.map((x) => ({ ...x })),
|
orderedElements.map((x) => ({ ...x })),
|
||||||
|
@ -59,7 +55,7 @@ const validateIndicesThrottled = throttle(
|
||||||
|
|
||||||
validateFractionalIndices(elements, {
|
validateFractionalIndices(elements, {
|
||||||
// throw in dev & test only, to remain functional on `DEBUG_FRACTIONAL_INDICES`
|
// throw in dev & test only, to remain functional on `DEBUG_FRACTIONAL_INDICES`
|
||||||
shouldThrow: isDevEnv() || import.meta.env.MODE === ENV.TEST,
|
shouldThrow: isTestEnv() || isDevEnv(),
|
||||||
includeBoundTextValidation: true,
|
includeBoundTextValidation: true,
|
||||||
reconciliationContext: {
|
reconciliationContext: {
|
||||||
localElements,
|
localElements,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { ENV } from "../constants";
|
import { ENV } from "../constants";
|
||||||
import { isDevEnv } from "../utils";
|
import { isDevEnv, isTestEnv } from "../utils";
|
||||||
|
|
||||||
import { charWidth, getLineWidth } from "./textMeasurements";
|
import { charWidth, getLineWidth } from "./textMeasurements";
|
||||||
|
|
||||||
|
@ -563,7 +563,7 @@ const isSingleCharacter = (maybeSingleCharacter: string) => {
|
||||||
* Invariant for the word wrapping algorithm.
|
* Invariant for the word wrapping algorithm.
|
||||||
*/
|
*/
|
||||||
const satisfiesWordInvariant = (word: string) => {
|
const satisfiesWordInvariant = (word: string) => {
|
||||||
if (import.meta.env.MODE === ENV.TEST || isDevEnv()) {
|
if (isTestEnv() || isDevEnv()) {
|
||||||
if (/\s/.test(word)) {
|
if (/\s/.test(word)) {
|
||||||
throw new Error("Word should not contain any whitespaces!");
|
throw new Error("Word should not contain any whitespaces!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import {
|
||||||
} from "../fractionalIndex";
|
} from "../fractionalIndex";
|
||||||
import { getElementsInGroup } from "../groups";
|
import { getElementsInGroup } from "../groups";
|
||||||
import { randomInteger } from "../random";
|
import { randomInteger } from "../random";
|
||||||
import { arrayToMap, isDevEnv } from "../utils";
|
import { arrayToMap, isDevEnv, isTestEnv } from "../utils";
|
||||||
import { toBrandedType } from "../utils";
|
import { toBrandedType } from "../utils";
|
||||||
|
|
||||||
import { getSelectedElements } from "./selection";
|
import { getSelectedElements } from "./selection";
|
||||||
|
@ -57,14 +57,10 @@ const getNonDeletedElements = <T extends ExcalidrawElement>(
|
||||||
|
|
||||||
const validateIndicesThrottled = throttle(
|
const validateIndicesThrottled = throttle(
|
||||||
(elements: readonly ExcalidrawElement[]) => {
|
(elements: readonly ExcalidrawElement[]) => {
|
||||||
if (
|
if (isDevEnv() || isTestEnv() || window?.DEBUG_FRACTIONAL_INDICES) {
|
||||||
isDevEnv() ||
|
|
||||||
import.meta.env.MODE === ENV.TEST ||
|
|
||||||
window?.DEBUG_FRACTIONAL_INDICES
|
|
||||||
) {
|
|
||||||
validateFractionalIndices(elements, {
|
validateFractionalIndices(elements, {
|
||||||
// throw only in dev & test, to remain functional on `DEBUG_FRACTIONAL_INDICES`
|
// throw only in dev & test, to remain functional on `DEBUG_FRACTIONAL_INDICES`
|
||||||
shouldThrow: isDevEnv() || import.meta.env.MODE === ENV.TEST,
|
shouldThrow: isDevEnv() || isTestEnv(),
|
||||||
includeBoundTextValidation: true,
|
includeBoundTextValidation: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { AppStateChange, ElementsChange } from "./change";
|
||||||
import { ENV } from "./constants";
|
import { ENV } from "./constants";
|
||||||
import { newElementWith } from "./element/mutateElement";
|
import { newElementWith } from "./element/mutateElement";
|
||||||
import { Emitter } from "./emitter";
|
import { Emitter } from "./emitter";
|
||||||
import { isDevEnv, isShallowEqual } from "./utils";
|
import { isDevEnv, isShallowEqual, isTestEnv } from "./utils";
|
||||||
|
|
||||||
import { deepCopyElement } from "./element/duplicate";
|
import { deepCopyElement } from "./element/duplicate";
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ export class Store implements IStore {
|
||||||
const message = `There can be at most three store actions scheduled at the same time, but there are "${this.scheduledActions.size}".`;
|
const message = `There can be at most three store actions scheduled at the same time, but there are "${this.scheduledActions.size}".`;
|
||||||
console.error(message, this.scheduledActions.values());
|
console.error(message, this.scheduledActions.values());
|
||||||
|
|
||||||
if (isDevEnv() || import.meta.env.MODE === ENV.TEST) {
|
if (isTestEnv() || isDevEnv()) {
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,7 +169,7 @@ export const throttleRAF = <T extends any[]>(
|
||||||
};
|
};
|
||||||
|
|
||||||
const ret = (...args: T) => {
|
const ret = (...args: T) => {
|
||||||
if (import.meta.env.MODE === "test") {
|
if (isTestEnv()) {
|
||||||
fn(...args);
|
fn(...args);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue