Skip to content

Commit

Permalink
test: migrate to Vitest (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
targos authored Mar 23, 2024
1 parent 3b85a72 commit 5356dd7
Show file tree
Hide file tree
Showing 164 changed files with 341 additions and 40 deletions.
6 changes: 0 additions & 6 deletions jest.config.js

This file was deleted.

3 changes: 0 additions & 3 deletions jest.setup.ts

This file was deleted.

10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"prettier": "prettier --check src",
"prettier-write": "prettier --write src",
"test": "npm run test-only && npm run eslint && npm run prettier && npm run check-types",
"test-only": "jest --coverage",
"test-only": "vitest run --coverage",
"tsc": "npm run clean && npm run tsc-cjs && npm run tsc-esm",
"tsc-cjs": "tsc --project tsconfig.cjs.json",
"tsc-esm": "tsc --project tsconfig.esm.json"
Expand All @@ -88,20 +88,18 @@
},
"homepage": "https://github.com/mljs/spectra-processing#readme",
"devDependencies": {
"@types/jest": "^29.5.12",
"@vitest/coverage-v8": "^1.4.0",
"cheminfo-build": "^1.2.0",
"eslint": "^8.57.0",
"eslint-config-cheminfo-typescript": "^12.2.0",
"esm": "^3.2.25",
"jest": "^29.7.0",
"jest-matcher-deep-close-to": "^3.0.2",
"jscpd": "^3.5.10",
"ml-spectra-fitting": "^4.2.3",
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"spectrum-generator": "^8.0.11",
"ts-jest": "^29.1.2",
"typescript": "^5.4.2"
"typescript": "^5.4.3",
"vitest": "^1.4.0"
},
"dependencies": {
"binary-search": "^1.3.6",
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`test existence of exported functions 1`] = `
[
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, it } from 'vitest';

import * as SpectraProcessing from '../index';

it('test existence of exported functions', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/matrix/__tests__/matrixAbsoluteMedian.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { matrixAbsoluteMedian } from '../matrixAbsoluteMedian';

test('matrixAbsoluteMedian', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/matrix/__tests__/matrixApplyNumericalDecoding.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { matrixApplyNumericalEncoding } from '../matrixApplyNumericalEncoding';
import { matrixNumericalEncoding } from '../matrixNumericalEncoding';

Expand Down
2 changes: 2 additions & 0 deletions src/matrix/__tests__/matrixAutoCorrelation.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { matrixAutoCorrelation } from '../matrixAutoCorrelation';

test('simple', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/matrix/__tests__/matrixBoxPlot.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { matrixBoxPlot } from '../matrixBoxPlot';

test('test matrixBoxPlot even', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/matrix/__tests__/matrixCenterZMean.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { matrixCenterZMean } from '../matrixCenterZMean';

test('matrixCenterZMean', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/matrix/__tests__/matrixCheck.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { matrixCheck } from '../matrixCheck';

test('should throw error', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/matrix/__tests__/matrixClone.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { matrixClone } from '../matrixClone';

import { datasetForEncoding } from './fixtures/encoding';
Expand Down
2 changes: 2 additions & 0 deletions src/matrix/__tests__/matrixColumnsCorrelation.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { matrixColumnsCorrelation } from '../matrixColumnsCorrelation';

test('matrixColumnsCorrelation', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/matrix/__tests__/matrixCreateEmpty.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { matrixCreateEmpty } from '../matrixCreateEmpty';

test('matrixCreateEmpty with default constructor', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/matrix/__tests__/matrixHistogram.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { matrixHistogram } from '../matrixHistogram';

test('simple case', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/matrix/__tests__/matrixMaxAbsoluteZ.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { matrixMaxAbsoluteZ } from '../matrixMaxAbsoluteZ';

test('basic', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/matrix/__tests__/matrixMinMaxAbsoluteZ.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { matrixMinMaxAbsoluteZ } from '../matrixMinMaxAbsoluteZ';

test('basic', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/matrix/__tests__/matrixMinMaxZ.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { matrixMinMaxZ } from '../matrixMinMaxZ';

test('basic', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/matrix/__tests__/matrixNumericalDecoding.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { matrixNumericalDecoding } from '../matrixNumericalDecoding';
import { matrixNumericalEncoding } from '../matrixNumericalEncoding';

Expand Down
2 changes: 2 additions & 0 deletions src/matrix/__tests__/matrixNumericalEncoding.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { matrixNumericalEncoding } from '../matrixNumericalEncoding';

import { datasetForEncoding } from './fixtures/encoding';
Expand Down
2 changes: 2 additions & 0 deletions src/matrix/__tests__/matrixPQN.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { matrixPQN } from '../matrixPQN';

test('Probabilistic quotient normalization method', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/matrix/__tests__/matrixSetSubMatrix.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { matrixSetSubMatrix } from '../matrixSetSubMatrix';

test('simple case', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/matrix/__tests__/matrixToArray.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { matrixToArray } from '../matrixToArray';

test('matrixToArray', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/matrix/__tests__/matrixZPivotRescale.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { matrixZPivotRescale } from '../matrixZPivotRescale';

test('only positive number', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/matrix/__tests__/matrixZRescale.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { matrixZRescale } from '../matrixZRescale';

test('default options', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/matrix/__tests__/matrixZRescalePerColumn.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { matrixZRescalePerColumn } from '../../index';

test('default options', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/reim/__tests__/reimAbsolute.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { reimAbsolute } from '../reimAbsolute';

test('test reimAbsolute', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/reim/__tests__/reimAutoPhaseCorrection.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { readFileSync } from 'node:fs';
import { join } from 'path';

import { expect, test } from 'vitest';

import { reimAutoPhaseCorrection } from '../reimAutoPhaseCorrection';
import { reimPhaseCorrection } from '../reimPhaseCorrection';

Expand Down
2 changes: 2 additions & 0 deletions src/reim/__tests__/reimFFT.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { reimFFT } from '../reimFFT';

test('test reimFFT', () => {
Expand Down
1 change: 1 addition & 0 deletions src/reim/__tests__/reimPhaseCorrection.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import XSAdd from 'ml-xsadd';
import { expect, test } from 'vitest';

import { reimPhaseCorrection } from '../reimPhaseCorrection';

Expand Down
2 changes: 1 addition & 1 deletion src/utils/__tests__/__snapshots__/stringify.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`stringify 1`] = `
"{
Expand Down
2 changes: 2 additions & 0 deletions src/utils/__tests__/createFromToArray.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { createFromToArray } from '../createFromToArray';

