Skip to content
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

test: replace Jest with Vitest #317

Merged
merged 9 commits into from
Jan 20, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
self-review
targos committed Jan 16, 2025
commit c93539daa89f3528228f29fa993bda7a6a850f43
8 changes: 6 additions & 2 deletions demo/components/CameraFeed.tsx
Original file line number Diff line number Diff line change
@@ -4,16 +4,20 @@

import UnavailableCamera from './UnavailableCamera.js';

export default function CameraFeed() {

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

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.addEventListener('loadedmetadata', () => {
const onLoadedMetadata = () => {
video.play().catch((error: unknown) => console.error(error));
});
};
video.addEventListener('loadedmetadata', onLoadedMetadata);
return () => {
video.removeEventListener('loadedmetadata', onLoadedMetadata);

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

Codecov / codecov/patch

demo/components/CameraFeed.tsx#L14-L19

Added lines #L14 - L19 were not covered by tests
};
}, [selectedCamera]);
if (!selectedCamera) {
return <UnavailableCamera />;
6 changes: 4 additions & 2 deletions demo/components/CameraTransform.tsx
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
snapshotImageRef: RefObject<Image | null>;
}

export default function CameraTransform(props: CameraTransformProps) {

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

GitHub Actions / nodejs / lint-eslint

Missing JSDoc comment
const { canvasInputRef, transform, snapshotUrl, snapshotImageRef } = props;
const [{ selectedCamera }] = useCameraContext();
const videoRef = useRef<HTMLVideoElement>(null);
@@ -38,7 +38,7 @@
const video = videoRef.current as HTMLVideoElement;
let nextFrameRequest: number;
video.srcObject = selectedCamera.stream;
video.addEventListener('loadedmetadata', () => {
const onLoadedMetadata = () => {

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

Codecov / codecov/patch

demo/components/CameraTransform.tsx#L41

Added line #L41 was not covered by tests
video
.play()
.then(() => {
@@ -62,18 +62,20 @@
result = convertColor(result, 'RGBA');
}
writeCanvas(result, canvasOutput);
} catch (error_) {
setError(error_.stack);
console.error(error_);

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

Codecov / codecov/patch

demo/components/CameraTransform.tsx#L65-L67

Added lines #L65 - L67 were not covered by tests
}
nextFrameRequest = requestAnimationFrame(nextFrame);
}
nextFrameRequest = requestAnimationFrame(nextFrame);
})
.catch((error_: unknown) => console.error(error_));

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

Codecov / codecov/patch

demo/components/CameraTransform.tsx#L73

Added line #L73 was not covered by tests
});
};
video.addEventListener('loadedmetadata', onLoadedMetadata);

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

Codecov / codecov/patch

demo/components/CameraTransform.tsx#L75

Added line #L75 was not covered by tests

