Skip to content

Commit

Permalink
chore: migrate from jest to vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny committed Apr 15, 2024
1 parent 92af328 commit 5f950d9
Show file tree
Hide file tree
Showing 23 changed files with 37 additions and 50 deletions.
4 changes: 0 additions & 4 deletions babel.config.js

This file was deleted.

9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
"build": "npm run tsc-esm && cheminfo-build --entry lib-esm/index.js --root GSD",
"check-types": "tsc --noEmit",
"clean": "rimraf lib lib-esm",
"example": "nodemon -w src -w examples/example.js -r esm examples/example.js",
"eslint": "eslint src --cache",
"eslint-fix": "npm run eslint -- --fix",
"prepack": "npm run tsc",
"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 Down Expand Up @@ -55,9 +54,7 @@
"trailingComma": "all"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.24.1",
"@babel/preset-typescript": "^7.24.1",
"@types/jest": "^29.5.12",
"@vitest/coverage-v8": "^1.5.0",
"cheminfo-build": "^1.2.0",
"eslint": "^8.57.0",
"eslint-config-cheminfo-typescript": "^12.3.0",
Expand All @@ -66,11 +63,11 @@
"jest-matcher-deep-close-to": "^3.0.2",
"mf-global": "^3.0.18",
"ml-stat": "^1.3.3",
"nodemon": "^3.1.0",
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"spectrum-generator": "^8.0.11",
"typescript": "^5.4.5",
"vitest": "^1.5.0",
"xy-parser": "^5.0.5"
},
"dependencies": {
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/ethylvinylether.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { readFileSync } from 'fs';

import { describe, expect, it } from 'vitest';

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

describe('Global spectra deconvolution NMR spectra', () => {
Expand Down
4 changes: 1 addition & 3 deletions src/__tests__/gaussian-noise.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type { DataXY } from 'cheminfo-types';
import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to';
import { describe, expect, it } from 'vitest';

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

expect.extend({ toBeDeepCloseTo, toMatchCloseTo });

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { generateSpectrum } = require('spectrum-generator');

Expand Down
4 changes: 1 addition & 3 deletions src/__tests__/gaussian-noiseParam.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type { DataXY } from 'cheminfo-types';
import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to';
import { describe, expect, it } from 'vitest';

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

expect.extend({ toBeDeepCloseTo, toMatchCloseTo });

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { generateSpectrum } = require('spectrum-generator');

Expand Down
4 changes: 1 addition & 3 deletions src/__tests__/gaussian-overlapping.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import type { DataXY } from 'cheminfo-types';
import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to';
import { describe, expect, it } from 'vitest';

import { gsd } from '../gsd';
import { optimizePeaks } from '../post/optimizePeaks';

expect.extend({ toBeDeepCloseTo, toMatchCloseTo });

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { generateSpectrum } = require('spectrum-generator');

Expand Down
4 changes: 1 addition & 3 deletions src/__tests__/gaussian-smooth.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type { DataXY } from 'cheminfo-types';
import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to';
import { describe, expect, it } from 'vitest';

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

expect.extend({ toBeDeepCloseTo, toMatchCloseTo });

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { generateSpectrum } = require('spectrum-generator');

Expand Down
4 changes: 1 addition & 3 deletions src/__tests__/gaussian.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type { DataXY } from 'cheminfo-types';
import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to';
import { describe, expect, it } from 'vitest';

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

expect.extend({ toBeDeepCloseTo, toMatchCloseTo });

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { generateSpectrum } = require('spectrum-generator');

Expand Down
4 changes: 1 addition & 3 deletions src/__tests__/power.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type { DataXY } from 'cheminfo-types';
import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to';
import { describe, expect, it } from 'vitest';

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

expect.extend({ toBeDeepCloseTo, toMatchCloseTo });

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

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

describe('Throw Errors', () => {
Expand Down
4 changes: 1 addition & 3 deletions src/__tests__/ubiquitin.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { readFileSync } from 'fs';

import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to';
import { describe, expect, it } from 'vitest';
import { parseXY } from 'xy-parser';

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

expect.extend({ toBeDeepCloseTo, toMatchCloseTo });

// var gsd = require("../src/index");
// var optimizePeaks = require("../src/optimize");

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

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

describe('Simple test cases', () => {
Expand Down
4 changes: 1 addition & 3 deletions src/post/__tests__/broadenPeaks.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to';
import { describe, expect, it } from 'vitest';

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

expect.extend({ toBeDeepCloseTo, toMatchCloseTo });

describe('broadenPeaks', () => {
it('empty', () => {
const result = broadenPeaks([]);
Expand Down
1 change: 1 addition & 0 deletions src/post/__tests__/joinBroadPeaks.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { generateSpectrum } from 'spectrum-generator';
import { describe, expect, it } from 'vitest';

import { gsd } from '../../gsd';
import { joinBroadPeaks } from '../joinBroadPeaks';
Expand Down
4 changes: 1 addition & 3 deletions src/post/__tests__/optimizePeaks.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { toMatchCloseTo } from 'jest-matcher-deep-close-to';
import { generateSpectrum } from 'spectrum-generator';
import { describe, expect, it } from 'vitest';

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

expect.extend({ toMatchCloseTo });

describe('optimizePeaks', () => {
it('Should throw because execution time is over timeout', () => {
const peaks = [{ x: 0, y: 1, width: 0.12 }];
Expand Down
4 changes: 1 addition & 3 deletions src/post/__tests__/optimizePeaksWithLogs.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { toMatchCloseTo } from 'jest-matcher-deep-close-to';
import { generateSpectrum } from 'spectrum-generator';
import { describe, expect, it } from 'vitest';

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

expect.extend({ toMatchCloseTo });

describe('optimizePeaksWithLogs', () => {
it('Should throw because execution time is over timeout', () => {
const peaks = [{ x: 0, y: 1, width: 0.12 }];
Expand Down
4 changes: 1 addition & 3 deletions src/utils/__tests__/addMissingShape.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { toMatchCloseTo } from 'jest-matcher-deep-close-to';
import { getShape1D } from 'ml-peak-shape-generator';
import { describe, expect, it } from 'vitest';

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

expect.extend({ toMatchCloseTo });

describe('addMissingShape', () => {
it('gaussian shape', () => {
const result = addMissingShape([
Expand Down
2 changes: 2 additions & 0 deletions src/utils/__tests__/groupPeaks.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, it } from 'vitest';

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

describe('groupPeaks', () => {
Expand Down
4 changes: 1 addition & 3 deletions src/utils/__tests__/optimizeTop.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { toBeDeepCloseTo } from 'jest-matcher-deep-close-to';
import { describe, expect, it } from 'vitest';

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

expect.extend({ toBeDeepCloseTo });

describe('optimizeTop', () => {
it('no change', () => {
const peaks = [{ index: 2, x: 2, y: 5 }];
Expand Down
4 changes: 1 addition & 3 deletions src/utils/__tests__/setShape.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { toMatchCloseTo } from 'jest-matcher-deep-close-to';
import { describe, expect, it } from 'vitest';

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

expect.extend({ toMatchCloseTo });

describe('setShape', () => {
it('gaussian shape', () => {
const result = setShape([
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"strict": true,
"target": "es2020"
},
"include": ["./src/**/*", "old"]
"include": ["./src/**/*", "vitest.setup.ts"]
}
7 changes: 7 additions & 0 deletions vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
setupFiles: ['vitest.setup.ts']
}
})
4 changes: 4 additions & 0 deletions vitest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to';
import { expect } from 'vitest';

expect.extend({ toMatchCloseTo, toBeDeepCloseTo });

0 comments on commit 5f950d9

Please sign in to comment.