test('case when we sample within a specific range with log distribution and include start and end points', () => {
Expand Down
1 change: 1 addition & 0 deletions src/utils/__tests__/createRandomArray.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { optimize } from 'ml-spectra-fitting';
import { expect, test } from 'vitest';

import { xHistogram } from '../../x';
import { createRandomArray } from '../createRandomArray';
Expand Down
2 changes: 2 additions & 0 deletions src/utils/__tests__/createStepArray.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { createStepArray } from '../createStepArray';

test('case when we specify the step', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/__tests__/getRescaler.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { getRescaler } from '../getRescaler';

test('getRescale', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/__tests__/isPowerOfTwo.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { isPowerOfTwo } from '../isPowerOfTwo';

test('check if a power of two is next', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/__tests__/nextPowerOfTwo.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { nextPowerOfTwo } from '../nextPowerOfTwo';

test('check if a power of two is next', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/__tests__/stringify.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { stringify } from '../stringify';

test('stringify', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/x/__tests__/getOutputArray.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { getOutputArray } from '../getOutputArray';

test('no output', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/x/__tests__/xAbsolute.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { xAbsolute } from '../xAbsolute';

test('normal array', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/x/__tests__/xAbsoluteMedian.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { xAbsoluteMedian } from '../xAbsoluteMedian';

test('positive values', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/x/__tests__/xAdd.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { xAdd } from '../xAdd';

test('test xAdd of 2 vectors', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/x/__tests__/xApplyFunctionStr.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { xApplyFunctionStr } from '../xApplyFunctionStr';

test('xApplyFunctionStr', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/x/__tests__/xAutoCorrelation.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Scilab: xcorr(linear)
import { expect, test } from 'vitest'; // Scilab: xcorr(linear)

import { xAutoCorrelation } from '../xAutoCorrelation';

test('auto-correlation linear function', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/x/__tests__/xBoxPlot.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { xBoxPlot } from '../xBoxPlot';

test('test xBoxPlot even', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/x/__tests__/xCheck.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { xCheck } from '../xCheck';

test('should throw on invalid value', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/x/__tests__/xCorrelation.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { xCorrelation } from '../xCorrelation';

// wolfram alpha: xCorrelation([1,2,3],[4,5,6])
Expand Down
2 changes: 2 additions & 0 deletions src/x/__tests__/xCostMatrix.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { xCostMatrix } from '../xCostMatrix';

const array1 = [1, 2, 3, 4, 5];
Expand Down
2 changes: 2 additions & 0 deletions src/x/__tests__/xCrossCorrelation.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { xCrossCorrelation } from '../xCrossCorrelation';

test('cross-correlation linear and constant function', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/x/__tests__/xCumulative.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { xCumulative } from '../xCumulative';

test('zero length array', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/x/__tests__/xDivide.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { xDivide } from '../xDivide';

test('test divide of 2 vectors', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/x/__tests__/xDotProduct.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { xDotProduct } from '../xDotProduct';

test('cross-correlation linear and constant function', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/x/__tests__/xEnsureFloat64.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { xEnsureFloat64 } from '../xEnsureFloat64';

test('normal array', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/x/__tests__/xFindClosestIndex.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, it } from 'vitest';

import { xFindClosestIndex } from '../xFindClosestIndex';

describe('Find closest index in sorted array test', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/x/__tests__/xGetFromToIndex.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { xGetFromToIndex } from '../xGetFromToIndex';

test('no from to', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/x/__tests__/xHilbertTransform.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { xHilbertTransform } from '../xHilbertTransform';
import { xMaxValue } from '../xMaxValue';

Expand Down
1 change: 1 addition & 0 deletions src/x/__tests__/xHistogram.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import XSAdd from 'ml-xsadd';
import { expect, test } from 'vitest';

import { createFromToArray } from '../../utils';
import { xHistogram } from '../xHistogram';
Expand Down
2 changes: 2 additions & 0 deletions src/x/__tests__/xIsEquallySpaced.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { xIsEquallySpaced } from '../xIsEquallySpaced';

test('empty', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/x/__tests__/xIsMonotonic.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { xIsMonotonic } from '../xIsMonotonic';

test('test xIsMonotonic increasing', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/x/__tests__/xMassCenterVectorSimilarity.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { xyMassCenterVector } from '../../xy';
import { xMassCenterVectorSimilarity } from '../xMassCenterVectorSimilarity';

Expand Down
2 changes: 2 additions & 0 deletions src/x/__tests__/xMaxAbsoluteValue.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { xMaxAbsoluteValue } from '../xMaxAbsoluteValue';

test('xMaxAbsoluteValue', () => {
Expand Down
Loading

0 comments on commit 5356dd7

Please sign in to comment.