return () => {
video.removeEventListener('loadedmetadata', onLoadedMetadata);

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

Codecov / codecov/patch

demo/components/CameraTransform.tsx#L78

Added line #L78 was not covered by tests
if (nextFrameRequest) {
cancelAnimationFrame(nextFrameRequest);
}
2 changes: 1 addition & 1 deletion src/__tests__/Image.test.ts
Original file line number Diff line number Diff line change
@@ -221,7 +221,7 @@ test('getCoordinates - with rounding', () => {
test('getCoordinates - bad parameter', () => {
const img = new Image(4, 5);
// @ts-expect-error bad parameter
expect(() => img.getCoordinates('bad')).toThrow(/bad/);
expect(() => img.getCoordinates('bad')).toThrow('bad');
});

test('fill with a constant color', () => {

Unchanged files with check annotations Beta

import Filters from './Filters.js';
import Home from './Home.js';
export default function App() {

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

GitHub Actions / nodejs / lint-eslint

Missing JSDoc comment
return (
<CameraProvider>
<HashRouter>
import { useCameraContext } from '../contexts/cameraContext.js';
export default function CameraSelector() {

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

GitHub Actions / nodejs / lint-eslint

Missing JSDoc comment
const [{ cameras, selectedCamera }, dispatch] = useCameraContext();
if (cameras.length === 0) return null;
return (
camera: { device, stream },
});
})
.catch((error: unknown) => console.error(error));

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

Codecov / codecov/patch

demo/components/CameraSelector.tsx#L32

Added line #L32 was not covered by tests
}
}}
>
canvasInputRef: RefObject<HTMLCanvasElement | null>;
}
export default function CameraSnapshotButton(props: CameraSnapshotButtonProps) {

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

GitHub Actions / nodejs / lint-eslint

Missing JSDoc comment
const { setSnapshotUrl, snapshotImageRef, canvasInputRef } = props;
function handleClick() {
if (canvasInputRef.current) {
title: string;
children: ReactNode;
}
export default function Container(props: ContainerProps) {

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

GitHub Actions / nodejs / lint-eslint

Missing JSDoc comment
return (
<div>
<Navbar />
import type { ReactNode } from 'react';
export default function ErrorAlert(props: { children: ReactNode }) {

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

GitHub Actions / nodejs / lint-eslint

Missing JSDoc comment
return (
<div className="p-4 text-red-800 bg-red-200 rounded">{props.children}</div>
);
import Container from './Container.js';
export default function Filters() {

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

GitHub Actions / nodejs / lint-eslint

Missing JSDoc comment
return <Container title="Filters">Filters</Container>;
}
const testTransform: TransformFunction = testGetFastKeypoints;
export default function Home() {

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

GitHub Actions / nodejs / lint-eslint

Missing JSDoc comment
const snapshotImageRef = useRef<Image>(null);
const canvasInputRef = useRef<HTMLCanvasElement>(null);
const [snapshotUrl, setSnapshotUrl] = useState('');
{ name: 'Filters', href: '/filters', current: false },
];
export default function Navbar() {

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

GitHub Actions / nodejs / lint-eslint

Missing JSDoc comment
const location = useLocation();
const currentNavigation = navigation.map((navItem) => ({
...navItem,
export default function SnapshotImage(props: SnapshotImageProps) {
const { snapshotUrl: snapshot } = props;
return snapshot ? (
<img alt="snapshot" style={{ transform: 'scaleX(-1)' }} src={snapshot} />
) : null;

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

Codecov / codecov/patch

demo/components/SnapshotImage.tsx#L7-L9

Added lines #L7 - L9 were not covered by tests
}
defaultCameraState,
} from './cameraContext.js';
export function CameraProvider(props: { children: ReactNode }) {
const [cameraState, dispatch] = useReducer(
cameraStateReducer,
defaultCameraState,
);
const value = useMemo<CameraContext>(
() => [cameraState, dispatch],
[cameraState],
);
useEffect(() => {
async function getCameras() {
const devices = await navigator.mediaDevices.enumerateDevices();
const cameras = devices.filter((device) => device.kind === 'videoinput');
if (cameras.length > 0) {

Check warning on line 24 in demo/contexts/cameraContext.provider.tsx

Codecov / codecov/patch

demo/contexts/cameraContext.provider.tsx#L11-L24

Added lines #L11 - L24 were not covered by tests
// TODO: handle denied permission
const firstCameraStream = await navigator.mediaDevices.getUserMedia({
video: { deviceId: cameras[0].deviceId },
});
dispatch({
type: 'SET_CAMERAS',
cameras,
firstCamera: { device: cameras[0], stream: firstCameraStream },
});
}
}

Check warning on line 35 in demo/contexts/cameraContext.provider.tsx

Codecov / codecov/patch

demo/contexts/cameraContext.provider.tsx#L26-L35

Added lines #L26 - L35 were not covered by tests
function handleDeviceChange() {
getCameras().catch((error: unknown) => console.error(error));
}

Check warning on line 39 in demo/contexts/cameraContext.provider.tsx

Codecov / codecov/patch

demo/contexts/cameraContext.provider.tsx#L37-L39

Added lines #L37 - L39 were not covered by tests
navigator.mediaDevices.addEventListener('devicechange', handleDeviceChange);
handleDeviceChange();
return () => {
navigator.mediaDevices.removeEventListener(
'devicechange',
handleDeviceChange,
);
};
}, []);

Check warning on line 49 in demo/contexts/cameraContext.provider.tsx

Codecov / codecov/patch

demo/contexts/cameraContext.provider.tsx#L41-L49

Added lines #L41 - L49 were not covered by tests
return (
<cameraContext.Provider value={value}>
{props.children}
</cameraContext.Provider>

Check warning on line 54 in demo/contexts/cameraContext.provider.tsx

Codecov / codecov/patch

demo/contexts/cameraContext.provider.tsx#L51-L54

Added lines #L51 - L54 were not covered by tests
);
}

Check warning on line 56 in demo/contexts/cameraContext.provider.tsx

Codecov / codecov/patch

demo/contexts/cameraContext.provider.tsx#L56

Added line #L56 was not covered by tests
selectedCamera: Camera | null;
}
export const defaultCameraState: CameraState = {
cameras: [],
selectedCamera: null,
};

Check warning on line 18 in demo/contexts/cameraContext.tsx

Codecov / codecov/patch

demo/contexts/cameraContext.tsx#L15-L18

Added lines #L15 - L18 were not covered by tests
export type CameraContext = [
state: CameraState,
dispatch: Dispatch<CameraAction>,
];
export const cameraContext = createContext<CameraContext>([

Check warning on line 25 in demo/contexts/cameraContext.tsx

Codecov / codecov/patch

demo/contexts/cameraContext.tsx#L25

Added line #L25 was not covered by tests
defaultCameraState,
() => {
// Empty
camera: Camera;
};
export const cameraStateReducer = produce(

Check warning on line 47 in demo/contexts/cameraContext.tsx

Codecov / codecov/patch

demo/contexts/cameraContext.tsx#L47

Added line #L47 was not covered by tests
(state: CameraState, action: CameraAction) => {
switch (action.type) {
case 'SET_CAMERAS': {
} else if (state.selectedCamera === null) {
state.selectedCamera = action.firstCamera;
} else if (
!state.cameras.some(

Check warning on line 57 in demo/contexts/cameraContext.tsx

Codecov / codecov/patch

demo/contexts/cameraContext.tsx#L57

Added line #L57 was not covered by tests
(camera) => camera.deviceId === action.firstCamera.device.deviceId,
)
) {
import './index.css';
import App from './components/App.js';

Check warning on line 5 in demo/index.tsx

Codecov / codecov/patch

demo/index.tsx#L5

Added line #L5 was not covered by tests
const root = createRoot(document.querySelector('#root') as HTMLElement);

Check warning on line 7 in demo/index.tsx

Codecov / codecov/patch

demo/index.tsx#L7

Added line #L7 was not covered by tests
root.render(<App />);
tailwindcss: {},
autoprefixer: {},
},
};

Check warning on line 6 in postcss.config.js

Codecov / codecov/patch

postcss.config.js#L6

Added line #L6 was not covered by tests
import { writeSync } from '../../src/save/write.js';
import { overlapImages } from '../../src/featureMatching/visualize/overlapImages.js';
import { readSync } from '../../src/load/read.js';

Check warning on line 3 in scripts/alignImages/alignImages.ts

Codecov / codecov/patch

scripts/alignImages/alignImages.ts#L2-L3

Added lines #L2 - L3 were not covered by tests
import { readFileSync, readdirSync, unlinkSync } from 'fs';
import { join } from 'path';
import { getAffineTransform } from '../../src/index.js';

Check warning on line 6 in scripts/alignImages/alignImages.ts

Codecov / codecov/patch

scripts/alignImages/alignImages.ts#L6

Added line #L6 was not covered by tests
// global variables
const emptyFolder = true; // results
getCrosscheckMatches,
MontageDisposition,
getBestKeypointsInRadius,
} from '../../src/featureMatching.js';
import { readSync, writeSync } from '../../src/index.js';

Check warning on line 14 in scripts/featureMatching/featureMatchingTest.ts

Codecov / codecov/patch

scripts/featureMatching/featureMatchingTest.ts#L13-L14

Added lines #L13 - L14 were not covered by tests
import {
getBrief,
GetBriefOptions,
} from '../../src/featureMatching/descriptors/getBrief.js';
import { GetColorsOptions } from '../../src/featureMatching/utils/getColors.js';
import { getMinMax } from '../../src/utils/getMinMax.js';

Check warning on line 20 in scripts/featureMatching/featureMatchingTest.ts

Codecov / codecov/patch

scripts/featureMatching/featureMatchingTest.ts#L18-L20

Added lines #L18 - L20 were not covered by tests
import util from 'util';
import { sliceBrief } from '../../src/featureMatching/descriptors/utils/sliceBrief.js';

Check warning on line 23 in scripts/featureMatching/featureMatchingTest.ts

Codecov / codecov/patch

scripts/featureMatching/featureMatchingTest.ts#L23

Added line #L23 was not covered by tests
util.inspect.defaultOptions.depth = 5;
const getBriefOptions: GetBriefOptions = {
// generate some variations of the alphabet image for feature matching
// run this script with: ts-node --log-error generateFMtestImages.ts
import { readSync, writeSync, Image } from '../../src/index.js';

Check warning on line 3 in scripts/featureMatching/generateFMtestImages.ts

Codecov / codecov/patch

scripts/featureMatching/generateFMtestImages.ts#L3

Added line #L3 was not covered by tests
import { join } from 'path';
console.log(__dirname);
// @eslint-ignore
import { Image } from '../src/Image.js';
import { getHarrisScore } from '../src/featureMatching/getHarrisScore.js';

Check warning on line 3 in scripts/testHarris.ts

Codecov / codecov/patch

scripts/testHarris.ts#L2-L3

Added lines #L2 - L3 were not covered by tests
const fastRadius = 3;
RoiKind,
readSync,
writeSync,
} from '../src/index.js';

Check warning on line 11 in scripts/tophatTest.ts

Codecov / codecov/patch

scripts/tophatTest.ts#L11

Added line #L11 was not covered by tests
const disk12 = [
[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0],