mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-24 01:02:19 +02:00
Added mockContext and mockCanvas objects
This commit is contained in:
parent
6049f6a776
commit
bc2ebc7967
11
test/utils/mocks/mockCanvas.ts
Normal file
11
test/utils/mocks/mockCanvas.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { mockContext } from "#test/utils/mocks/mockContext";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A minimal stub object to mock HTMLCanvasElement
|
||||||
|
*/
|
||||||
|
export const mockCanvas: any = {
|
||||||
|
width: 0,
|
||||||
|
getContext() {
|
||||||
|
return mockContext;
|
||||||
|
},
|
||||||
|
};
|
15
test/utils/mocks/mockContext.ts
Normal file
15
test/utils/mocks/mockContext.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { mockCanvas } from "#test/utils/mocks/mockCanvas";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A minimal stub object to mock CanvasRenderingContext2D
|
||||||
|
*/
|
||||||
|
export const mockContext: any = {
|
||||||
|
font: "",
|
||||||
|
//@ts-ignore
|
||||||
|
measureText: () => new TextMetrics(""),
|
||||||
|
save: () => {},
|
||||||
|
scale: () => {},
|
||||||
|
clearRect: () => {},
|
||||||
|
canvas: mockCanvas,
|
||||||
|
restore: () => {},
|
||||||
|
};
|
@ -14,12 +14,13 @@ import { initStatsKeys } from "#app/ui/game-stats-ui-handler";
|
|||||||
import { setCookie } from "#app/utils";
|
import { setCookie } from "#app/utils";
|
||||||
import { blobToString } from "#test/testUtils/gameManagerUtils";
|
import { blobToString } from "#test/testUtils/gameManagerUtils";
|
||||||
import { MockConsoleLog } from "#test/testUtils/mocks/mockConsoleLog";
|
import { MockConsoleLog } from "#test/testUtils/mocks/mockConsoleLog";
|
||||||
|
import { mockContext } from "#test/testUtils/mocks/mockContext";
|
||||||
|
import { MockFetch } from "#test/testUtils/mocks/mockFetch";
|
||||||
import { mockLocalStorage } from "#test/testUtils/mocks/mockLocalStorage";
|
import { mockLocalStorage } from "#test/testUtils/mocks/mockLocalStorage";
|
||||||
import { MockImage } from "#test/testUtils/mocks/mocksContainer/mockImage";
|
import { MockImage } from "#test/testUtils/mocks/mocksContainer/mockImage";
|
||||||
import Phaser from "phaser";
|
import Phaser from "phaser";
|
||||||
import InputText from "phaser3-rex-plugins/plugins/inputtext";
|
import InputText from "phaser3-rex-plugins/plugins/inputtext";
|
||||||
import { vi } from "vitest";
|
import { vi } from "vitest";
|
||||||
import { MockFetch } from "./mocks/mockFetch";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An initialization function that is run at the beginning of every test file (via `beforeAll()`).
|
* An initialization function that is run at the beginning of every test file (via `beforeAll()`).
|
||||||
@ -77,6 +78,7 @@ export function initTestFile() {
|
|||||||
Phaser.GameObjects.NineSlice.prototype.setPositionRelative = setPositionRelative;
|
Phaser.GameObjects.NineSlice.prototype.setPositionRelative = setPositionRelative;
|
||||||
Phaser.GameObjects.Text.prototype.setPositionRelative = setPositionRelative;
|
Phaser.GameObjects.Text.prototype.setPositionRelative = setPositionRelative;
|
||||||
Phaser.GameObjects.Rectangle.prototype.setPositionRelative = setPositionRelative;
|
Phaser.GameObjects.Rectangle.prototype.setPositionRelative = setPositionRelative;
|
||||||
|
HTMLCanvasElement.prototype.getContext = () => mockContext;
|
||||||
|
|
||||||
// Initialize all of these things if and only if they have not been initialized yet
|
// Initialize all of these things if and only if they have not been initialized yet
|
||||||
if (allMoves.length === 0) {
|
if (allMoves.length === 0) {
|
||||||
|
@ -6,17 +6,6 @@ export default defineProject(({ mode }) => ({
|
|||||||
test: {
|
test: {
|
||||||
testTimeout: 20000,
|
testTimeout: 20000,
|
||||||
setupFiles: ["./test/fontFace.setup.ts", "./test/vitest.setup.ts"],
|
setupFiles: ["./test/fontFace.setup.ts", "./test/vitest.setup.ts"],
|
||||||
server: {
|
|
||||||
deps: {
|
|
||||||
inline: ["vitest-canvas-mock"],
|
|
||||||
//@ts-ignore
|
|
||||||
optimizer: {
|
|
||||||
web: {
|
|
||||||
include: ["vitest-canvas-mock"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
environment: "jsdom" as const,
|
environment: "jsdom" as const,
|
||||||
environmentOptions: {
|
environmentOptions: {
|
||||||
jsdom: {
|
jsdom: {
|
||||||
|
Loading…
Reference in New Issue
Block a user