jscanify 1.0.0 → 1.1.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/test/tests.js ADDED
@@ -0,0 +1,74 @@
1
+ console.log("RUNNING JSCANIFY TESTS");
2
+ console.log("Warning: This may take a bit");
3
+
4
+ const { Canvas, createCanvas, Image, ImageData, loadImage } = require("canvas");
5
+ const { writeFileSync, unlinkSync, existsSync } = require("fs");
6
+ const assert = require("assert");
7
+
8
+ const jscanify = require("../src/jscanify-node");
9
+ const path = require("path");
10
+
11
+ const outputPaths = {
12
+ highlight: __dirname + "/output/highlighted.jpg",
13
+ extracted: __dirname + "/output/extracted.jpg",
14
+ };
15
+
16
+ const TEST_IMAGE_PATH = path.join(
17
+ __dirname,
18
+ "..",
19
+ "docs",
20
+ "images",
21
+ "test",
22
+ "test.png"
23
+ );
24
+
25
+ function setup() {
26
+ console.log("=== setting up tests ===");
27
+ console.log("Deleting previously generated images");
28
+ Object.values(outputPaths).forEach((path) => {
29
+ if (existsSync(path)) {
30
+ unlinkSync(path);
31
+ }
32
+ });
33
+ }
34
+
35
+ function test() {
36
+ const scanner = new jscanify();
37
+
38
+ console.log("=== beginning tests ===");
39
+ console.log("loading OpenCV.js...");
40
+ scanner.loadOpenCV(function (cv) {
41
+ console.log("Finished loading OpenCV.js");
42
+ describe("feature tests", function (done) {
43
+ it("should highlight paper", function (done) {
44
+ const highlighted = scanner.highlightPaper(testImage);
45
+ writeFileSync(
46
+ outputPaths.highlight,
47
+ highlighted.toBuffer("image/jpeg")
48
+ );
49
+
50
+ assert.ok(existsSync(outputPaths.highlight));
51
+ done()
52
+ });
53
+
54
+ it("should extract paper", function (done) {
55
+ scanner.extractPaper(testImage, 386, 500, function (extracted) {
56
+ writeFileSync(
57
+ outputPaths.extracted,
58
+ extracted.toBuffer("image/jpeg")
59
+ );
60
+
61
+ assert.ok(existsSync(outputPaths.extracted));
62
+ done();
63
+ });
64
+ });
65
+ });
66
+ });
67
+ }
68
+
69
+ let testImage;
70
+ loadImage(TEST_IMAGE_PATH).then(function (image) {
71
+ testImage = image;
72
+ setup();
73
+ test();
74
+ });
Binary file