From 258fc2245a8f28f9f2c800981915d81df80dfd46 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Wed, 5 Aug 2026 11:46:11 +0200 Subject: [PATCH] test(opencv): replace chai with node:assert/strict (#22597) --- packages/opencv/test/e2e/opencv.e2e.spec.ts | 70 ++++++++++----------- packages/opencv/test/unit/opencv.spec.ts | 5 +- 2 files changed, 36 insertions(+), 39 deletions(-) diff --git a/packages/opencv/test/e2e/opencv.e2e.spec.ts b/packages/opencv/test/e2e/opencv.e2e.spec.ts index dee962f02..7d8c94784 100644 --- a/packages/opencv/test/e2e/opencv.e2e.spec.ts +++ b/packages/opencv/test/e2e/opencv.e2e.spec.ts @@ -1,15 +1,12 @@ +import assert from 'node:assert/strict'; import path from 'node:path'; import {describe, it, before} from 'node:test'; import {fileURLToPath} from 'node:url'; import {fs, node} from '@appium/support'; -import {expect, use} from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import {getImageOccurrence, getImagesMatches, getImagesSimilarity} from '../../lib/index.js'; -use(chaiAsPromised); - const FIXTURES_ROOT = path.resolve( node.getModuleRootSync('@appium/opencv', fileURLToPath(import.meta.url))!, 'test', @@ -41,8 +38,8 @@ describe('OpenCV helpers', {timeout: 120000}, () => { it('should calculate the number of matches between two images', async function () { for (const detectorName of ['AKAZE', 'ORB'] as const) { const {count, totalCount} = await getImagesMatches(fullImage!, fullImage!, {detectorName}); - expect(count).to.be.above(0); - expect(totalCount).to.eql(count); + assert.ok(count > 0); + assert.strictEqual(totalCount, count); } }); @@ -50,7 +47,7 @@ describe('OpenCV helpers', {timeout: 120000}, () => { const {visualization} = await getImagesMatches(fullImage!, fullImage!, { visualize: true, }); - expect(visualization).to.not.be.empty; + assert.ok(visualization!.length > 0); }); it('should visualize matches between two images and apply goodMatchesFactor', async function () { @@ -59,57 +56,58 @@ describe('OpenCV helpers', {timeout: 120000}, () => { matchFunc: 'BruteForceHamming', goodMatchesFactor: 40, }); - expect(visualization).to.not.be.empty; - expect(points1.length).to.be.above(4); - expect(rect1.x).to.be.above(0); - expect(rect1.y).to.be.above(0); - expect(rect1.width).to.be.above(0); - expect(rect1.height).to.be.above(0); - expect(points2.length).to.be.above(4); - expect(rect2.x).to.be.above(0); - expect(rect2.y).to.be.above(0); - expect(rect2.width).to.be.above(0); - expect(rect2.height).to.be.above(0); + assert.ok(visualization!.length > 0); + assert.ok(points1.length > 4); + assert.ok(rect1.x > 0); + assert.ok(rect1.y > 0); + assert.ok(rect1.width > 0); + assert.ok(rect1.height > 0); + assert.ok(points2.length > 4); + assert.ok(rect2.x > 0); + assert.ok(rect2.y > 0); + assert.ok(rect2.width > 0); + assert.ok(rect2.height > 0); }); }); describe('getImagesSimilarity', function () { it('should calculate the similarity score between two images', async function () { const {score} = await getImagesSimilarity(imgFixture!, imgFixture!); - expect(score).to.be.above(0); + assert.ok(score > 0); }); it('should visualize the similarity between two images', async function () { const {visualization} = await getImagesSimilarity(originalImage!, changedImage!, { visualize: true, }); - expect(visualization).to.not.be.empty; + assert.ok(visualization!.length > 0); }); }); describe('getImageOccurrence', function () { it('should calculate the partial image position in the full image', async function () { const {rect, score} = await getImageOccurrence(fullImage!, partialImage!); - expect(rect.x).to.be.above(0); - expect(rect.y).to.be.above(0); - expect(rect.width).to.be.above(0); - expect(rect.height).to.be.above(0); - expect(score).to.be.above(0); + assert.ok(rect.x > 0); + assert.ok(rect.y > 0); + assert.ok(rect.width > 0); + assert.ok(rect.height > 0); + assert.ok(score > 0); }); it('should reject matches that fall below a threshold', async function () { - await expect( + await assert.rejects( getImageOccurrence(fullImage!, partialImage!, { threshold: 1.0, }), - ).to.eventually.be.rejectedWith(/threshold/); + /threshold/, + ); }); it('should visualize the partial image position in the full image', async function () { const {visualization} = await getImageOccurrence(fullImage!, partialImage!, { visualize: true, }); - expect(visualization).to.not.be.empty; + assert.ok(visualization!.length > 0); }); describe('multiple', function () { @@ -118,14 +116,14 @@ describe('OpenCV helpers', {timeout: 120000}, () => { threshold: 0.8, multiple: true, }); - expect(multiple).to.have.length(3); + assert.strictEqual(multiple!.length, 3); for (const result of multiple!) { - expect(result.rect.x).to.be.above(0); - expect(result.rect.y).to.be.above(0); - expect(result.rect.width).to.be.above(0); - expect(result.rect.height).to.be.above(0); - expect(result.score).to.be.above(0); + assert.ok(result.rect.x > 0); + assert.ok(result.rect.y > 0); + assert.ok(result.rect.width > 0); + assert.ok(result.rect.height > 0); + assert.ok(result.score > 0); } }); @@ -134,7 +132,7 @@ describe('OpenCV helpers', {timeout: 120000}, () => { threshold: 1.0, multiple: true, }); - expect(multiple).to.have.length(1); + assert.strictEqual(multiple!.length, 1); }); it('should visualize the partial image position in the full image', async function () { @@ -144,7 +142,7 @@ describe('OpenCV helpers', {timeout: 120000}, () => { }); for (const result of multiple!) { - expect(result.visualization).to.not.be.empty; + assert.ok(result.visualization!.length > 0); } }); }); diff --git a/packages/opencv/test/unit/opencv.spec.ts b/packages/opencv/test/unit/opencv.spec.ts index c3675cf71..d7f962e51 100644 --- a/packages/opencv/test/unit/opencv.spec.ts +++ b/packages/opencv/test/unit/opencv.spec.ts @@ -1,7 +1,6 @@ +import assert from 'node:assert/strict'; import {describe, it} from 'node:test'; -import {expect} from 'chai'; - import {initOpenCv} from '../../lib/index.js'; describe('OpenCV', function () { @@ -10,6 +9,6 @@ describe('OpenCV', function () { // @ts-expect-error opencv-bindings ships no type declarations; remove this once it does const {default: cv} = await import('opencv-bindings'); const buildInfo = cv.getBuildInformation(); - expect(buildInfo).to.include('OpenCV'); + assert.ok(buildInfo.includes('OpenCV')); }); });