TechStark / opencv-js

OpenCV JavaScript version for node.js or browser
Apache License 2.0
353 stars 31 forks source link

Testing issue | Jest | Vitest #29

Open vasile-encord opened 1 year ago

vasile-encord commented 1 year ago

No meter which method from the lib I call it just paralyse the test and it just stuck. Even if I try to console.log it.

import cv from "@techstark/opencv-js";

test("My test", () => {
    console.log(cv) // test will stuck
  },
);

Any ideas why it might happen?

arthur-encord commented 1 year ago

Could be because it's not initialised yet, you can try using onRuntimeInitialized, e.g. with Jest:

import cv from "@techstark/opencv-js";

const openCvLoadTimeout = 25000;

describe("opencvUtils", () => {
  beforeAll(
    async () =>
      // wait for opencv to load
      new Promise((resolve) => {
        cv.onRuntimeInitialized = () => {
          resolve(true);
        };
      }),
    openCvLoadTimeout
  );