jest-canvas-mock 2.1.0 → 2.3.0
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.
- package/CHANGELOG.md +32 -9
- package/README.md +38 -12
- package/lib/classes/CanvasGradient.js +16 -33
- package/lib/classes/CanvasPattern.js +8 -22
- package/lib/classes/CanvasRenderingContext2D.js +1243 -1263
- package/lib/classes/DOMMatrix.js +72 -79
- package/lib/classes/ImageBitmap.js +10 -24
- package/lib/classes/ImageData.js +50 -38
- package/lib/classes/Path2D.js +17 -33
- package/lib/classes/TextMetrics.js +19 -20
- package/lib/index.js +3 -3
- package/lib/mock/createCanvasEvent.js +4 -4
- package/lib/mock/createImageBitmap.js +13 -15
- package/lib/mock/prototype.js +12 -14
- package/lib/window.js +16 -16
- package/package.json +21 -14
- package/types/index.d.ts +40 -0
package/lib/window.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
exports.default = void 0;
|
|
7
7
|
|
|
8
8
|
var _Path2D = _interopRequireDefault(require("./classes/Path2D"));
|
|
9
9
|
|
|
@@ -25,15 +25,15 @@ var _prototype = _interopRequireDefault(require("./mock/prototype"));
|
|
|
25
25
|
|
|
26
26
|
var _createImageBitmap = _interopRequireDefault(require("./mock/createImageBitmap"));
|
|
27
27
|
|
|
28
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : {
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Created by hustcc 17/12/25.
|
|
32
32
|
* Contract: i@hust.cc
|
|
33
33
|
*/
|
|
34
|
-
var _default =
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
var _default = win => {
|
|
35
|
+
const d = win.document;
|
|
36
|
+
const f = win.document.createElement; // jsdom@11.6.2 || jest@^22.0.0, console.error in Function getContext();
|
|
37
37
|
// https://github.com/jsdom/jsdom/blob/4c7698f760fc64f20b2a0ddff450eddbdd193176/lib/jsdom/living/nodes/HTMLCanvasElement-impl.js#L55-L58
|
|
38
38
|
// cosole.error will make ci error.
|
|
39
39
|
// try {
|
|
@@ -61,17 +61,17 @@ var _default = function _default(win) {
|
|
|
61
61
|
*/
|
|
62
62
|
// if not exist, then mock it.
|
|
63
63
|
|
|
64
|
-
if (!win.Path2D) win.Path2D = _Path2D
|
|
65
|
-
if (!win.CanvasGradient) win.CanvasGradient = _CanvasGradient
|
|
66
|
-
if (!win.CanvasPattern) win.CanvasPattern = _CanvasPattern
|
|
67
|
-
if (!win.CanvasRenderingContext2D) win.CanvasRenderingContext2D = _CanvasRenderingContext2D
|
|
68
|
-
if (!win.DOMMatrix) win.DOMMatrix = _DOMMatrix
|
|
69
|
-
if (!win.ImageData) win.ImageData = _ImageData
|
|
70
|
-
if (!win.TextMetrics) win.TextMetrics = _TextMetrics
|
|
71
|
-
if (!win.ImageBitmap) win.ImageBitmap = _ImageBitmap
|
|
72
|
-
if (!win.createImageBitmap) win.createImageBitmap = _createImageBitmap
|
|
73
|
-
(0, _prototype
|
|
64
|
+
if (!win.Path2D) win.Path2D = _Path2D.default;
|
|
65
|
+
if (!win.CanvasGradient) win.CanvasGradient = _CanvasGradient.default;
|
|
66
|
+
if (!win.CanvasPattern) win.CanvasPattern = _CanvasPattern.default;
|
|
67
|
+
if (!win.CanvasRenderingContext2D) win.CanvasRenderingContext2D = _CanvasRenderingContext2D.default;
|
|
68
|
+
if (!win.DOMMatrix) win.DOMMatrix = _DOMMatrix.default;
|
|
69
|
+
if (!win.ImageData) win.ImageData = _ImageData.default;
|
|
70
|
+
if (!win.TextMetrics) win.TextMetrics = _TextMetrics.default;
|
|
71
|
+
if (!win.ImageBitmap) win.ImageBitmap = _ImageBitmap.default;
|
|
72
|
+
if (!win.createImageBitmap) win.createImageBitmap = _createImageBitmap.default;
|
|
73
|
+
(0, _prototype.default)();
|
|
74
74
|
return win;
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
-
exports
|
|
77
|
+
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jest-canvas-mock",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Mock a canvas in your jest tests.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -8,24 +8,26 @@
|
|
|
8
8
|
"test": "jest --no-cache",
|
|
9
9
|
"build": "babel src --out-dir lib",
|
|
10
10
|
"coveralls": "cat ./coverage/lcov.info | coveralls",
|
|
11
|
-
"prepare": "npm run build"
|
|
11
|
+
"prepare": "npm run build",
|
|
12
|
+
"prettier": "prettier --write ."
|
|
12
13
|
},
|
|
13
14
|
"dependencies": {
|
|
14
15
|
"cssfontparser": "^1.2.1",
|
|
15
|
-
"
|
|
16
|
+
"moo-color": "^1.0.2"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
18
|
-
"@babel/cli": "^7.
|
|
19
|
-
"@babel/core": "^7.
|
|
20
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
|
21
|
-
"@babel/preset-env": "^7.
|
|
22
|
-
"@commitlint/cli": "^
|
|
23
|
-
"@commitlint/config-angular": "^
|
|
24
|
-
"babel-jest": "^
|
|
19
|
+
"@babel/cli": "^7.8.4",
|
|
20
|
+
"@babel/core": "^7.9.0",
|
|
21
|
+
"@babel/plugin-proposal-class-properties": "^7.8.3",
|
|
22
|
+
"@babel/preset-env": "^7.9.5",
|
|
23
|
+
"@commitlint/cli": "^8.3.5",
|
|
24
|
+
"@commitlint/config-angular": "^8.3.4",
|
|
25
|
+
"babel-jest": "^25.3.0",
|
|
25
26
|
"babel-plugin-version": "^0.2.3",
|
|
26
|
-
"coveralls": "^3.0.
|
|
27
|
-
"husky": "^
|
|
28
|
-
"jest": "^
|
|
27
|
+
"coveralls": "^3.0.11",
|
|
28
|
+
"husky": "^4.2.5",
|
|
29
|
+
"jest": "^25.3.0",
|
|
30
|
+
"prettier": "^2.0.4"
|
|
29
31
|
},
|
|
30
32
|
"commitlint": {
|
|
31
33
|
"extends": [
|
|
@@ -35,7 +37,7 @@
|
|
|
35
37
|
"husky": {
|
|
36
38
|
"hooks": {
|
|
37
39
|
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
|
|
38
|
-
"pre-commit": "npm run test && npm run build"
|
|
40
|
+
"pre-commit": "npm run prettier && npm run test && npm run build"
|
|
39
41
|
}
|
|
40
42
|
},
|
|
41
43
|
"jest": {
|
|
@@ -61,6 +63,11 @@
|
|
|
61
63
|
"test",
|
|
62
64
|
"unit"
|
|
63
65
|
],
|
|
66
|
+
"files": [
|
|
67
|
+
"CHANGELOG.md",
|
|
68
|
+
"lib/",
|
|
69
|
+
"types/"
|
|
70
|
+
],
|
|
64
71
|
"author": "hustcc",
|
|
65
72
|
"license": "MIT",
|
|
66
73
|
"bugs": {
|
package/types/index.d.ts
CHANGED
|
@@ -29,6 +29,18 @@ declare global {
|
|
|
29
29
|
*/
|
|
30
30
|
__getEvents(): CanvasRenderingContext2DEvent[];
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Clear all the events associated with this CanvasRenderingContext2D object.
|
|
34
|
+
*
|
|
35
|
+
* This method cannot be used in a production environment, only with `jest` using
|
|
36
|
+
* `jest-canvas-mock` and should only be used for testing.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ctx.__clearEvents());
|
|
40
|
+
* expect(ctx.__getEvents()).toBe([]);
|
|
41
|
+
*/
|
|
42
|
+
__clearEvents(): void;
|
|
43
|
+
|
|
32
44
|
/**
|
|
33
45
|
* Get all the successful draw calls associated with this CanvasRenderingContext2D object.
|
|
34
46
|
*
|
|
@@ -40,6 +52,18 @@ declare global {
|
|
|
40
52
|
*/
|
|
41
53
|
__getDrawCalls(): CanvasRenderingContext2DEvent[];
|
|
42
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Clear all the successful draw calls associated with this CanvasRenderingContext2D object.
|
|
57
|
+
*
|
|
58
|
+
* This method cannot be used in a production environment, only with `jest` using
|
|
59
|
+
* `jest-canvas-mock` and should only be used for testing.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ctx.__clearDrawCalls());
|
|
63
|
+
* expect(ctx.__getDrawCalls()).toBe([]);
|
|
64
|
+
*/
|
|
65
|
+
__clearDrawCalls(): void;
|
|
66
|
+
|
|
43
67
|
/**
|
|
44
68
|
* Get the current path associated with this CanvasRenderingContext2D object.
|
|
45
69
|
*
|
|
@@ -50,5 +74,21 @@ declare global {
|
|
|
50
74
|
* expect(ctx.__getPath()).toMatchSnapshot();
|
|
51
75
|
*/
|
|
52
76
|
__getPath(): CanvasRenderingContext2DEvent[];
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Clears the current path associated with this CanvasRenderingContext2D object.
|
|
80
|
+
*
|
|
81
|
+
* This method cannot be used in a production environment, only with `jest` using
|
|
82
|
+
* `jest-canvas-mock` and should be only used for testing.
|
|
83
|
+
*/
|
|
84
|
+
__clearPath(): void;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Obtains the current clipping path.
|
|
88
|
+
*
|
|
89
|
+
* This method cannot be used in a production environment, only with `jest` using
|
|
90
|
+
* `jest-canvas-mock` and should be only used for testing.
|
|
91
|
+
*/
|
|
92
|
+
__getClippingRegion(): CanvasRenderingContext2DEvent[];
|
|
53
93
|
}
|
|
54
94
|
}
|