@canvasengine/testing 2.0.0-beta.41

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.
@@ -0,0 +1,329 @@
1
+ import * as vitest from 'vitest';
2
+ import { vi } from 'vitest';
3
+ import { ComponentInstance, Props, Element } from 'canvasengine';
4
+ export { ComponentInstance, Element, Props } from 'canvasengine';
5
+
6
+ /**
7
+ * Base class for creating mock event emitters
8
+ * Provides event handling functionality similar to PixiJS EventEmitter
9
+ */
10
+ declare class MockEventEmitter {
11
+ #private;
12
+ on(event: string, handler: Function): this;
13
+ off(event: string, handler?: Function): this;
14
+ emit(event: string, data?: any): this;
15
+ once(event: string, handler: Function): this;
16
+ removeAllListeners(event?: string): this;
17
+ }
18
+ /**
19
+ * Mock for PixiJS ObservablePoint
20
+ * Represents a point that can be observed for changes
21
+ */
22
+ declare class MockObservablePoint {
23
+ x: number;
24
+ y: number;
25
+ cb?: (point: MockObservablePoint) => void;
26
+ constructor(x?: number, y?: number, cb?: (point: MockObservablePoint) => void);
27
+ set(x: number, y: number): this;
28
+ copyFrom(point: {
29
+ x: number;
30
+ y: number;
31
+ }): this;
32
+ copyTo(point: {
33
+ x: number;
34
+ y: number;
35
+ }): {
36
+ x: number;
37
+ y: number;
38
+ };
39
+ equals(point: {
40
+ x: number;
41
+ y: number;
42
+ }): boolean;
43
+ }
44
+ /**
45
+ * Mock for PixiJS Rectangle
46
+ */
47
+ declare class MockRectangle {
48
+ x: number;
49
+ y: number;
50
+ width: number;
51
+ height: number;
52
+ constructor(x?: number, y?: number, width?: number, height?: number);
53
+ contains: vitest.Mock<(x: number, y: number) => boolean>;
54
+ clone: vitest.Mock<() => MockRectangle>;
55
+ }
56
+ /**
57
+ * Mock for PixiJS Texture
58
+ */
59
+ declare class MockTexture {
60
+ width: number;
61
+ height: number;
62
+ baseTexture: any;
63
+ frame: MockRectangle;
64
+ valid: boolean;
65
+ constructor(width?: number, height?: number);
66
+ destroy: vitest.Mock<(...args: any[]) => any>;
67
+ update: vitest.Mock<(...args: any[]) => any>;
68
+ clone: vitest.Mock<() => MockTexture>;
69
+ }
70
+ /**
71
+ * Mock for PixiJS Container
72
+ * Base class for all display objects that can contain children
73
+ */
74
+ declare class MockContainer extends MockEventEmitter {
75
+ x: number;
76
+ y: number;
77
+ width: number;
78
+ height: number;
79
+ alpha: number;
80
+ visible: boolean;
81
+ rotation: number;
82
+ scale: MockObservablePoint;
83
+ anchor: MockObservablePoint;
84
+ pivot: MockObservablePoint;
85
+ skew: MockObservablePoint;
86
+ tint: number;
87
+ blendMode: number;
88
+ filters: any[];
89
+ mask: any;
90
+ parent: MockContainer | null;
91
+ children: MockContainer[];
92
+ eventMode: string;
93
+ destroyed: boolean;
94
+ zIndex: number;
95
+ sortableChildren: boolean;
96
+ sortDirty: boolean;
97
+ addChild: vitest.Mock<(<T extends MockContainer>(this: MockContainer, child: T) => T)>;
98
+ addChildAt: vitest.Mock<(<T extends MockContainer>(this: MockContainer, child: T, index: number) => T)>;
99
+ removeChild: vitest.Mock<(<T extends MockContainer>(this: MockContainer, child: T) => T)>;
100
+ removeChildAt: vitest.Mock<(this: MockContainer, index: number) => MockContainer>;
101
+ removeChildren: vitest.Mock<(this: MockContainer, beginIndex?: any, endIndex?: any) => MockContainer[]>;
102
+ getChildAt: vitest.Mock<(this: MockContainer, index: number) => MockContainer>;
103
+ getChildIndex: vitest.Mock<(this: MockContainer, child: MockContainer) => number>;
104
+ setChildIndex: vitest.Mock<(this: MockContainer, child: MockContainer, index: number) => void>;
105
+ swapChildren: vitest.Mock<(this: MockContainer, child: MockContainer, child2: MockContainer) => void>;
106
+ destroy: vitest.Mock<(this: MockContainer, options?: any) => void>;
107
+ updateTransform: vitest.Mock<(...args: any[]) => any>;
108
+ render: vitest.Mock<(...args: any[]) => any>;
109
+ calculateBounds: vitest.Mock<(...args: any[]) => any>;
110
+ getLocalBounds: vitest.Mock<() => MockRectangle>;
111
+ getBounds: vitest.Mock<() => MockRectangle>;
112
+ toLocal: vitest.Mock<(point: {
113
+ x: number;
114
+ y: number;
115
+ }) => {
116
+ x: number;
117
+ y: number;
118
+ }>;
119
+ toGlobal: vitest.Mock<(point: {
120
+ x: number;
121
+ y: number;
122
+ }) => {
123
+ x: number;
124
+ y: number;
125
+ }>;
126
+ }
127
+ /**
128
+ * Mock for PixiJS Graphics
129
+ */
130
+ declare class MockGraphics extends MockContainer {
131
+ geometry: any;
132
+ clear: vitest.Mock<() => this>;
133
+ rect: vitest.Mock<() => this>;
134
+ circle: vitest.Mock<() => this>;
135
+ ellipse: vitest.Mock<() => this>;
136
+ polygon: vitest.Mock<() => this>;
137
+ lineTo: vitest.Mock<() => this>;
138
+ moveTo: vitest.Mock<() => this>;
139
+ beginFill: vitest.Mock<() => this>;
140
+ endFill: vitest.Mock<() => this>;
141
+ lineStyle: vitest.Mock<() => this>;
142
+ drawRect: vitest.Mock<() => this>;
143
+ drawCircle: vitest.Mock<() => this>;
144
+ drawEllipse: vitest.Mock<() => this>;
145
+ drawPolygon: vitest.Mock<() => this>;
146
+ }
147
+ /**
148
+ * Mock for PixiJS Sprite
149
+ */
150
+ declare class MockSprite extends MockContainer {
151
+ texture: MockTexture;
152
+ anchor: MockObservablePoint;
153
+ constructor(texture?: MockTexture);
154
+ static from: vitest.Mock<(source: string | MockTexture) => MockSprite>;
155
+ }
156
+ /**
157
+ * Mock for PixiJS Text
158
+ */
159
+ declare class MockText extends MockContainer {
160
+ text: string;
161
+ style: any;
162
+ canvas: HTMLCanvasElement | null;
163
+ context: CanvasRenderingContext2D | null;
164
+ resolution: number;
165
+ constructor(text?: string, style?: any);
166
+ updateText: vitest.Mock<(respectDirty?: any) => void>;
167
+ updateTransform: vitest.Mock<(...args: any[]) => any>;
168
+ }
169
+ /**
170
+ * Mock for PixiJS Mesh
171
+ */
172
+ declare class MockMesh extends MockContainer {
173
+ geometry: any;
174
+ shader: any;
175
+ texture: MockTexture | null;
176
+ constructor(geometry?: any, shader?: any, texture?: MockTexture);
177
+ }
178
+ /**
179
+ * Mock for PixiJS TilingSprite
180
+ */
181
+ declare class MockTilingSprite extends MockContainer {
182
+ texture: MockTexture;
183
+ tilePosition: MockObservablePoint;
184
+ tileScale: MockObservablePoint;
185
+ constructor(texture: MockTexture, width?: number, height?: number);
186
+ }
187
+ /**
188
+ * Mock for PixiJS NineSlicePlane
189
+ */
190
+ declare class MockNineSlicePlane extends MockContainer {
191
+ texture: MockTexture;
192
+ leftWidth: number;
193
+ topHeight: number;
194
+ rightWidth: number;
195
+ bottomHeight: number;
196
+ constructor(texture: MockTexture, leftWidth?: number, topHeight?: number, rightWidth?: number, bottomHeight?: number);
197
+ }
198
+ /**
199
+ * Mock for PixiJS DOMElement
200
+ */
201
+ declare class MockDOMElement extends MockContainer {
202
+ element: HTMLElement | null;
203
+ constructor(element?: HTMLElement | string);
204
+ }
205
+ /**
206
+ * Mock for PixiJS DOMContainer
207
+ */
208
+ declare class MockDOMContainer extends MockContainer {
209
+ constructor();
210
+ }
211
+ /**
212
+ * Mock for PixiJS Application
213
+ */
214
+ declare class MockApplication extends MockEventEmitter {
215
+ stage: MockContainer;
216
+ screen: MockRectangle;
217
+ view: HTMLCanvasElement;
218
+ destroyed: boolean;
219
+ renderer: any;
220
+ ticker: any;
221
+ loader: any;
222
+ constructor(options?: any);
223
+ render: vitest.Mock<() => void>;
224
+ destroy: vitest.Mock<(removeView?: any) => void>;
225
+ resize: vitest.Mock<(width: number, height: number) => void>;
226
+ }
227
+ /**
228
+ * Mock for PixiJS VideoResource (for Video component)
229
+ */
230
+ declare class MockVideoResource {
231
+ source: HTMLVideoElement | null;
232
+ width: number;
233
+ height: number;
234
+ valid: boolean;
235
+ constructor(source?: HTMLVideoElement);
236
+ load: vitest.Mock<() => Promise<Awaited<this>>>;
237
+ destroy: vitest.Mock<(...args: any[]) => any>;
238
+ }
239
+
240
+ /**
241
+ * Creates a mock Element with all required properties
242
+ *
243
+ * This function creates a complete mock Element that can be used in tests.
244
+ * The element includes a mock componentInstance (PixiJS instance) that can be spied upon.
245
+ *
246
+ * @param tag - The tag name of the element (e.g., 'Container', 'Sprite')
247
+ * @param props - Optional props to assign to the element
248
+ * @param componentInstance - Optional custom componentInstance. If not provided, a default mock will be created
249
+ * @returns A complete mock Element with all required properties
250
+ *
251
+ * @example
252
+ * ```typescript
253
+ * // Create a basic element with default mock
254
+ * const element = createMockElement('Container', { x: 100, y: 50 });
255
+ *
256
+ * // Create an element with custom componentInstance
257
+ * const customInstance = new MockSprite();
258
+ * const spriteElement = createMockElement('Sprite', { image: 'hero.png' }, customInstance);
259
+ *
260
+ * // Access and spy on componentInstance
261
+ * expect(element.componentInstance.x).toBe(100);
262
+ * ```
263
+ */
264
+ declare function createMockElement<T extends ComponentInstance = ComponentInstance>(tag: string, props?: Props, componentInstance?: T): Element<T>;
265
+
266
+ /**
267
+ * Creates a mock ComponentInstance based on the component type
268
+ *
269
+ * This helper function creates appropriate mock instances for different component types.
270
+ * It's useful when you need a ComponentInstance but don't want to use the real PixiJS implementation.
271
+ *
272
+ * @param componentType - The type of component to create a mock for
273
+ * @returns A mock ComponentInstance appropriate for the component type
274
+ *
275
+ * @example
276
+ * ```typescript
277
+ * const containerInstance = createMockComponentInstance('Container');
278
+ * const spriteInstance = createMockComponentInstance('Sprite');
279
+ * ```
280
+ */
281
+ declare function createMockComponentInstance(componentType: string): ComponentInstance;
282
+
283
+ /**
284
+ * Creates a spy on a property or method of an element's componentInstance
285
+ *
286
+ * This helper makes it easy to spy on the PixiJS instance (componentInstance) of an element.
287
+ * It's a convenience wrapper around vi.spyOn that targets element.componentInstance.
288
+ *
289
+ * @param element - The element whose componentInstance should be spied upon
290
+ * @param property - The property or method name to spy on
291
+ * @returns A Vitest spy object
292
+ *
293
+ * @example
294
+ * ```typescript
295
+ * const element = createMockElement('Container', { x: 100 });
296
+ *
297
+ * // Spy on a property getter/setter
298
+ * const xSpy = spyOnElement(element, 'x');
299
+ * element.componentInstance.x = 200;
300
+ * expect(xSpy).toHaveBeenCalled();
301
+ *
302
+ * // Spy on a method
303
+ * const addChildSpy = spyOnElement(element, 'addChild');
304
+ * element.componentInstance.addChild(new MockContainer());
305
+ * expect(addChildSpy).toHaveBeenCalled();
306
+ * ```
307
+ */
308
+ declare function spyOnElement<T extends ComponentInstance>(element: Element<T>, property: keyof T | string): ReturnType<typeof vi.spyOn>;
309
+ /**
310
+ * Creates spies on multiple properties or methods of an element's componentInstance
311
+ *
312
+ * This helper allows you to spy on multiple properties/methods at once.
313
+ *
314
+ * @param element - The element whose componentInstance should be spied upon
315
+ * @param properties - Array of property or method names to spy on
316
+ * @returns An object with spy objects keyed by property name
317
+ *
318
+ * @example
319
+ * ```typescript
320
+ * const element = createMockElement('Container');
321
+ * const spies = spyOnElementMultiple(element, ['addChild', 'removeChild', 'destroy']);
322
+ *
323
+ * element.componentInstance.addChild(new MockContainer());
324
+ * expect(spies.addChild).toHaveBeenCalled();
325
+ * ```
326
+ */
327
+ declare function spyOnElementMultiple<T extends ComponentInstance>(element: Element<T>, properties: (keyof T | string)[]): Record<string, ReturnType<typeof vi.spyOn>>;
328
+
329
+ export { MockApplication, MockContainer, MockDOMContainer, MockDOMElement, MockGraphics, MockMesh, MockNineSlicePlane, MockObservablePoint, MockRectangle, MockSprite, MockText, MockTexture, MockTilingSprite, MockVideoResource, createMockComponentInstance, createMockElement, spyOnElement, spyOnElementMultiple };
package/dist/index.js ADDED
@@ -0,0 +1,476 @@
1
+ // src/mocks/pixi-base.ts
2
+ import { vi } from "vitest";
3
+ var MockEventEmitter = class {
4
+ #eventListeners = /* @__PURE__ */ new Map();
5
+ on(event, handler) {
6
+ if (!this.#eventListeners.has(event)) {
7
+ this.#eventListeners.set(event, []);
8
+ }
9
+ this.#eventListeners.get(event).push(handler);
10
+ return this;
11
+ }
12
+ off(event, handler) {
13
+ if (!this.#eventListeners.has(event)) return this;
14
+ if (handler) {
15
+ const handlers = this.#eventListeners.get(event);
16
+ const index = handlers.indexOf(handler);
17
+ if (index > -1) {
18
+ handlers.splice(index, 1);
19
+ }
20
+ } else {
21
+ this.#eventListeners.delete(event);
22
+ }
23
+ return this;
24
+ }
25
+ emit(event, data) {
26
+ if (this.#eventListeners.has(event)) {
27
+ this.#eventListeners.get(event).forEach((handler) => handler(data));
28
+ }
29
+ return this;
30
+ }
31
+ once(event, handler) {
32
+ const onceHandler = (...args) => {
33
+ handler(...args);
34
+ this.off(event, onceHandler);
35
+ };
36
+ return this.on(event, onceHandler);
37
+ }
38
+ removeAllListeners(event) {
39
+ if (event) {
40
+ this.#eventListeners.delete(event);
41
+ } else {
42
+ this.#eventListeners.clear();
43
+ }
44
+ return this;
45
+ }
46
+ };
47
+ var MockObservablePoint = class {
48
+ constructor(x = 0, y = 0, cb) {
49
+ this.x = x;
50
+ this.y = y;
51
+ this.cb = cb;
52
+ }
53
+ set(x, y) {
54
+ this.x = x;
55
+ this.y = y;
56
+ this.cb?.(this);
57
+ return this;
58
+ }
59
+ copyFrom(point) {
60
+ this.x = point.x;
61
+ this.y = point.y;
62
+ this.cb?.(this);
63
+ return this;
64
+ }
65
+ copyTo(point) {
66
+ point.x = this.x;
67
+ point.y = this.y;
68
+ return point;
69
+ }
70
+ equals(point) {
71
+ return this.x === point.x && this.y === point.y;
72
+ }
73
+ };
74
+ var MockRectangle = class _MockRectangle {
75
+ constructor(x = 0, y = 0, width = 0, height = 0) {
76
+ this.contains = vi.fn((x, y) => {
77
+ return x >= this.x && x <= this.x + this.width && y >= this.y && y <= this.y + this.height;
78
+ });
79
+ this.clone = vi.fn(() => {
80
+ return new _MockRectangle(this.x, this.y, this.width, this.height);
81
+ });
82
+ this.x = x;
83
+ this.y = y;
84
+ this.width = width;
85
+ this.height = height;
86
+ }
87
+ };
88
+ var MockTexture = class _MockTexture {
89
+ constructor(width = 100, height = 100) {
90
+ this.valid = true;
91
+ this.destroy = vi.fn();
92
+ this.update = vi.fn();
93
+ this.clone = vi.fn(() => new _MockTexture(this.width, this.height));
94
+ this.width = width;
95
+ this.height = height;
96
+ this.frame = new MockRectangle(0, 0, width, height);
97
+ this.baseTexture = {
98
+ width,
99
+ height,
100
+ valid: true
101
+ };
102
+ }
103
+ };
104
+ var MockContainer = class extends MockEventEmitter {
105
+ constructor() {
106
+ super(...arguments);
107
+ this.x = 0;
108
+ this.y = 0;
109
+ this.width = 0;
110
+ this.height = 0;
111
+ this.alpha = 1;
112
+ this.visible = true;
113
+ this.rotation = 0;
114
+ this.scale = new MockObservablePoint(1, 1);
115
+ this.anchor = new MockObservablePoint(0, 0);
116
+ this.pivot = new MockObservablePoint(0, 0);
117
+ this.skew = new MockObservablePoint(0, 0);
118
+ this.tint = 16777215;
119
+ this.blendMode = 0;
120
+ this.filters = [];
121
+ this.mask = null;
122
+ this.parent = null;
123
+ this.children = [];
124
+ this.eventMode = "auto";
125
+ this.destroyed = false;
126
+ this.zIndex = 0;
127
+ this.sortableChildren = false;
128
+ this.sortDirty = false;
129
+ this.addChild = vi.fn(function(child) {
130
+ if (child.parent) {
131
+ child.parent.removeChild(child);
132
+ }
133
+ child.parent = this;
134
+ this.children.push(child);
135
+ return child;
136
+ });
137
+ this.addChildAt = vi.fn(function(child, index) {
138
+ if (child.parent) {
139
+ child.parent.removeChild(child);
140
+ }
141
+ child.parent = this;
142
+ this.children.splice(index, 0, child);
143
+ return child;
144
+ });
145
+ this.removeChild = vi.fn(function(child) {
146
+ const index = this.children.indexOf(child);
147
+ if (index > -1) {
148
+ this.children.splice(index, 1);
149
+ child.parent = null;
150
+ }
151
+ return child;
152
+ });
153
+ this.removeChildAt = vi.fn(function(index) {
154
+ const child = this.children[index];
155
+ if (child) {
156
+ this.children.splice(index, 1);
157
+ child.parent = null;
158
+ }
159
+ return child;
160
+ });
161
+ this.removeChildren = vi.fn(function(beginIndex = 0, endIndex = this.children.length) {
162
+ const removed = this.children.splice(beginIndex, endIndex - beginIndex);
163
+ removed.forEach((child) => {
164
+ child.parent = null;
165
+ });
166
+ return removed;
167
+ });
168
+ this.getChildAt = vi.fn(function(index) {
169
+ return this.children[index];
170
+ });
171
+ this.getChildIndex = vi.fn(function(child) {
172
+ return this.children.indexOf(child);
173
+ });
174
+ this.setChildIndex = vi.fn(function(child, index) {
175
+ const currentIndex = this.children.indexOf(child);
176
+ if (currentIndex > -1) {
177
+ this.children.splice(currentIndex, 1);
178
+ this.children.splice(index, 0, child);
179
+ }
180
+ });
181
+ this.swapChildren = vi.fn(function(child, child2) {
182
+ const index1 = this.children.indexOf(child);
183
+ const index2 = this.children.indexOf(child2);
184
+ if (index1 > -1 && index2 > -1) {
185
+ [this.children[index1], this.children[index2]] = [this.children[index2], this.children[index1]];
186
+ }
187
+ });
188
+ this.destroy = vi.fn(function(options) {
189
+ this.destroyed = true;
190
+ this.removeChildren();
191
+ this.removeAllListeners();
192
+ });
193
+ this.updateTransform = vi.fn();
194
+ this.render = vi.fn();
195
+ this.calculateBounds = vi.fn();
196
+ this.getLocalBounds = vi.fn(() => new MockRectangle(0, 0, this.width, this.height));
197
+ this.getBounds = vi.fn(() => new MockRectangle(this.x, this.y, this.width, this.height));
198
+ this.toLocal = vi.fn((point) => ({ x: point.x - this.x, y: point.y - this.y }));
199
+ this.toGlobal = vi.fn((point) => ({ x: point.x + this.x, y: point.y + this.y }));
200
+ }
201
+ };
202
+ var MockGraphics = class extends MockContainer {
203
+ constructor() {
204
+ super(...arguments);
205
+ this.geometry = null;
206
+ this.clear = vi.fn(() => this);
207
+ this.rect = vi.fn(() => this);
208
+ this.circle = vi.fn(() => this);
209
+ this.ellipse = vi.fn(() => this);
210
+ this.polygon = vi.fn(() => this);
211
+ this.lineTo = vi.fn(() => this);
212
+ this.moveTo = vi.fn(() => this);
213
+ this.beginFill = vi.fn(() => this);
214
+ this.endFill = vi.fn(() => this);
215
+ this.lineStyle = vi.fn(() => this);
216
+ this.drawRect = vi.fn(() => this);
217
+ this.drawCircle = vi.fn(() => this);
218
+ this.drawEllipse = vi.fn(() => this);
219
+ this.drawPolygon = vi.fn(() => this);
220
+ }
221
+ };
222
+ var MockSprite = class _MockSprite extends MockContainer {
223
+ constructor(texture) {
224
+ super();
225
+ this.anchor = new MockObservablePoint(0.5, 0.5);
226
+ this.texture = texture || new MockTexture(100, 100);
227
+ this.width = this.texture.width;
228
+ this.height = this.texture.height;
229
+ }
230
+ static {
231
+ this.from = vi.fn((source) => {
232
+ if (typeof source === "string") {
233
+ return new _MockSprite(new MockTexture(100, 100));
234
+ }
235
+ return new _MockSprite(source);
236
+ });
237
+ }
238
+ };
239
+ var MockText = class extends MockContainer {
240
+ constructor(text = "", style) {
241
+ super();
242
+ this.text = "";
243
+ this.style = {};
244
+ this.canvas = null;
245
+ this.context = null;
246
+ this.resolution = 1;
247
+ this.updateText = vi.fn((respectDirty = true) => {
248
+ });
249
+ this.updateTransform = vi.fn();
250
+ this.text = text;
251
+ this.style = style || {};
252
+ }
253
+ };
254
+ var MockMesh = class extends MockContainer {
255
+ constructor(geometry, shader, texture) {
256
+ super();
257
+ this.geometry = null;
258
+ this.shader = null;
259
+ this.texture = null;
260
+ this.geometry = geometry;
261
+ this.shader = shader;
262
+ this.texture = texture || null;
263
+ }
264
+ };
265
+ var MockTilingSprite = class extends MockContainer {
266
+ constructor(texture, width = 100, height = 100) {
267
+ super();
268
+ this.tilePosition = new MockObservablePoint(0, 0);
269
+ this.tileScale = new MockObservablePoint(1, 1);
270
+ this.texture = texture;
271
+ this.width = width;
272
+ this.height = height;
273
+ }
274
+ };
275
+ var MockNineSlicePlane = class extends MockContainer {
276
+ constructor(texture, leftWidth = 10, topHeight = 10, rightWidth = 10, bottomHeight = 10) {
277
+ super();
278
+ this.leftWidth = 10;
279
+ this.topHeight = 10;
280
+ this.rightWidth = 10;
281
+ this.bottomHeight = 10;
282
+ this.texture = texture;
283
+ this.leftWidth = leftWidth;
284
+ this.topHeight = topHeight;
285
+ this.rightWidth = rightWidth;
286
+ this.bottomHeight = bottomHeight;
287
+ }
288
+ };
289
+ var MockDOMElement = class extends MockContainer {
290
+ constructor(element) {
291
+ super();
292
+ this.element = null;
293
+ if (typeof element === "string") {
294
+ this.element = document.createElement(element);
295
+ } else {
296
+ this.element = element || null;
297
+ }
298
+ }
299
+ };
300
+ var MockDOMContainer = class extends MockContainer {
301
+ constructor() {
302
+ super();
303
+ }
304
+ };
305
+ var MockApplication = class extends MockEventEmitter {
306
+ constructor(options) {
307
+ super();
308
+ this.stage = new MockContainer();
309
+ this.screen = new MockRectangle(800, 600);
310
+ this.destroyed = false;
311
+ this.renderer = {
312
+ width: 800,
313
+ height: 600,
314
+ resolution: 1,
315
+ plugins: {},
316
+ render: vi.fn(),
317
+ destroy: vi.fn(),
318
+ resize: vi.fn(),
319
+ clear: vi.fn()
320
+ };
321
+ this.ticker = {
322
+ add: vi.fn(),
323
+ remove: vi.fn(),
324
+ start: vi.fn(),
325
+ stop: vi.fn()
326
+ };
327
+ this.loader = {
328
+ add: vi.fn(),
329
+ load: vi.fn()
330
+ };
331
+ this.render = vi.fn(() => {
332
+ });
333
+ this.destroy = vi.fn((removeView = false) => {
334
+ this.destroyed = true;
335
+ if (removeView && this.view.parentNode) {
336
+ this.view.parentNode.removeChild(this.view);
337
+ }
338
+ });
339
+ this.resize = vi.fn((width, height) => {
340
+ this.screen.width = width;
341
+ this.screen.height = height;
342
+ this.view.width = width;
343
+ this.view.height = height;
344
+ });
345
+ const canvas = document.createElement("canvas");
346
+ canvas.width = options?.width || 800;
347
+ canvas.height = options?.height || 600;
348
+ this.view = canvas;
349
+ this.screen.width = options?.width || 800;
350
+ this.screen.height = options?.height || 600;
351
+ }
352
+ };
353
+ var MockVideoResource = class {
354
+ constructor(source) {
355
+ this.source = null;
356
+ this.width = 0;
357
+ this.height = 0;
358
+ this.valid = false;
359
+ this.load = vi.fn(() => Promise.resolve(this));
360
+ this.destroy = vi.fn();
361
+ this.source = source || null;
362
+ if (source) {
363
+ this.width = source.videoWidth || 0;
364
+ this.height = source.videoHeight || 0;
365
+ this.valid = true;
366
+ }
367
+ }
368
+ };
369
+
370
+ // src/helpers/createMockElement.ts
371
+ import { Subject } from "rxjs";
372
+
373
+ // src/helpers/createMockComponentInstance.ts
374
+ function createMockComponentInstance(componentType) {
375
+ switch (componentType.toLowerCase()) {
376
+ case "container":
377
+ return new MockContainer();
378
+ case "sprite":
379
+ return new MockSprite();
380
+ case "text":
381
+ return new MockText();
382
+ case "graphics":
383
+ case "rect":
384
+ case "circle":
385
+ case "ellipse":
386
+ case "triangle":
387
+ case "svg":
388
+ return new MockGraphics();
389
+ case "mesh":
390
+ return new MockMesh();
391
+ case "tilingsprite":
392
+ return new MockTilingSprite(new MockTexture());
393
+ case "nineslicesprite":
394
+ return new MockNineSlicePlane(new MockTexture());
395
+ case "domelement":
396
+ return new MockDOMElement();
397
+ case "domcontainer":
398
+ return new MockDOMContainer();
399
+ default:
400
+ return new MockContainer();
401
+ }
402
+ }
403
+
404
+ // src/helpers/createMockElement.ts
405
+ function createMockElement(tag, props = {}, componentInstance) {
406
+ const instance = componentInstance || createMockComponentInstance(tag);
407
+ if (instance && typeof instance === "object") {
408
+ Object.keys(props).forEach((key) => {
409
+ if (key in instance && !["children", "context"].includes(key)) {
410
+ instance[key] = props[key];
411
+ }
412
+ });
413
+ }
414
+ const element = {
415
+ tag,
416
+ props: { ...props },
417
+ componentInstance: instance,
418
+ propSubscriptions: [],
419
+ propObservables: void 0,
420
+ parent: null,
421
+ context: void 0,
422
+ directives: {},
423
+ destroy: () => {
424
+ element.propSubscriptions.forEach((sub) => sub.unsubscribe());
425
+ element.effectSubscriptions.forEach((sub) => sub.unsubscribe());
426
+ element.effectUnmounts.forEach((fn) => {
427
+ if (typeof fn === "function") {
428
+ fn();
429
+ }
430
+ });
431
+ },
432
+ allElements: new Subject(),
433
+ isFrozen: false,
434
+ effectSubscriptions: [],
435
+ effectMounts: [],
436
+ effectUnmounts: []
437
+ };
438
+ return element;
439
+ }
440
+
441
+ // src/helpers/spyOnElement.ts
442
+ import { vi as vi2 } from "vitest";
443
+ function spyOnElement(element, property) {
444
+ if (!element.componentInstance) {
445
+ throw new Error("Element componentInstance is not defined");
446
+ }
447
+ return vi2.spyOn(element.componentInstance, property);
448
+ }
449
+ function spyOnElementMultiple(element, properties) {
450
+ const spies = {};
451
+ properties.forEach((property) => {
452
+ spies[property] = spyOnElement(element, property);
453
+ });
454
+ return spies;
455
+ }
456
+ export {
457
+ MockApplication,
458
+ MockContainer,
459
+ MockDOMContainer,
460
+ MockDOMElement,
461
+ MockGraphics,
462
+ MockMesh,
463
+ MockNineSlicePlane,
464
+ MockObservablePoint,
465
+ MockRectangle,
466
+ MockSprite,
467
+ MockText,
468
+ MockTexture,
469
+ MockTilingSprite,
470
+ MockVideoResource,
471
+ createMockComponentInstance,
472
+ createMockElement,
473
+ spyOnElement,
474
+ spyOnElementMultiple
475
+ };
476
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/mocks/pixi-base.ts","../src/helpers/createMockElement.ts","../src/helpers/createMockComponentInstance.ts","../src/helpers/spyOnElement.ts"],"sourcesContent":["import { vi } from 'vitest';\n\n/**\n * Base class for creating mock event emitters\n * Provides event handling functionality similar to PixiJS EventEmitter\n */\nclass MockEventEmitter {\n #eventListeners: Map<string, Function[]> = new Map();\n\n on(event: string, handler: Function) {\n if (!this.#eventListeners.has(event)) {\n this.#eventListeners.set(event, []);\n }\n this.#eventListeners.get(event)!.push(handler);\n return this;\n }\n\n off(event: string, handler?: Function) {\n if (!this.#eventListeners.has(event)) return this;\n if (handler) {\n const handlers = this.#eventListeners.get(event)!;\n const index = handlers.indexOf(handler);\n if (index > -1) {\n handlers.splice(index, 1);\n }\n } else {\n this.#eventListeners.delete(event);\n }\n return this;\n }\n\n emit(event: string, data?: any) {\n if (this.#eventListeners.has(event)) {\n this.#eventListeners.get(event)!.forEach(handler => handler(data));\n }\n return this;\n }\n\n once(event: string, handler: Function) {\n const onceHandler = (...args: any[]) => {\n handler(...args);\n this.off(event, onceHandler);\n };\n return this.on(event, onceHandler);\n }\n\n removeAllListeners(event?: string) {\n if (event) {\n this.#eventListeners.delete(event);\n } else {\n this.#eventListeners.clear();\n }\n return this;\n }\n}\n\n/**\n * Mock for PixiJS ObservablePoint\n * Represents a point that can be observed for changes\n */\nexport class MockObservablePoint {\n x: number;\n y: number;\n cb?: (point: MockObservablePoint) => void;\n\n constructor(x = 0, y = 0, cb?: (point: MockObservablePoint) => void) {\n this.x = x;\n this.y = y;\n this.cb = cb;\n }\n\n set(x: number, y: number) {\n this.x = x;\n this.y = y;\n this.cb?.(this);\n return this;\n }\n\n copyFrom(point: { x: number; y: number }) {\n this.x = point.x;\n this.y = point.y;\n this.cb?.(this);\n return this;\n }\n\n copyTo(point: { x: number; y: number }) {\n point.x = this.x;\n point.y = this.y;\n return point;\n }\n\n equals(point: { x: number; y: number }) {\n return this.x === point.x && this.y === point.y;\n }\n}\n\n/**\n * Mock for PixiJS Rectangle\n */\nexport class MockRectangle {\n x: number;\n y: number;\n width: number;\n height: number;\n\n constructor(x = 0, y = 0, width = 0, height = 0) {\n this.x = x;\n this.y = y;\n this.width = width;\n this.height = height;\n }\n\n contains = vi.fn((x: number, y: number) => {\n return x >= this.x && x <= this.x + this.width &&\n y >= this.y && y <= this.y + this.height;\n });\n\n clone = vi.fn(() => {\n return new MockRectangle(this.x, this.y, this.width, this.height);\n });\n}\n\n/**\n * Mock for PixiJS Texture\n */\nexport class MockTexture {\n width: number;\n height: number;\n baseTexture: any;\n frame: MockRectangle;\n valid: boolean = true;\n\n constructor(width = 100, height = 100) {\n this.width = width;\n this.height = height;\n this.frame = new MockRectangle(0, 0, width, height);\n this.baseTexture = {\n width,\n height,\n valid: true,\n };\n }\n\n destroy = vi.fn();\n update = vi.fn();\n clone = vi.fn(() => new MockTexture(this.width, this.height));\n}\n\n/**\n * Mock for PixiJS Container\n * Base class for all display objects that can contain children\n */\nexport class MockContainer extends MockEventEmitter {\n x: number = 0;\n y: number = 0;\n width: number = 0;\n height: number = 0;\n alpha: number = 1;\n visible: boolean = true;\n rotation: number = 0;\n scale: MockObservablePoint = new MockObservablePoint(1, 1);\n anchor: MockObservablePoint = new MockObservablePoint(0, 0);\n pivot: MockObservablePoint = new MockObservablePoint(0, 0);\n skew: MockObservablePoint = new MockObservablePoint(0, 0);\n tint: number = 0xffffff;\n blendMode: number = 0;\n filters: any[] = [];\n mask: any = null;\n parent: MockContainer | null = null;\n children: MockContainer[] = [];\n eventMode: string = 'auto';\n destroyed: boolean = false;\n zIndex: number = 0;\n sortableChildren: boolean = false;\n sortDirty: boolean = false;\n\n addChild = vi.fn(function<T extends MockContainer>(this: MockContainer, child: T): T {\n if (child.parent) {\n child.parent.removeChild(child);\n }\n child.parent = this;\n this.children.push(child);\n return child;\n });\n\n addChildAt = vi.fn(function<T extends MockContainer>(this: MockContainer, child: T, index: number): T {\n if (child.parent) {\n child.parent.removeChild(child);\n }\n child.parent = this;\n this.children.splice(index, 0, child);\n return child;\n });\n\n removeChild = vi.fn(function<T extends MockContainer>(this: MockContainer, child: T): T {\n const index = this.children.indexOf(child);\n if (index > -1) {\n this.children.splice(index, 1);\n child.parent = null;\n }\n return child;\n });\n\n removeChildAt = vi.fn(function(this: MockContainer, index: number): MockContainer {\n const child = this.children[index];\n if (child) {\n this.children.splice(index, 1);\n child.parent = null;\n }\n return child;\n });\n\n removeChildren = vi.fn(function(this: MockContainer, beginIndex = 0, endIndex = this.children.length): MockContainer[] {\n const removed = this.children.splice(beginIndex, endIndex - beginIndex);\n removed.forEach(child => { child.parent = null; });\n return removed;\n });\n\n getChildAt = vi.fn(function(this: MockContainer, index: number): MockContainer {\n return this.children[index];\n });\n\n getChildIndex = vi.fn(function(this: MockContainer, child: MockContainer): number {\n return this.children.indexOf(child);\n });\n\n setChildIndex = vi.fn(function(this: MockContainer, child: MockContainer, index: number): void {\n const currentIndex = this.children.indexOf(child);\n if (currentIndex > -1) {\n this.children.splice(currentIndex, 1);\n this.children.splice(index, 0, child);\n }\n });\n\n swapChildren = vi.fn(function(this: MockContainer, child: MockContainer, child2: MockContainer): void {\n const index1 = this.children.indexOf(child);\n const index2 = this.children.indexOf(child2);\n if (index1 > -1 && index2 > -1) {\n [this.children[index1], this.children[index2]] = [this.children[index2], this.children[index1]];\n }\n });\n\n destroy = vi.fn(function(this: MockContainer, options?: any): void {\n this.destroyed = true;\n this.removeChildren();\n this.removeAllListeners();\n });\n\n updateTransform = vi.fn();\n render = vi.fn();\n calculateBounds = vi.fn();\n getLocalBounds = vi.fn(() => new MockRectangle(0, 0, this.width, this.height));\n getBounds = vi.fn(() => new MockRectangle(this.x, this.y, this.width, this.height));\n toLocal = vi.fn((point: { x: number; y: number }) => ({ x: point.x - this.x, y: point.y - this.y }));\n toGlobal = vi.fn((point: { x: number; y: number }) => ({ x: point.x + this.x, y: point.y + this.y }));\n}\n\n/**\n * Mock for PixiJS Graphics\n */\nexport class MockGraphics extends MockContainer {\n geometry: any = null;\n\n clear = vi.fn(() => this);\n rect = vi.fn(() => this);\n circle = vi.fn(() => this);\n ellipse = vi.fn(() => this);\n polygon = vi.fn(() => this);\n lineTo = vi.fn(() => this);\n moveTo = vi.fn(() => this);\n beginFill = vi.fn(() => this);\n endFill = vi.fn(() => this);\n lineStyle = vi.fn(() => this);\n drawRect = vi.fn(() => this);\n drawCircle = vi.fn(() => this);\n drawEllipse = vi.fn(() => this);\n drawPolygon = vi.fn(() => this);\n}\n\n/**\n * Mock for PixiJS Sprite\n */\nexport class MockSprite extends MockContainer {\n texture: MockTexture;\n anchor: MockObservablePoint = new MockObservablePoint(0.5, 0.5);\n\n constructor(texture?: MockTexture) {\n super();\n this.texture = texture || new MockTexture(100, 100);\n this.width = this.texture.width;\n this.height = this.texture.height;\n }\n\n static from = vi.fn((source: string | MockTexture) => {\n if (typeof source === 'string') {\n return new MockSprite(new MockTexture(100, 100));\n }\n return new MockSprite(source);\n });\n}\n\n/**\n * Mock for PixiJS Text\n */\nexport class MockText extends MockContainer {\n text: string = '';\n style: any = {};\n canvas: HTMLCanvasElement | null = null;\n context: CanvasRenderingContext2D | null = null;\n resolution: number = 1;\n\n constructor(text = '', style?: any) {\n super();\n this.text = text;\n this.style = style || {};\n }\n\n updateText = vi.fn((respectDirty = true) => {});\n updateTransform = vi.fn();\n}\n\n/**\n * Mock for PixiJS Mesh\n */\nexport class MockMesh extends MockContainer {\n geometry: any = null;\n shader: any = null;\n texture: MockTexture | null = null;\n\n constructor(geometry?: any, shader?: any, texture?: MockTexture) {\n super();\n this.geometry = geometry;\n this.shader = shader;\n this.texture = texture || null;\n }\n}\n\n/**\n * Mock for PixiJS TilingSprite\n */\nexport class MockTilingSprite extends MockContainer {\n texture: MockTexture;\n tilePosition: MockObservablePoint = new MockObservablePoint(0, 0);\n tileScale: MockObservablePoint = new MockObservablePoint(1, 1);\n\n constructor(texture: MockTexture, width = 100, height = 100) {\n super();\n this.texture = texture;\n this.width = width;\n this.height = height;\n }\n}\n\n/**\n * Mock for PixiJS NineSlicePlane\n */\nexport class MockNineSlicePlane extends MockContainer {\n texture: MockTexture;\n leftWidth: number = 10;\n topHeight: number = 10;\n rightWidth: number = 10;\n bottomHeight: number = 10;\n\n constructor(texture: MockTexture, leftWidth = 10, topHeight = 10, rightWidth = 10, bottomHeight = 10) {\n super();\n this.texture = texture;\n this.leftWidth = leftWidth;\n this.topHeight = topHeight;\n this.rightWidth = rightWidth;\n this.bottomHeight = bottomHeight;\n }\n}\n\n/**\n * Mock for PixiJS DOMElement\n */\nexport class MockDOMElement extends MockContainer {\n element: HTMLElement | null = null;\n\n constructor(element?: HTMLElement | string) {\n super();\n if (typeof element === 'string') {\n this.element = document.createElement(element);\n } else {\n this.element = element || null;\n }\n }\n}\n\n/**\n * Mock for PixiJS DOMContainer\n */\nexport class MockDOMContainer extends MockContainer {\n constructor() {\n super();\n }\n}\n\n/**\n * Mock for PixiJS Application\n */\nexport class MockApplication extends MockEventEmitter {\n stage: MockContainer = new MockContainer();\n screen: MockRectangle = new MockRectangle(800, 600);\n view: HTMLCanvasElement;\n destroyed: boolean = false;\n renderer: any = {\n width: 800,\n height: 600,\n resolution: 1,\n plugins: {},\n render: vi.fn(),\n destroy: vi.fn(),\n resize: vi.fn(),\n clear: vi.fn(),\n };\n ticker: any = {\n add: vi.fn(),\n remove: vi.fn(),\n start: vi.fn(),\n stop: vi.fn(),\n };\n loader: any = {\n add: vi.fn(),\n load: vi.fn(),\n };\n\n constructor(options?: any) {\n super();\n const canvas = document.createElement('canvas');\n canvas.width = options?.width || 800;\n canvas.height = options?.height || 600;\n this.view = canvas;\n this.screen.width = options?.width || 800;\n this.screen.height = options?.height || 600;\n }\n\n render = vi.fn(() => {});\n destroy = vi.fn((removeView = false) => {\n this.destroyed = true;\n if (removeView && this.view.parentNode) {\n this.view.parentNode.removeChild(this.view);\n }\n });\n resize = vi.fn((width: number, height: number) => {\n this.screen.width = width;\n this.screen.height = height;\n this.view.width = width;\n this.view.height = height;\n });\n}\n\n/**\n * Mock for PixiJS VideoResource (for Video component)\n */\nexport class MockVideoResource {\n source: HTMLVideoElement | null = null;\n width: number = 0;\n height: number = 0;\n valid: boolean = false;\n\n constructor(source?: HTMLVideoElement) {\n this.source = source || null;\n if (source) {\n this.width = source.videoWidth || 0;\n this.height = source.videoHeight || 0;\n this.valid = true;\n }\n }\n\n load = vi.fn(() => Promise.resolve(this));\n destroy = vi.fn();\n}\n","import { Element, Props } from 'canvasengine';\nimport { ComponentInstance } from 'canvasengine';\nimport { Subject } from 'rxjs';\nimport { createMockComponentInstance } from './createMockComponentInstance';\n\n/**\n * Creates a mock Element with all required properties\n * \n * This function creates a complete mock Element that can be used in tests.\n * The element includes a mock componentInstance (PixiJS instance) that can be spied upon.\n * \n * @param tag - The tag name of the element (e.g., 'Container', 'Sprite')\n * @param props - Optional props to assign to the element\n * @param componentInstance - Optional custom componentInstance. If not provided, a default mock will be created\n * @returns A complete mock Element with all required properties\n * \n * @example\n * ```typescript\n * // Create a basic element with default mock\n * const element = createMockElement('Container', { x: 100, y: 50 });\n * \n * // Create an element with custom componentInstance\n * const customInstance = new MockSprite();\n * const spriteElement = createMockElement('Sprite', { image: 'hero.png' }, customInstance);\n * \n * // Access and spy on componentInstance\n * expect(element.componentInstance.x).toBe(100);\n * ```\n */\nexport function createMockElement<T extends ComponentInstance = ComponentInstance>(\n tag: string,\n props: Props = {},\n componentInstance?: T\n): Element<T> {\n const instance = componentInstance || (createMockComponentInstance(tag) as T);\n\n // Apply props to componentInstance if they are standard PixiJS properties\n if (instance && typeof instance === 'object') {\n Object.keys(props).forEach(key => {\n if (key in instance && !['children', 'context'].includes(key)) {\n (instance as any)[key] = props[key];\n }\n });\n }\n\n const element: Element<T> = {\n tag,\n props: { ...props },\n componentInstance: instance,\n propSubscriptions: [],\n propObservables: undefined,\n parent: null,\n context: undefined,\n directives: {},\n destroy: () => {\n // Mock destroy implementation\n element.propSubscriptions.forEach(sub => sub.unsubscribe());\n element.effectSubscriptions.forEach(sub => sub.unsubscribe());\n element.effectUnmounts.forEach(fn => {\n if (typeof fn === 'function') {\n fn();\n }\n });\n },\n allElements: new Subject(),\n isFrozen: false,\n effectSubscriptions: [],\n effectMounts: [],\n effectUnmounts: [],\n };\n\n return element;\n}\n","import { ComponentInstance } from 'canvasengine';\nimport { MockContainer, MockSprite, MockText, MockGraphics, MockMesh, MockTilingSprite, MockNineSlicePlane, MockDOMElement, MockDOMContainer, MockTexture } from '../mocks/pixi-base';\n\n/**\n * Creates a mock ComponentInstance based on the component type\n * \n * This helper function creates appropriate mock instances for different component types.\n * It's useful when you need a ComponentInstance but don't want to use the real PixiJS implementation.\n * \n * @param componentType - The type of component to create a mock for\n * @returns A mock ComponentInstance appropriate for the component type\n * \n * @example\n * ```typescript\n * const containerInstance = createMockComponentInstance('Container');\n * const spriteInstance = createMockComponentInstance('Sprite');\n * ```\n */\nexport function createMockComponentInstance(componentType: string): ComponentInstance {\n switch (componentType.toLowerCase()) {\n case 'container':\n return new MockContainer() as any;\n case 'sprite':\n return new MockSprite() as any;\n case 'text':\n return new MockText() as any;\n case 'graphics':\n case 'rect':\n case 'circle':\n case 'ellipse':\n case 'triangle':\n case 'svg':\n return new MockGraphics() as any;\n case 'mesh':\n return new MockMesh() as any;\n case 'tilingsprite':\n return new MockTilingSprite(new MockTexture()) as any;\n case 'nineslicesprite':\n return new MockNineSlicePlane(new MockTexture()) as any;\n case 'domelement':\n return new MockDOMElement() as any;\n case 'domcontainer':\n return new MockDOMContainer() as any;\n default:\n // Default to Container for unknown types\n return new MockContainer() as any;\n }\n}\n","import { vi } from 'vitest';\nimport { Element, ComponentInstance } from 'canvasengine';\n\n/**\n * Creates a spy on a property or method of an element's componentInstance\n * \n * This helper makes it easy to spy on the PixiJS instance (componentInstance) of an element.\n * It's a convenience wrapper around vi.spyOn that targets element.componentInstance.\n * \n * @param element - The element whose componentInstance should be spied upon\n * @param property - The property or method name to spy on\n * @returns A Vitest spy object\n * \n * @example\n * ```typescript\n * const element = createMockElement('Container', { x: 100 });\n * \n * // Spy on a property getter/setter\n * const xSpy = spyOnElement(element, 'x');\n * element.componentInstance.x = 200;\n * expect(xSpy).toHaveBeenCalled();\n * \n * // Spy on a method\n * const addChildSpy = spyOnElement(element, 'addChild');\n * element.componentInstance.addChild(new MockContainer());\n * expect(addChildSpy).toHaveBeenCalled();\n * ```\n */\nexport function spyOnElement<T extends ComponentInstance>(\n element: Element<T>,\n property: keyof T | string\n): ReturnType<typeof vi.spyOn> {\n if (!element.componentInstance) {\n throw new Error('Element componentInstance is not defined');\n }\n\n return vi.spyOn(element.componentInstance as any, property as string);\n}\n\n/**\n * Creates spies on multiple properties or methods of an element's componentInstance\n * \n * This helper allows you to spy on multiple properties/methods at once.\n * \n * @param element - The element whose componentInstance should be spied upon\n * @param properties - Array of property or method names to spy on\n * @returns An object with spy objects keyed by property name\n * \n * @example\n * ```typescript\n * const element = createMockElement('Container');\n * const spies = spyOnElementMultiple(element, ['addChild', 'removeChild', 'destroy']);\n * \n * element.componentInstance.addChild(new MockContainer());\n * expect(spies.addChild).toHaveBeenCalled();\n * ```\n */\nexport function spyOnElementMultiple<T extends ComponentInstance>(\n element: Element<T>,\n properties: (keyof T | string)[]\n): Record<string, ReturnType<typeof vi.spyOn>> {\n const spies: Record<string, ReturnType<typeof vi.spyOn>> = {};\n \n properties.forEach(property => {\n spies[property as string] = spyOnElement(element, property);\n });\n \n return spies;\n}\n"],"mappings":";AAAA,SAAS,UAAU;AAMnB,IAAM,mBAAN,MAAuB;AAAA,EACrB,kBAA2C,oBAAI,IAAI;AAAA,EAEnD,GAAG,OAAe,SAAmB;AACnC,QAAI,CAAC,KAAK,gBAAgB,IAAI,KAAK,GAAG;AACpC,WAAK,gBAAgB,IAAI,OAAO,CAAC,CAAC;AAAA,IACpC;AACA,SAAK,gBAAgB,IAAI,KAAK,EAAG,KAAK,OAAO;AAC7C,WAAO;AAAA,EACT;AAAA,EAEA,IAAI,OAAe,SAAoB;AACrC,QAAI,CAAC,KAAK,gBAAgB,IAAI,KAAK,EAAG,QAAO;AAC7C,QAAI,SAAS;AACX,YAAM,WAAW,KAAK,gBAAgB,IAAI,KAAK;AAC/C,YAAM,QAAQ,SAAS,QAAQ,OAAO;AACtC,UAAI,QAAQ,IAAI;AACd,iBAAS,OAAO,OAAO,CAAC;AAAA,MAC1B;AAAA,IACF,OAAO;AACL,WAAK,gBAAgB,OAAO,KAAK;AAAA,IACnC;AACA,WAAO;AAAA,EACT;AAAA,EAEA,KAAK,OAAe,MAAY;AAC9B,QAAI,KAAK,gBAAgB,IAAI,KAAK,GAAG;AACnC,WAAK,gBAAgB,IAAI,KAAK,EAAG,QAAQ,aAAW,QAAQ,IAAI,CAAC;AAAA,IACnE;AACA,WAAO;AAAA,EACT;AAAA,EAEA,KAAK,OAAe,SAAmB;AACrC,UAAM,cAAc,IAAI,SAAgB;AACtC,cAAQ,GAAG,IAAI;AACf,WAAK,IAAI,OAAO,WAAW;AAAA,IAC7B;AACA,WAAO,KAAK,GAAG,OAAO,WAAW;AAAA,EACnC;AAAA,EAEA,mBAAmB,OAAgB;AACjC,QAAI,OAAO;AACT,WAAK,gBAAgB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A,WAAU;AA4BZ,SAAS,aACd,SACA,UAC6B;AAC7B,MAAI,CAAC,QAAQ,mBAAmB;AAC9B,UAAM,IAAI,MAAM,0CAA0C;AAAA,EAC5D;AAEA,SAAOA,IAAG,MAAM,QAAQ,mBAA0B,QAAkB;AACtE;AAoBO,SAAS,qBACd,SACA,YAC6C;AAC7C,QAAM,QAAqD,CAAC;AAE5D,aAAW,QAAQ,cAAY;AAC7B,UAAM,QAAkB,IAAI,aAAa,SAAS,QAAQ;AAAA,EAC5D,CAAC;AAED,SAAO;AACT;","names":["vi"]}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@canvasengine/testing",
3
+ "version": "2.0.0-beta.41",
4
+ "description": "Testing utilities and mocks for CanvasEngine",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "peerDependencies": {
12
+ "vitest": "*",
13
+ "canvasengine": "2.0.0-beta.41"
14
+ },
15
+ "devDependencies": {
16
+ "@types/node": "^25.0.1",
17
+ "tsup": "^8.5.1",
18
+ "typescript": "^5.9.3"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "keywords": [
24
+ "canvas",
25
+ "pixijs",
26
+ "testing",
27
+ "mocks"
28
+ ],
29
+ "author": "Samuel Ronce",
30
+ "license": "MIT",
31
+ "homepage": "https://canvasengine.net",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/RSamaium/CanvasEngine.git"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/RSamaium/CanvasEngine/issues"
38
+ },
39
+ "dependencies": {
40
+ "rxjs": "^7.8.1"
41
+ },
42
+ "scripts": {
43
+ "build": "tsup",
44
+ "dev": "tsup --watch"
45
+ }
46
+ }