opencv-js icon indicating copy to clipboard operation
opencv-js copied to clipboard

Testing issue | Jest | Vitest

Open vasile-encord opened this issue 2 years ago • 1 comments

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?

vasile-encord avatar May 10 '23 13:05 vasile-encord

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
  );

arthur-encord avatar May 19 '23 08:05 arthur-encord

See also https://github.com/TechStark/opencv-js/blob/main/test/cv.ts

ttt43ttt avatar Oct 25 '24 04:10 ttt43ttt