Skip to content

Unlock custom brushes, natural fill effects and intuitive hatching in p5.js

Fix test

acamposuribe406cd4747d98
diff --git a/package.json b/package.json
index 249ad30..550b1f7 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,7 @@
"scripts": {
"test": "vitest run",
"test:watch": "vitest",
- "build": "rollup --config -w"
+ "build": "rollup --config"
},
"files": [
"dist",
diff --git a/test/fill.test.js b/test/fill.test.js
index d3243d4..5a52e53 100644
--- a/test/fill.test.js
+++ b/test/fill.test.js
@@ -9,6 +9,9 @@ const { blend, mockCtx, mockState } = vi.hoisted(() => ({
save: vi.fn(),
setTransform: vi.fn(),
stroke: vi.fn(),
+ getTransform: vi.fn(() => ({
+ a: 1, b: 0, c: 0, d: 1, e: 0, f: 0,
+ })),
fillStyle: "",
globalCompositeOperation: "source-over",
lineCap: "round",
@@ -67,6 +70,20 @@ vi.mock("../src/core/plot.js", () => ({
Plot: class Plot {},
}));
+vi.mock("../src/core/runtime.js", () => ({
+ createColor: (r, g, b) => ({
+ r: typeof r === 'string' ? 255 : r,
+ g: g ?? r ?? 0,
+ b: b ?? r ?? 0,
+ _getRed: function() { return this.r; },
+ _getGreen: function() { return this.g; },
+ _getBlue: function() { return this.b; },
+ }),
+ getAffineMatrix: () => ({
+ a: 1, b: 0, c: 0, d: 1, x: 0, y: 0,
+ }),
+}));
+
import { createFill, fill } from "../src/fill/fill.js";
describe("createFill()", () => {
diff --git a/test/unit.test.js b/test/unit.test.js
index 1dce827..0c0591d 100644
--- a/test/unit.test.js
+++ b/test/unit.test.js
@@ -21,6 +21,15 @@ vi.mock("../src/core/color.js", () => ({
isMixReady: () => {},
}));
+// Mock runtime.js to properly handle angle mode
+vi.mock("../src/core/runtime.js", () => ({
+ usesRadians: () => currentAngleMode.value === "radians",
+ fromDegrees: (angle) => currentAngleMode.value === "radians" ? (angle * Math.PI) / 180 : angle,
+ createColor: () => ({}),
+ getAffineMatrix: () => ({ a: 1, b: 0, c: 0, d: 1, x: 0, y: 0 }),
+ setRuntime: () => {},
+}));
+
vi.mock("../src/core/target.js", () => ({
Renderer: {
angleMode: () => currentAngleMode.value,