Skip to content

test: replace Jest with Vitest #317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 0 additions & 7 deletions .eslintrc.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/release-head.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
node-version: '22.x'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/typedoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
pull_request:

env:
NODE_VERSION: 20.x
NODE_VERSION: 22.x
ENTRY_FILE: 'src/index.ts'

jobs:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ yarn.lock
.DS_Store

lib
lib-esm
lib-cjs

# debug images
src/**/*.tif
Expand All @@ -136,3 +136,5 @@ scripts/**/**.png
scripts/**/**.json

private

.jest-image-snapshot-touched-files
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ Image processing and manipulation in JavaScript.

## [API](https://image-js.github.io/image-js-typescript/)

Look at the [examples](./examples) directory for how the API is being designed.

## Development

See [Development documentation](./Development.md).
Expand Down
2 changes: 1 addition & 1 deletion api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
*/
"mainEntryPointFilePath": "<projectFolder>/lib-esm/index.d.ts",
"mainEntryPointFilePath": "<projectFolder>/lib/index.d.ts",

/**
* A list of NPM package names whose exports should be treated as part of this package.
Expand Down
4 changes: 0 additions & 4 deletions demo/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
root: true
extends: [cheminfo-react, cheminfo-typescript]
rules:
no-console: off
6 changes: 3 additions & 3 deletions demo/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { HashRouter, Route, Routes } from 'react-router-dom';

import { CameraProvider } from '../contexts/cameraContext';
import { CameraProvider } from '../contexts/cameraContext.provider.js';

import Filters from './Filters';
import Home from './Home';
import Filters from './Filters.js';
import Home from './Home.js';

export default function App() {

Check warning on line 8 in demo/components/App.tsx

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc comment
return (
<CameraProvider>
<HashRouter>
Expand Down
12 changes: 8 additions & 4 deletions demo/components/CameraFeed.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { useEffect, useRef } from 'react';

import { useCameraContext } from '../contexts/cameraContext';
import { useCameraContext } from '../contexts/cameraContext.js';

import UnavailableCamera from './UnavailableCamera';
import UnavailableCamera from './UnavailableCamera.js';

export default function CameraFeed() {

Check warning on line 7 in demo/components/CameraFeed.tsx

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc comment
const [{ selectedCamera }] = useCameraContext();
const videoRef = useRef<HTMLVideoElement>(null);
useEffect(() => {
const video = videoRef.current;
if (!video || !selectedCamera) return;
video.srcObject = selectedCamera.stream;
video.onloadedmetadata = () => {
video.play().catch((err: unknown) => console.error(err));
const onLoadedMetadata = () => {
video.play().catch((error: unknown) => console.error(error));
};
video.addEventListener('loadedmetadata', onLoadedMetadata);
return () => {
video.removeEventListener('loadedmetadata', onLoadedMetadata);
};
}, [selectedCamera]);
if (!selectedCamera) {
Expand Down
4 changes: 2 additions & 2 deletions demo/components/CameraSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCameraContext } from '../contexts/cameraContext';
import { useCameraContext } from '../contexts/cameraContext.js';

export default function CameraSelector() {

Check warning on line 3 in demo/components/CameraSelector.tsx

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc comment
const [{ cameras, selectedCamera }, dispatch] = useCameraContext();
if (cameras.length === 0) return null;
return (
Expand Down Expand Up @@ -29,7 +29,7 @@
camera: { device, stream },
});
})
.catch((err: unknown) => console.error(err));
.catch((error: unknown) => console.error(error));
}
}}
>
Expand Down
9 changes: 5 additions & 4 deletions demo/components/CameraSnapshotButton.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { MutableRefObject, RefObject } from 'react';
import type { RefObject } from 'react';

import { readCanvas, Image } from '../../src';
import type { Image } from '../../src/index.js';
import { readCanvas } from '../../src/index.js';

interface CameraSnapshotButtonProps {
snapshotImageRef: MutableRefObject<Image | null>;
snapshotImageRef: RefObject<Image | null>;
setSnapshotUrl: (snapshotUrl: string) => void;
canvasInputRef: RefObject<HTMLCanvasElement>;
canvasInputRef: RefObject<HTMLCanvasElement | null>;
}

export default function CameraSnapshotButton(props: CameraSnapshotButtonProps) {

Check warning on line 12 in demo/components/CameraSnapshotButton.tsx

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc comment
const { setSnapshotUrl, snapshotImageRef, canvasInputRef } = props;
function handleClick() {
if (canvasInputRef.current) {
Expand Down
30 changes: 17 additions & 13 deletions demo/components/CameraTransform.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import { RefObject, useEffect, useRef, useState } from 'react';
import type { RefObject } from 'react';
import { useEffect, useRef, useState } from 'react';

import { Image, readCanvas, writeCanvas } from '../../src';
import { convertColor } from '../../src/operations/convertColor';
import { useCameraContext } from '../contexts/cameraContext';
import type { Image } from '../../src/index.js';
import { readCanvas, writeCanvas } from '../../src/index.js';
import { convertColor } from '../../src/operations/convertColor.js';
import { useCameraContext } from '../contexts/cameraContext.js';

import ErrorAlert from './ErrorAlert';
import SnapshotImage from './SnapshotImage';
import UnavailableCamera from './UnavailableCamera';
import ErrorAlert from './ErrorAlert.js';
import SnapshotImage from './SnapshotImage.js';
import UnavailableCamera from './UnavailableCamera.js';

export type TransformFunction =
| ((image: Image) => Image)
| ((image: Image, snapshot: Image | null) => Image);

interface CameraTransformProps {
transform: TransformFunction;
canvasInputRef: RefObject<HTMLCanvasElement>;
canvasInputRef: RefObject<HTMLCanvasElement | null>;
snapshotUrl: string;
snapshotImageRef: RefObject<Image | null>;
}

export default function CameraTransform(props: CameraTransformProps) {

Check warning on line 24 in demo/components/CameraTransform.tsx

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc comment
const { canvasInputRef, transform, snapshotUrl, snapshotImageRef } = props;
const [{ selectedCamera }] = useCameraContext();
const videoRef = useRef<HTMLVideoElement>(null);
Expand All @@ -36,7 +38,7 @@
const video = videoRef.current as HTMLVideoElement;
let nextFrameRequest: number;
video.srcObject = selectedCamera.stream;
video.onloadedmetadata = () => {
const onLoadedMetadata = () => {
video
.play()
.then(() => {
Expand All @@ -60,18 +62,20 @@
result = convertColor(result, 'RGBA');
}
writeCanvas(result, canvasOutput);
} catch (err) {
setError(err.stack);
console.error(err);
} catch (error_) {
setError(error_.stack);
console.error(error_);
}
nextFrameRequest = requestAnimationFrame(nextFrame);
}
nextFrameRequest = requestAnimationFrame(nextFrame);
})
.catch((err: unknown) => console.error(err));
.catch((error_: unknown) => console.error(error_));
};
video.addEventListener('loadedmetadata', onLoadedMetadata);

return () => {
video.removeEventListener('loadedmetadata', onLoadedMetadata);
if (nextFrameRequest) {
cancelAnimationFrame(nextFrameRequest);
}
Expand Down
4 changes: 2 additions & 2 deletions demo/components/Container.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ReactNode } from 'react';
import type { ReactNode } from 'react';

import Navbar from './Navbar';
import Navbar from './Navbar.js';

interface ContainerProps {
title: string;
children: ReactNode;
}
export default function Container(props: ContainerProps) {

Check warning on line 9 in demo/components/Container.tsx

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc comment
return (
<div>
<Navbar />
Expand Down
2 changes: 1 addition & 1 deletion demo/components/ErrorAlert.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ReactNode } from 'react';
import type { ReactNode } from 'react';

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

Check warning on line 3 in demo/components/ErrorAlert.tsx

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc comment
return (
<div className="p-4 text-red-800 bg-red-200 rounded">{props.children}</div>
);
Expand Down
2 changes: 1 addition & 1 deletion demo/components/Filters.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Container from './Container';
import Container from './Container.js';

export default function Filters() {

Check warning on line 3 in demo/components/Filters.tsx

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc comment
return <Container title="Filters">Filters</Container>;
}
14 changes: 7 additions & 7 deletions demo/components/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { useRef, useState } from 'react';

import { Image } from '../../src';
import type { Image } from '../../src/index.js';

import CameraSelector from './CameraSelector';
import CameraSnapshotButton from './CameraSnapshotButton';
import CameraTransform, { TransformFunction } from './CameraTransform';
import Container from './Container';
import { testGetFastKeypoints } from './testFunctions/testGetFastKeypoints';
import CameraSelector from './CameraSelector.js';
import CameraSnapshotButton from './CameraSnapshotButton.js';
import type { TransformFunction } from './CameraTransform.js';
import CameraTransform from './CameraTransform.js';
import Container from './Container.js';
import { testGetFastKeypoints } from './testFunctions/testGetFastKeypoints.js';

const testTransform: TransformFunction = testGetFastKeypoints;

export default function Home() {

Check warning on line 14 in demo/components/Home.tsx

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc comment
const snapshotImageRef = useRef<Image>(null);
const canvasInputRef = useRef<HTMLCanvasElement>(null);
const [snapshotUrl, setSnapshotUrl] = useState('');
console.log(snapshotUrl);
return (
<Container title="Home">
<div className="space-y-1">
Expand Down
4 changes: 3 additions & 1 deletion demo/components/SnapshotImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ interface SnapshotImageProps {

export default function SnapshotImage(props: SnapshotImageProps) {
const { snapshotUrl: snapshot } = props;
return <img style={{ transform: 'scaleX(-1)' }} src={snapshot} />;
return snapshot ? (
<img alt="snapshot" style={{ transform: 'scaleX(-1)' }} src={snapshot} />
) : null;
}
2 changes: 1 addition & 1 deletion demo/components/UnavailableCamera.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ErrorAlert from './ErrorAlert';
import ErrorAlert from './ErrorAlert.js';

export default function UnavailableCamera() {
return <ErrorAlert>Camera is not available.</ErrorAlert>;
Expand Down
6 changes: 3 additions & 3 deletions demo/components/comparisonFunctions/testComputeSsim.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Image } from '../../../src';
import { computeSsim } from '../../../src/compare/computeSsim';
import { computeSsim } from '../../../src/compare/computeSsim.js';
import { Image } from '../../../src/index.js';

/**
* Compute the structural similarity of the input image and the image blurred.
*
* @param image - Input image.
* @param snapshot
* @returns The structural similarity matrix.
*/
export function testComputeSsim(image: Image, snapshot: Image | null): Image {
Expand Down
5 changes: 2 additions & 3 deletions demo/components/testFunctions/testCannyEdge.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { convertBinaryToGrey, Image } from '../../../src';
import type { Image } from '../../../src/index.js';
import { convertBinaryToGrey } from '../../../src/index.js';

/**
* Detect the edges in the image using Canny edge detection
*
* @param image - Input image.
* @returns The treated image.
*/
Expand All @@ -19,7 +19,6 @@ export function testCannyEdge(image: Image): Image {

/**
* Detect the edges in the image using Canny edge detection and overlay the edges on the original image.
*
* @param image - Input image.
* @returns The treated image.
*/
Expand Down
5 changes: 2 additions & 3 deletions demo/components/testFunctions/testColorRois.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Image } from '../../../src';
import { fromMask, colorRois } from '../../../src/roi';
import { Image } from '../../../src/index.js';
import { fromMask, colorRois } from '../../../src/roi/index.js';

/**
* Make a mask out of the image and detect all ROIs. Returns only the white ROIs on a black background.
*
* @param image - Input image.
* @returns The treated image.
*/
Expand Down
3 changes: 1 addition & 2 deletions demo/components/testFunctions/testCopyTo.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Image } from '../../../src';
import { Image } from '../../../src/index.js';

