Skip to content

Commit 0b99864

Browse files
committed
Added typings test.
1 parent cffe724 commit 0b99864

File tree

6 files changed

+84
-2
lines changed

6 files changed

+84
-2
lines changed

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
},
1313
"devDependencies": {
1414
"pngjs": "^3.3.3",
15-
"tap": "^12.1.1"
15+
"tap": "^12.1.1",
16+
"typescript": "^3.6.3"
1617
},
1718
"scripts": {
18-
"test": "tap tests/*Tests.js"
19+
"test": "npm run test:unit && npm run test:types",
20+
"test:unit": "tap tests/*Tests.js",
21+
"test:types": "tsc -p ./tests/types/tsconfig.json"
1922
},
2023
"bugs": {
2124
"url": "https://github.com/dmester/canvas-renderer/issues"

tests/types/canvas.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Canvas, CanvasContext, createCanvas } from "../../";
2+
3+
// The following code is for testing typings only. It does not produce any sensible output.
4+
5+
// Canvas
6+
const canvas: Canvas = createCanvas(100, 100);
7+
canvas.width = 100;
8+
canvas.height = 100;
9+
canvas.backColor = "#fff";
10+
canvas.backColor = 0xffffffff;
11+
12+
// Context
13+
const ctx: CanvasContext = canvas.getContext("2d", {});
14+
const ctx2: CanvasContext = canvas.getContext("2d");
15+
const ctx3: CanvasContext = canvas.getContext();
16+
17+
// State management
18+
ctx.save();
19+
ctx.restore();
20+
21+
// Transforms
22+
ctx.resetTransform();
23+
ctx.rotate(52);
24+
ctx.scale(1.5, 1.5);
25+
ctx.setTransform(1, 0, 0, 1, 0, 0);
26+
ctx.transform(1, 0, 0, 1, 0, 0);
27+
ctx.translate(10, 10);
28+
29+
// Drawing
30+
ctx.fillStyle = 0xffffffff;
31+
ctx.fillStyle = "#0000ff";
32+
ctx.beginPath();
33+
ctx.moveTo(90, 90);
34+
ctx.lineTo(90, 50);
35+
ctx.arc(50, 50, 50, 0, Math.PI);
36+
ctx.closePath();
37+
ctx.fill();
38+
ctx.fill("evenodd");
39+
ctx.fill("nonzero");
40+
ctx.fillRect(0, 0, 10, 10);
41+
ctx.clearRect(0, 0, 20, 20);
42+
43+
// Export
44+
const dataUri1: string = canvas.toDataURL();
45+
const dataUri2: string = canvas.toDataURL("image/png");
46+
const dataUri3: string = canvas.toDataURL("image/png", 0.92);
47+
const pngWithoutKeywords: Buffer = canvas.toPng();
48+
const pngWithKeywords: Buffer = canvas.toPng({ "Software": "canvas-renderer 1.0" });

tests/types/esimport.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { createCanvas, Canvas, CanvasContext } from "../../";
2+
3+
// The following code is for testing typings only. It does not produce any sensible output.
4+
5+
const canvas: Canvas = createCanvas(100, 100);
6+
const ctx: CanvasContext = canvas.getContext("2d", {});

tests/types/importas.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as canvasRenderer from "../../";
2+
3+
// The following code is for testing typings only. It does not produce any sensible output.
4+
5+
const canvas: canvasRenderer.Canvas = canvasRenderer.createCanvas(100, 100);
6+
const ctx: canvasRenderer.CanvasContext = canvas.getContext("2d", {});

tests/types/require.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import canvasRenderer = require("../../");
2+
3+
// The following code is for testing typings only. It does not produce any sensible output.
4+
5+
const canvas: canvasRenderer.Canvas = canvasRenderer.createCanvas(100, 100);
6+
const ctx: canvasRenderer.CanvasContext = canvas.getContext("2d", {});

tests/types/tsconfig.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"module": "commonjs",
5+
"strict": true,
6+
"noEmit": true,
7+
"esModuleInterop": false
8+
},
9+
"compileOnSave": false,
10+
"include": [
11+
"./*.ts"
12+
],
13+
}

0 commit comments

Comments
 (0)