Skip to content

Commit 156fa0f

Browse files
committed
chore: migrate to Vitest
1 parent 692b155 commit 156fa0f

File tree

450 files changed

+1821
-1795
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

450 files changed

+1821
-1795
lines changed

.eslintrc.yml

-7
This file was deleted.

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ yarn.lock
124124
.DS_Store
125125

126126
lib
127-
lib-esm
127+
lib-cjs
128128

129129
# debug images
130130
src/**/*.tif
@@ -136,3 +136,5 @@ scripts/**/**.png
136136
scripts/**/**.json
137137

138138
private
139+
140+
.jest-image-snapshot-touched-files

api-extractor.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
*
4646
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
4747
*/
48-
"mainEntryPointFilePath": "<projectFolder>/lib-esm/index.d.ts",
48+
"mainEntryPointFilePath": "<projectFolder>/lib/index.d.ts",
4949

5050
/**
5151
* A list of NPM package names whose exports should be treated as part of this package.

demo/.eslintrc.yml

-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
root: true
2-
extends: [cheminfo-react, cheminfo-typescript]
3-
rules:
4-
no-console: off

demo/components/App.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { HashRouter, Route, Routes } from 'react-router-dom';
22

3-
import { CameraProvider } from '../contexts/cameraContext';
3+
import { CameraProvider } from '../contexts/cameraContext.provider.js';
44

5-
import Filters from './Filters';
6-
import Home from './Home';
5+
import Filters from './Filters.js';
6+
import Home from './Home.js';
77

88
export default function App() {
99
return (

demo/components/CameraFeed.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { useEffect, useRef } from 'react';
22

3-
import { useCameraContext } from '../contexts/cameraContext';
3+
import { useCameraContext } from '../contexts/cameraContext.js';
44

5-
import UnavailableCamera from './UnavailableCamera';
5+
import UnavailableCamera from './UnavailableCamera.js';
66

77
export default function CameraFeed() {
88
const [{ selectedCamera }] = useCameraContext();
@@ -11,9 +11,9 @@ export default function CameraFeed() {
1111
const video = videoRef.current;
1212
if (!video || !selectedCamera) return;
1313
video.srcObject = selectedCamera.stream;
14-
video.onloadedmetadata = () => {
15-
video.play().catch((err: unknown) => console.error(err));
16-
};
14+
video.addEventListener('loadedmetadata', () => {
15+
video.play().catch((error: unknown) => console.error(error));
16+
});
1717
}, [selectedCamera]);
1818
if (!selectedCamera) {
1919
return <UnavailableCamera />;

demo/components/CameraSelector.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCameraContext } from '../contexts/cameraContext';
1+
import { useCameraContext } from '../contexts/cameraContext.js';
22

33
export default function CameraSelector() {
44
const [{ cameras, selectedCamera }, dispatch] = useCameraContext();
@@ -29,7 +29,7 @@ export default function CameraSelector() {
2929
camera: { device, stream },
3030
});
3131
})
32-
.catch((err: unknown) => console.error(err));
32+
.catch((error: unknown) => console.error(error));
3333
}
3434
}}
3535
>

demo/components/CameraSnapshotButton.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { MutableRefObject, RefObject } from 'react';
1+
import type { RefObject } from 'react';
22

3-
import { readCanvas, Image } from '../../src';
3+
import type { Image } from '../../src/index.js';
4+
import { readCanvas } from '../../src/index.js';
45

56
interface CameraSnapshotButtonProps {
6-
snapshotImageRef: MutableRefObject<Image | null>;
7+
snapshotImageRef: RefObject<Image | null>;
78
setSnapshotUrl: (snapshotUrl: string) => void;
8-
canvasInputRef: RefObject<HTMLCanvasElement>;
9+
canvasInputRef: RefObject<HTMLCanvasElement | null>;
910
}
1011

1112
export default function CameraSnapshotButton(props: CameraSnapshotButtonProps) {

demo/components/CameraTransform.tsx

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
import { RefObject, useEffect, useRef, useState } from 'react';
1+
import type { RefObject } from 'react';
2+
import { useEffect, useRef, useState } from 'react';
23

3-
import { Image, readCanvas, writeCanvas } from '../../src';
4-
import { convertColor } from '../../src/operations/convertColor';
5-
import { useCameraContext } from '../contexts/cameraContext';
4+
import type { Image } from '../../src/index.js';
5+
import { readCanvas, writeCanvas } from '../../src/index.js';
6+
import { convertColor } from '../../src/operations/convertColor.js';
7+
import { useCameraContext } from '../contexts/cameraContext.js';
68

7-
import ErrorAlert from './ErrorAlert';
8-
import SnapshotImage from './SnapshotImage';
9-
import UnavailableCamera from './UnavailableCamera';
9+
import ErrorAlert from './ErrorAlert.js';
10+
import SnapshotImage from './SnapshotImage.js';
11+
import UnavailableCamera from './UnavailableCamera.js';
1012

1113
export type TransformFunction =
1214
| ((image: Image) => Image)
1315
| ((image: Image, snapshot: Image | null) => Image);
1416

1517
interface CameraTransformProps {
1618
transform: TransformFunction;
17-
canvasInputRef: RefObject<HTMLCanvasElement>;
19+
canvasInputRef: RefObject<HTMLCanvasElement | null>;
1820
snapshotUrl: string;
1921
snapshotImageRef: RefObject<Image | null>;
2022
}
@@ -36,7 +38,7 @@ export default function CameraTransform(props: CameraTransformProps) {
3638
const video = videoRef.current as HTMLVideoElement;
3739
let nextFrameRequest: number;
3840
video.srcObject = selectedCamera.stream;
39-
video.onloadedmetadata = () => {
41+
video.addEventListener('loadedmetadata', () => {
4042
video
4143
.play()
4244
.then(() => {
@@ -60,16 +62,16 @@ export default function CameraTransform(props: CameraTransformProps) {
6062
result = convertColor(result, 'RGBA');
6163
}
6264
writeCanvas(result, canvasOutput);
63-
} catch (err) {
64-
setError(err.stack);
65-
console.error(err);
65+
} catch (error_) {
66+
setError(error_.stack);
67+
console.error(error_);
6668
}
6769
nextFrameRequest = requestAnimationFrame(nextFrame);
6870
}
6971
nextFrameRequest = requestAnimationFrame(nextFrame);
7072
})
71-
.catch((err: unknown) => console.error(err));
72-
};
73+
.catch((error_: unknown) => console.error(error_));
74+
});
7375

7476
return () => {
7577
if (nextFrameRequest) {

demo/components/Container.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ReactNode } from 'react';
1+
import type { ReactNode } from 'react';
22

3-
import Navbar from './Navbar';
3+
import Navbar from './Navbar.js';
44

55
interface ContainerProps {
66
title: string;

demo/components/ErrorAlert.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ReactNode } from 'react';
1+
import type { ReactNode } from 'react';
22

33
export default function ErrorAlert(props: { children: ReactNode }) {
44
return (

demo/components/Filters.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Container from './Container';
1+
import Container from './Container.js';
22

33
export default function Filters() {
44
return <Container title="Filters">Filters</Container>;

demo/components/Home.tsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { useRef, useState } from 'react';
22

3-
import { Image } from '../../src';
3+
import type { Image } from '../../src/index.js';
44

5-
import CameraSelector from './CameraSelector';
6-
import CameraSnapshotButton from './CameraSnapshotButton';
7-
import CameraTransform, { TransformFunction } from './CameraTransform';
8-
import Container from './Container';
9-
import { testGetFastKeypoints } from './testFunctions/testGetFastKeypoints';
5+
import CameraSelector from './CameraSelector.js';
6+
import CameraSnapshotButton from './CameraSnapshotButton.js';
7+
import type { TransformFunction } from './CameraTransform.js';
8+
import CameraTransform from './CameraTransform.js';
9+
import Container from './Container.js';
10+
import { testGetFastKeypoints } from './testFunctions/testGetFastKeypoints.js';
1011

1112
const testTransform: TransformFunction = testGetFastKeypoints;
1213

demo/components/UnavailableCamera.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ErrorAlert from './ErrorAlert';
1+
import ErrorAlert from './ErrorAlert.js';
22

33
export default function UnavailableCamera() {
44
return <ErrorAlert>Camera is not available.</ErrorAlert>;

demo/components/comparisonFunctions/testComputeSsim.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Image } from '../../../src';
2-
import { computeSsim } from '../../../src/compare/computeSsim';
1+
import { computeSsim } from '../../../src/compare/computeSsim.js';
2+
import { Image } from '../../../src/index.js';
33

44
/**
55
* Compute the structural similarity of the input image and the image blurred.
6-
*
76
* @param image - Input image.
7+
* @param snapshot
88
* @returns The structural similarity matrix.
99
*/
1010
export function testComputeSsim(image: Image, snapshot: Image | null): Image {

demo/components/testFunctions/testCannyEdge.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { convertBinaryToGrey, Image } from '../../../src';
1+
import type { Image } from '../../../src/index.js';
2+
import { convertBinaryToGrey } from '../../../src/index.js';
23

34
/**
45
* Detect the edges in the image using Canny edge detection
5-
*
66
* @param image - Input image.
77
* @returns The treated image.
88
*/
@@ -19,7 +19,6 @@ export function testCannyEdge(image: Image): Image {
1919

2020
/**
2121
* Detect the edges in the image using Canny edge detection and overlay the edges on the original image.
22-
*
2322
* @param image - Input image.
2423
* @returns The treated image.
2524
*/

demo/components/testFunctions/testColorRois.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { Image } from '../../../src';
2-
import { fromMask, colorRois } from '../../../src/roi';
1+
import { Image } from '../../../src/index.js';
2+
import { fromMask, colorRois } from '../../../src/roi/index.js';
33

44
/**
55
* Make a mask out of the image and detect all ROIs. Returns only the white ROIs on a black background.
6-
*
76
* @param image - Input image.
87
* @returns The treated image.
98
*/

demo/components/testFunctions/testCopyTo.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { Image } from '../../../src';
1+
import { Image } from '../../../src/index.js';
22

33
/**
44
* Copy a black and a red square to the source image.
5-
*
65
* @param image - Input image.
76
* @returns The treated image.
87
*/

demo/components/testFunctions/testCorrectColor.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { Image } from '../../../src';
2-
import { polishAltered } from '../../../src/correctColor/__tests__/testUtils/imageColors';
3-
import { referenceColorCard } from '../../../src/correctColor/__tests__/testUtils/referenceColorCard';
4-
import { correctColor } from '../../../src/correctColor/correctColor';
1+
import { polishAltered } from '../../../src/correctColor/__tests__/testUtils/imageColors.js';
2+
import { referenceColorCard } from '../../../src/correctColor/__tests__/testUtils/referenceColorCard.js';
3+
import { correctColor } from '../../../src/correctColor/correctColor.js';
54
import {
65
getMeasuredColors,
76
getReferenceColors,
8-
} from '../../../src/correctColor/utils/formatData';
7+
} from '../../../src/correctColor/utils/formatData.js';
8+
import type { Image } from '../../../src/index.js';
99

1010
/**
1111
* Copy a black and a red square to the source image.
12-
*
1312
* @param image - Input image.
1413
* @returns The treated image.
1514
*/

demo/components/testFunctions/testCrop.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Image } from '../../../src';
1+
import type { Image } from '../../../src/index.js';
22
// options
33
const cropImageRatio = 2; // defines the size of the cropped image
44
const interval = 2; // defines the speed

demo/components/testFunctions/testDerivativeFilter.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { Image } from '../../../src';
1+
import type { Image } from '../../../src/index.js';
22

33
/**
44
* Apply a derivative filter to the source image.
5-
*
65
* @param image - Input image.
76
* @returns The treated image.
87
*/

demo/components/testFunctions/testExtract.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { fromMask, Image } from '../../../src';
1+
import { fromMask, Image } from '../../../src/index.js';
22

33
/**
44
* Extract the pixels of a mask from the image.
5-
*
65
* @param image - Input image.
76
* @returns The treated image.
87
*/

demo/components/testFunctions/testGetBorderPoints.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { fromMask, Image, Mask } from '../../../src';
1+
import type { Image } from '../../../src/index.js';
2+
import { fromMask, Mask } from '../../../src/index.js';
23
/**
34
* Paint the border of the larger black ROI on the image.
4-
* @param image The image to process
5+
* @param image - The image to process
56
* @returns The processed image.
67
*/
78
export function testGetBorderPoints(image: Image): Image {

demo/components/testFunctions/testGetConvexHull.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { fromMask, Image } from '../../../src';
1+
import type { Image } from '../../../src/index.js';
2+
import { fromMask } from '../../../src/index.js';
23

34
/**
45
* Draw the convex Hull polygon of the largest ROI in green and display the filled ROI in purple.
5-
*
66
* @param image - Input image.
77
* @returns The image with the convex Hull.
88
*/

demo/components/testFunctions/testGetFastKeypoints.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { Image } from '../../../src';
2-
import { getFastKeypoints } from '../../../src/featureMatching/keypoints/getFastKeypoints';
1+
import { getFastKeypoints } from '../../../src/featureMatching/keypoints/getFastKeypoints.js';
2+
import type { Image } from '../../../src/index.js';
33

44
/**
55
* Find the FAST keypoints in the video.
6-
*
76
* @param image - Input image.
87
* @returns The image with the fast keypoints.
98
*/

demo/components/testFunctions/testGetFeret.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { fromMask, Image } from '../../../src';
1+
import type { Image } from '../../../src/index.js';
2+
import { fromMask } from '../../../src/index.js';
23

34
/**
45
* Draw the Feret diameters of the largest ROI detected in the image.
5-
*
66
* @param image - Input image.
77
* @returns The image with the Feret diameters.
88
*/

demo/components/testFunctions/testGetMask.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { fromMask, Image } from '../../../src';
1+
import type { Image } from '../../../src/index.js';
2+
import { fromMask } from '../../../src/index.js';
23
/**
34
* Paint the border of the larger black ROI on the image.
4-
* @param image The image to process
5+
* @param image - The image to process
56
* @returns The processed image.
67
*/
78
export function testGetContourMask(image: Image): Image {

demo/components/testFunctions/testGetMbr.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { fromMask, Image } from '../../../src';
1+
import type { Image } from '../../../src/index.js';
2+
import { fromMask } from '../../../src/index.js';
23

34
/**
45
* Draw the MBR of the largest ROI.
5-
*
66
* @param image - Input image.
77
* @returns The image with the MBR.
88
*/

demo/components/testFunctions/testLevel.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { Image } from '../../../src';
1+
import type { Image } from '../../../src/index.js';
22

33
/**
44
* Enhance contrast of the source image using level.
5-
*
65
* @param image - Input image.
76
* @returns The treated image.
87
*/

0 commit comments

Comments
 (0)