UNPKG

2.28 kBPlain TextView Raw
1import * as Jimp from "jimp";
2
3const jimpInst: Jimp = new Jimp("test");
4
5// Main Jimp export should already have all of these already applied
6jimpInst.read("Test");
7jimpInst.displace(jimpInst, 2);
8jimpInst.resize(40, 40);
9// $ExpectType 0
10jimpInst.PNG_FILTER_NONE;
11
12// $ExpectError
13jimpInst.test;
14
15// $ExpectError
16jimpInst.func();
17
18// Main Jimp export should already have all of these already applied
19Jimp.read("Test");
20Jimp.displace(Jimp, 2);
21Jimp.shadow((err, val, coords) => {});
22Jimp.resize(40, 40);
23// $ExpectType 0
24Jimp.PNG_FILTER_NONE;
25
26// $ExpectError
27Jimp.test;
28
29// $ExpectError
30Jimp.func();
31
32test("can clone properly", async () => {
33 const baseImage = await Jimp.read("filename");
34 const cloneBaseImage = baseImage.clone();
35
36 // $ExpectType -1
37 cloneBaseImage.PNG_FILTER_AUTO;
38
39 test("can handle `this` returns on the core type properly", () => {
40 // $ExpectType -1
41 cloneBaseImage.diff(jimpInst, jimpInst).image.PNG_FILTER_AUTO;
42 });
43
44 test("can handle `this` returns properly", () => {
45 cloneBaseImage
46 .resize(1, 1)
47 .crop(0, 0, 0, 0)
48 .mask(cloneBaseImage, 2, 2)
49 .print("a" as any, 2, 2, "a" as any)
50 .resize(1, 1)
51 .quality(1)
52 .deflateLevel(2).PNG_FILTER_AUTO;
53 });
54
55 test("can handle imageCallbacks `this` properly", () => {
56 cloneBaseImage.rgba(false, (_, jimpCBIn) => {
57 jimpCBIn.read("Test");
58 jimpCBIn.displace(jimpInst, 2);
59 jimpCBIn.resize(40, 40);
60 // $ExpectType 0
61 jimpCBIn.PNG_FILTER_NONE;
62
63 // $ExpectError
64 jimpCBIn.test;
65
66 // $ExpectError
67 jimpCBIn.func();
68 });
69 });
70});
71
72test("Can handle callback with constructor", () => {
73 const myBmpBuffer: Buffer = {} as any;
74
75 Jimp.read(myBmpBuffer, (err, cbJimpInst) => {
76 cbJimpInst.read("Test");
77 cbJimpInst.displace(jimpInst, 2);
78 cbJimpInst.resize(40, 40);
79 // $ExpectType 0
80 cbJimpInst.PNG_FILTER_NONE;
81
82 // $ExpectError
83 cbJimpInst.test;
84
85 // $ExpectError
86 cbJimpInst.func();
87 });
88});
89
90test("Can handle appendConstructorOption", () => {
91 Jimp.appendConstructorOption(
92 "Name of Option",
93 (args) => args.hasSomeCustomThing,
94 function (resolve, reject, args) {
95 // $ExpectError
96 this.bitmap = 3;
97 Jimp.resize(2, 2);
98 resolve();
99 }
100 );
101});