/**
* Copy a black and a red square to the source image.
*
* @param image - Input image.
* @returns The treated image.
*/
Expand Down
11 changes: 5 additions & 6 deletions demo/components/testFunctions/testCorrectColor.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Image } from '../../../src';
import { polishAltered } from '../../../src/correctColor/__tests__/testUtils/imageColors';
import { referenceColorCard } from '../../../src/correctColor/__tests__/testUtils/referenceColorCard';
import { correctColor } from '../../../src/correctColor/correctColor';
import { polishAltered } from '../../../src/correctColor/__tests__/testUtils/imageColors.js';
import { referenceColorCard } from '../../../src/correctColor/__tests__/testUtils/referenceColorCard.js';
import { correctColor } from '../../../src/correctColor/correctColor.js';
import {
getMeasuredColors,
getReferenceColors,
} from '../../../src/correctColor/utils/formatData';
} from '../../../src/correctColor/utils/formatData.js';
import type { Image } from '../../../src/index.js';

/**
* Copy a black and a red square to the source image.
*
* @param image - Input image.
* @returns The treated image.
*/
Expand Down
2 changes: 1 addition & 1 deletion demo/components/testFunctions/testCrop.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Image } from '../../../src';
import type { Image } from '../../../src/index.js';
// options
const cropImageRatio = 2; // defines the size of the cropped image
const interval = 2; // defines the speed
Expand Down
3 changes: 1 addition & 2 deletions demo/components/testFunctions/testDerivativeFilter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Image } from '../../../src';
import type { Image } from '../../../src/index.js';

