From 90cf5246c87644adaf088587197fe81895b2a7d1 Mon Sep 17 00:00:00 2001 From: ColonelParrot <65585002+ColonelParrot@users.noreply.github.com> Date: Tue, 9 May 2023 18:48:08 -0400 Subject: [PATCH] Add base folder check, optimizations --- test/tests.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/test/tests.js b/test/tests.js index 1202864..90e8a00 100644 --- a/test/tests.js +++ b/test/tests.js @@ -1,8 +1,12 @@ +/* + run tests with: npm test +*/ + console.log("RUNNING JSCANIFY TESTS"); console.log("Warning: This may take a bit"); -const { Canvas, createCanvas, Image, ImageData, loadImage } = require("canvas"); -const { writeFileSync, unlinkSync, existsSync } = require("fs"); +const { loadImage } = require("canvas"); +const { mkdirSync, writeFileSync, unlinkSync, existsSync } = require("fs"); const assert = require("assert"); const jscanify = require("../src/jscanify-node"); @@ -13,6 +17,8 @@ const outputPaths = { extracted: __dirname + "/output/extracted.jpg", }; +const baseFolder = __dirname.replaceAll("\\", "/") + "/output/"; + const TEST_IMAGE_PATH = path.join( __dirname, "..", @@ -30,6 +36,10 @@ function setup() { unlinkSync(path); } }); + + if (!existsSync(baseFolder)) { + mkdirSync(baseFolder); + } } function test() { @@ -39,6 +49,7 @@ function test() { console.log("loading OpenCV.js..."); scanner.loadOpenCV(function (cv) { console.log("Finished loading OpenCV.js"); + console.log("Writing test images to: " + baseFolder); describe("feature tests", function (done) { it("should highlight paper", function (done) { const highlighted = scanner.highlightPaper(testImage); @@ -48,7 +59,7 @@ function test() { ); assert.ok(existsSync(outputPaths.highlight)); - done() + done(); }); it("should extract paper", function (done) {