jest-webgl-canvas-mock
Advanced tools
Comparing version 2.5.0 to 2.5.2
@@ -15,3 +15,3 @@ "use strict"; | ||
if (!Number.isFinite(numoffset) || numoffset < 0 || numoffset > 1) { | ||
throw new DOMException('IndexSizeError', "Failed to execute 'addColorStop' on 'CanvasGradient': The provided value ('" + numoffset + "') is outside the range (0.0, 1.0)"); | ||
throw new DOMException("Failed to execute 'addColorStop' on 'CanvasGradient': The provided value ('" + numoffset + "') is outside the range (0.0, 1.0)", 'IndexSizeError'); | ||
} | ||
@@ -18,0 +18,0 @@ try { |
@@ -137,3 +137,3 @@ "use strict"; | ||
} = options; | ||
if (!path && !id) throw new DOMException('ConstraintError', "Failed to execute 'addHitRegion' on '" + this.constructor.name + "': Both id and control are null."); | ||
if (!path && !id) throw new DOMException("Failed to execute 'addHitRegion' on '" + this.constructor.name + "': Both id and control are null.", 'ConstraintError'); | ||
if (fillRule && fillRule !== 'evenodd' && fillRule !== 'nonzero') throw new TypeError("Failed to execute 'addHitRegion' on '" + this.constructor.name + "': The provided value '" + fillRule + "' is not a valid enum value of type CanvasFillRule."); | ||
@@ -165,3 +165,3 @@ this._events.push((0, _createCanvasEvent.default)('addHitRegion', getTransformSlice(this), { | ||
if (!Number.isFinite(xResult + yResult + radiusResult + startAngleResult + endAngleResult)) return; | ||
if (Number(radius) < 0) throw new DOMException('IndexSizeError', "Failed to execute 'arc' on '" + this.constructor.name + "': The radius provided (" + radius + ') is negative.'); | ||
if (Number(radius) < 0) throw new DOMException("Failed to execute 'arc' on '" + this.constructor.name + "': The radius provided (" + radius + ') is negative.', 'IndexSizeError'); | ||
const event = (0, _createCanvasEvent.default)('arc', getTransformSlice(this), { | ||
@@ -179,3 +179,3 @@ x: xResult, | ||
arcTo(cpx1, cpy1, cpx2, cpy2, radius) { | ||
if (arguments.length < 5) throw new DOMException('IndexSizeError', "Failed to execute 'arcTo' on '" + this.constructor.name + "': 5 arguments required, but only " + arguments.length + ' present.'); | ||
if (arguments.length < 5) throw new TypeError("Failed to execute 'arcTo' on '" + this.constructor.name + "': 5 arguments required, but only " + arguments.length + ' present.'); | ||
const cpx1Result = Number(cpx1); | ||
@@ -187,3 +187,3 @@ const cpy1Result = Number(cpy1); | ||
if (!Number.isFinite(cpx1Result + cpx2Result + cpy1Result + cpy2Result + radiusResult)) return; | ||
if (radiusResult < 0) throw new TypeError("Failed to execute 'arcTo' on '" + this.constructor.name + "': The radius provided (" + radius + ') is negative.'); | ||
if (radiusResult < 0) throw new DOMException("Failed to execute 'arcTo' on '" + this.constructor.name + "': The radius provided (" + radius + ') is negative.', 'IndexSizeError'); | ||
const event = (0, _createCanvasEvent.default)('arcTo', getTransformSlice(this), { | ||
@@ -333,3 +333,3 @@ cpx1: cpx1Result, | ||
if (image instanceof ImageBitmap) { | ||
if (image._closed) throw new DOMException('InvalidStateError', "Failed to execute 'createPattern' on 'CanvasRenderingContext2D': The image source is detached."); | ||
if (image._closed) throw new DOMException("Failed to execute 'createPattern' on 'CanvasRenderingContext2D': The image source is detached.", 'InvalidStateError'); | ||
this._events.push(event); | ||
@@ -364,4 +364,4 @@ return new _CanvasPattern.default(); | ||
if (!Number.isFinite(x0Result + y0Result + r0Result + x1Result + y1Result + r1Result)) throw new TypeError("Failed to execute 'createRadialGradient' on '" + this.constructor.name + "': The provided double value is non-finite."); | ||
if (r0Result < 0) throw new DOMException('IndexSizeError', "Failed to execute 'createRadialGradient' on '" + this.constructor.name + "': The r0 provided is less than 0."); | ||
if (r1Result < 0) throw new DOMException('IndexSizeError', "Failed to execute 'createRadialGradient' on '" + this.constructor.name + "': The r1 provided is less than 0."); | ||
if (r0Result < 0) throw new DOMException("Failed to execute 'createRadialGradient' on '" + this.constructor.name + "': The r0 provided is less than 0.", 'IndexSizeError'); | ||
if (r1Result < 0) throw new DOMException("Failed to execute 'createRadialGradient' on '" + this.constructor.name + "': The r1 provided is less than 0.", 'IndexSizeError'); | ||
const event = (0, _createCanvasEvent.default)('createRadialGradient', getTransformSlice(this), { | ||
@@ -432,3 +432,3 @@ x0: x0Result, | ||
if (img instanceof ImageBitmap) { | ||
if (img._closed) throw new DOMException('InvalidStateError', "DOMException: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image source is detached."); | ||
if (img._closed) throw new DOMException("DOMException: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image source is detached.", 'InvalidStateError'); | ||
valid = true; | ||
@@ -503,4 +503,4 @@ } | ||
if (!Number.isFinite(xResult + yResult + radiusXResult + radiusYResult + rotationResult + startAngleResult + endAngleResult)) return; | ||
if (Number(radiusX) < 0) throw new DOMException('IndexSizeError', "Failed to execute 'ellipse' on '" + this.constructor.name + "': The major-axis radius provided (" + radiusX + ') is negative.'); | ||
if (Number(radiusY) < 0) throw new DOMException('IndexSizeError', "Failed to execute 'ellipse' on '" + this.constructor.name + "': The minor-axis radius provided (" + radiusY + ') is negative.'); | ||
if (Number(radiusX) < 0) throw new DOMException("Failed to execute 'ellipse' on '" + this.constructor.name + "': The major-axis radius provided (" + radiusX + ') is negative.', 'IndexSizeError'); | ||
if (Number(radiusY) < 0) throw new DOMException("Failed to execute 'ellipse' on '" + this.constructor.name + "': The minor-axis radius provided (" + radiusY + ') is negative.', 'IndexSizeError'); | ||
const event = (0, _createCanvasEvent.default)('ellipse', getTransformSlice(this), { | ||
@@ -624,4 +624,6 @@ x: xResult, | ||
} | ||
getImageData() { | ||
return new ImageData(this._canvas.width, this._canvas.height); | ||
getImageData(x, y, w, h) { | ||
if (arguments.length < 4) throw new TypeError("Failed to execute 'getImageData' on '" + this.constructor.name + "': 4 arguments required, but only " + arguments.length + ' present.'); | ||
if (w == 0 || h == 0) throw new DOMException("Failed to execute 'getImageData' on '" + this.constructor.name + "': The source " + (w == 0 ? 'width' : 'height') + ' is 0.', 'IndexSizeError'); | ||
return new ImageData(Math.abs(w), Math.abs(h)); | ||
} | ||
@@ -628,0 +630,0 @@ getLineDash() { |
@@ -20,3 +20,3 @@ "use strict"; | ||
} | ||
const ver = "2.5.0"; | ||
const ver = "2.5.2"; | ||
exports.ver = ver; | ||
@@ -23,0 +23,0 @@ function setupJestCanvasMock(window) { |
@@ -10,3 +10,4 @@ "use strict"; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function mockPrototype() { | ||
function mockPrototype(win) { | ||
var _win$HTMLCanvasElemen; | ||
/** | ||
@@ -23,3 +24,3 @@ * This weakmap is designed to contain all of the generated canvas contexts. It's keys are the | ||
*/ | ||
function getContext(type, options) { | ||
const getContextMock = jest.fn(function getContext(type, options) { | ||
if (type === '2d') { | ||
@@ -40,6 +41,20 @@ /** | ||
} | ||
return getContext.internal.call(this, type, options); | ||
try { | ||
if (!this.dataset.internalRequireTest) require('canvas'); | ||
} catch (_unused) { | ||
return null; | ||
} | ||
return getContextMock.internal.call(this, type, options); | ||
}); | ||
let htmlCanvasElementPrototype = HTMLCanvasElement.prototype; | ||
if (win !== null && win !== void 0 && (_win$HTMLCanvasElemen = win.HTMLCanvasElement) !== null && _win$HTMLCanvasElemen !== void 0 && _win$HTMLCanvasElemen.prototype) { | ||
var _win$HTMLCanvasElemen2; | ||
htmlCanvasElementPrototype = win === null || win === void 0 ? void 0 : (_win$HTMLCanvasElemen2 = win.HTMLCanvasElement) === null || _win$HTMLCanvasElemen2 === void 0 ? void 0 : _win$HTMLCanvasElemen2.prototype; | ||
} | ||
getContext.internal = HTMLCanvasElement.prototype.getContext; | ||
HTMLCanvasElement.prototype.getContext = getContext; | ||
if (!jest.isMockFunction(htmlCanvasElementPrototype.getContext)) { | ||
getContextMock.internal = htmlCanvasElementPrototype.getContext; | ||
} else { | ||
getContextMock.internal = htmlCanvasElementPrototype.getContext.internal; | ||
} | ||
htmlCanvasElementPrototype.getContext = getContextMock; | ||
@@ -78,8 +93,8 @@ /** | ||
}); | ||
if (!jest.isMockFunction(HTMLCanvasElement.prototype.toBlob)) { | ||
toBlobOverride.internal = HTMLCanvasElement.prototype.toBlob; | ||
if (!jest.isMockFunction(htmlCanvasElementPrototype.toBlob)) { | ||
toBlobOverride.internal = htmlCanvasElementPrototype.toBlob; | ||
} else { | ||
toBlobOverride.internal = HTMLCanvasElement.prototype.toBlob.internal; | ||
toBlobOverride.internal = htmlCanvasElementPrototype.toBlob.internal; | ||
} | ||
HTMLCanvasElement.prototype.toBlob = toBlobOverride; | ||
htmlCanvasElementPrototype.toBlob = toBlobOverride; | ||
@@ -105,8 +120,8 @@ /** | ||
}); | ||
if (!jest.isMockFunction(HTMLCanvasElement.prototype.toDataURL)) { | ||
toDataURLOverride.internal = HTMLCanvasElement.prototype.toDataURL; | ||
if (!jest.isMockFunction(htmlCanvasElementPrototype.toDataURL)) { | ||
toDataURLOverride.internal = htmlCanvasElementPrototype.toDataURL; | ||
} else { | ||
toDataURLOverride.internal = HTMLCanvasElement.prototype.toDataURL.internal; | ||
toDataURLOverride.internal = htmlCanvasElementPrototype.toDataURL.internal; | ||
} | ||
HTMLCanvasElement.prototype.toDataURL = toDataURLOverride; | ||
htmlCanvasElementPrototype.toDataURL = toDataURLOverride; | ||
} |
@@ -80,5 +80,5 @@ "use strict"; | ||
if (!win.WebGLUniformLocation) win.WebGLUniformLocation = function () {}; | ||
(0, _prototype.default)(); | ||
(0, _prototype.default)(win); | ||
return win; | ||
}; | ||
exports.default = _default; |
{ | ||
"name": "jest-webgl-canvas-mock", | ||
"version": "2.5.0", | ||
"version": "2.5.2", | ||
"description": "Mock both 2D and WebGL contexts in Jest.", | ||
@@ -28,7 +28,10 @@ "main": "lib/index.js", | ||
"@commitlint/config-angular": "^17.6.1", | ||
"@inrupt/jest-jsdom-polyfills": "^2.5.0", | ||
"babel-jest": "^25.3.0", | ||
"babel-plugin-version": "^0.2.3", | ||
"coveralls": "^3.0.11", | ||
"husky": "^4.2.5", | ||
"jest": "^29.5.0", | ||
"jest-environment-jsdom": "^29.5.0", | ||
"jsdom": "^22.1.0", | ||
"prettier": "^2.0.4" | ||
@@ -55,2 +58,3 @@ }, | ||
"setupFiles": [ | ||
"@inrupt/jest-jsdom-polyfills", | ||
"./src/index.js", | ||
@@ -57,0 +61,0 @@ "./__mocks__/worker.js" |
@@ -1,2 +0,2 @@ | ||
export function setupJestCanvasMock(window?: Window) {} | ||
export function setupJestCanvasMock(window?: Window): void; | ||
@@ -3,0 +3,0 @@ export interface CanvasRenderingContext2DEvent { |
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
128797
2391
0
16
1