/**
* Apply a derivative filter to the source image.
*
* @param image - Input image.
* @returns The treated image.
*/
Expand Down
3 changes: 1 addition & 2 deletions demo/components/testFunctions/testExtract.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { fromMask, Image } from '../../../src';
import { fromMask, Image } from '../../../src/index.js';

/**
* Extract the pixels of a mask from the image.
*
* @param image - Input image.
* @returns The treated image.
*/
Expand Down
5 changes: 3 additions & 2 deletions demo/components/testFunctions/testGetBorderPoints.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { fromMask, Image, Mask } from '../../../src';
import type { Image } from '../../../src/index.js';
import { fromMask, Mask } from '../../../src/index.js';
/**
* Paint the border of the larger black ROI on the image.
* @param image The image to process
* @param image - The image to process
* @returns The processed image.
*/
export function testGetBorderPoints(image: Image): Image {
Expand Down
4 changes: 2 additions & 2 deletions demo/components/testFunctions/testGetConvexHull.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { fromMask, Image } from '../../../src';
import type { Image } from '../../../src/index.js';
import { fromMask } from '../../../src/index.js';

/**
* Draw the convex Hull polygon of the largest ROI in green and display the filled ROI in purple.
*
* @param image - Input image.
* @returns The image with the convex Hull.
*/
Expand Down
5 changes: 2 additions & 3 deletions demo/components/testFunctions/testGetFastKeypoints.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Image } from '../../../src';
import { getFastKeypoints } from '../../../src/featureMatching/keypoints/getFastKeypoints';
import { getFastKeypoints } from '../../../src/featureMatching/keypoints/getFastKeypoints.js';
import type { Image } from '../../../src/index.js';

/**
* Find the FAST keypoints in the video.
*
* @param image - Input image.
* @returns The image with the fast keypoints.
*/
Expand Down
Loading
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy