From 04542c7e37d3f2c96269aea047a5ac724f4339be Mon Sep 17 00:00:00 2001 From: Luc Patiny Date: Mon, 14 Oct 2024 16:49:52 +0200 Subject: [PATCH] chore: migrate from jest to vitest --- eslint.config.mjs | 1 - package.json | 14 +- src/__tests__/index.test.js | 2 + src/__tests__/peakPicking.test.js | 2 + .../__snapshots__/fromVamas.test.js.snap | 242 +++++++++++++++++- src/from/__tests__/fromVamas.test.js | 2 + src/from/__tests__/getNormalizedMeta.test.js | 2 + src/from/__tests__/mapComponents.test.js | 1 + src/from/__tests__/parseRegion.test.js | 2 + .../__tests__/appendBackground.test.js | 2 + .../background/__tests__/linear.test.js | 2 + .../background/__tests__/shirley.test.js | 2 + .../__tests__/predictPolymer.test.js | 1 + .../__tests__/predictUsingAI.test.js | 1 + .../__tests__/predictUsingHoseCodes.test.js | 1 + 15 files changed, 266 insertions(+), 11 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 61043a3..25ddf84 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -6,7 +6,6 @@ export default [ { languageOptions: { globals: { - ...globals.jest, ...globals.node, }, }, diff --git a/package.json b/package.json index b85082c..f14c97f 100644 --- a/package.json +++ b/package.json @@ -15,9 +15,9 @@ "prepack": "rollup -c", "prettier": "prettier --check src", "prettier-write": "prettier --write src", - "test": "npm run test-coverage && npm run eslint", - "test-coverage": "jest --coverage", - "test-only": "jest" + "test": "npm run test-coverage && npm run eslint && npm run prettier", + "test-coverage": "vitest run --coverage", + "test-only": "vitest run" }, "repository": { "type": "git", @@ -30,22 +30,18 @@ "url": "https://github.com/cheminfo/xps-analysis/issues" }, "homepage": "https://github.com/cheminfo/xps-analysis#readme", - "jest": { - "testEnvironment": "node" - }, "devDependencies": { "@babel/plugin-transform-modules-commonjs": "^7.25.7", - "@types/jest": "^29.5.13", "cheminfo-build": "^1.2.0", "eslint": "^9.12.0", "eslint-config-cheminfo": "^12.0.1", "globals": "^15.11.0", - "jest": "^29.7.0", "openchemlib": "^8.15.0", "papaparse": "^5.4.1", "prettier": "^3.3.3", "rollup": "^4.24.0", - "spectrum-generator": "^8.0.11" + "spectrum-generator": "^8.0.11", + "vitest": "^2.1.3" }, "dependencies": { "common-spectrum": "2.12.0", diff --git a/src/__tests__/index.test.js b/src/__tests__/index.test.js index 1b7f386..937cf29 100644 --- a/src/__tests__/index.test.js +++ b/src/__tests__/index.test.js @@ -1,6 +1,8 @@ import { readFileSync } from 'fs'; import { join } from 'path'; +import { describe, it, expect } from 'vitest'; + import { fromVamas, toJcamp } from '..'; describe('fromVamas', () => { diff --git a/src/__tests__/peakPicking.test.js b/src/__tests__/peakPicking.test.js index 266f8df..e8bda74 100644 --- a/src/__tests__/peakPicking.test.js +++ b/src/__tests__/peakPicking.test.js @@ -1,6 +1,8 @@ import { readFileSync } from 'fs'; import { join } from 'path'; +import { describe, it, expect } from 'vitest'; + import { fromVamas } from '..'; import { peakPicking } from '../peakPicking'; diff --git a/src/from/__tests__/__snapshots__/fromVamas.test.js.snap b/src/from/__tests__/__snapshots__/fromVamas.test.js.snap index 7278d3b..d252907 100644 --- a/src/from/__tests__/__snapshots__/fromVamas.test.js.snap +++ b/src/from/__tests__/__snapshots__/fromVamas.test.js.snap @@ -1,4 +1,244 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`fromVamas > Cellulose with CASA information, regions and components 1`] = ` +{ + "analyserMode": "FAT", + "analysisSource": { + "beamWidthX": { + "units": "um", + "value": 6000, + }, + "beamWidthY": { + "units": "um", + "value": 500, + }, + "characteristicEnergy": { + "units": "eV", + "value": 1486.6, + }, + "label": "Al Ka, Monochromated", + }, + "components": [ + { + "area": { + "lowerBound": 1e-20, + "upperBound": 126904.8, + "value": 4830.0138, + }, + "assignment": "C 1s 1", + "atomicMass": 12.011, + "bindingEnergy": { + "units": "eV", + "value": 286.7736, + }, + "componentID": "C 1s 1", + "fwhm": { + "lowerBound": 0.25, + "upperBound": 6.25, + "value": 1.1057933, + }, + "groupIndex": -1, + "kineticEnergy": { + "units": "eV", + "value": 1199.8264, + }, + "position": { + "lowerBound": 1199.7, + "upperBound": 1199.87, + "value": 1199.8264, + }, + "relativeSensitivityFactor": 0.278, + "shape": { + "kind": "lorentzianAsymmetric", + "options": { + "alpha": 1.4, + "beta": 1.7, + "m": 100, + }, + }, + "uncorrectedRSF": 0.278, + }, + { + "area": { + "constrain": { + "factor": 0.2048, + "linkedComponent": 0, + }, + "lowerBound": 0, + "upperBound": 2000, + "value": 989.18682, + }, + "assignment": "C 1s 2", + "atomicMass": 12.011, + "bindingEnergy": { + "units": "eV", + "value": 288.1950999999999, + }, + "componentID": "C 1s 2", + "fwhm": { + "lowerBound": 0.25, + "upperBound": 6.25, + "value": 1.1121055, + }, + "groupIndex": -1, + "kineticEnergy": { + "units": "eV", + "value": 1198.4049, + }, + "position": { + "lowerBound": 1198.34, + "upperBound": 1198.74, + "value": 1198.4049, + }, + "relativeSensitivityFactor": 0.278, + "shape": { + "kind": "lorentzianAsymmetric", + "options": { + "alpha": 1.4, + "beta": 1.6, + "m": 100, + }, + }, + "uncorrectedRSF": 0.278, + }, + { + "area": { + "lowerBound": 0, + "upperBound": 243, + "value": 56.812945, + }, + "assignment": "C 1s degrad", + "atomicMass": 12.011, + "bindingEnergy": { + "units": "eV", + "value": 288.8453999999999, + }, + "componentID": "C 1s degrad", + "fwhm": { + "lowerBound": 0.25, + "upperBound": 2, + "value": 0.82920074, + }, + "groupIndex": -1, + "kineticEnergy": { + "units": "eV", + "value": 1197.7546, + }, + "position": { + "lowerBound": 1197.3546, + "upperBound": 1197.7546, + "value": 1197.7546, + }, + "relativeSensitivityFactor": 0.278, + "shape": { + "kind": "gaussianLorentzianProduct", + "options": { + "mixingRatio": 30, + }, + }, + "uncorrectedRSF": 0.278, + }, + { + "area": { + "lowerBound": 1e-20, + "upperBound": 126904.8, + "value": 100.40835, + }, + "assignment": "C 1s Adv.C", + "atomicMass": 12.011, + "bindingEnergy": { + "units": "eV", + "value": 284.8711999999998, + }, + "componentID": "C 1s Adv.C", + "fwhm": { + "lowerBound": 0.25, + "upperBound": 6.25, + "value": 0.74742285, + }, + "groupIndex": -1, + "kineticEnergy": { + "units": "eV", + "value": 1201.7288, + }, + "position": { + "lowerBound": 1201.4, + "upperBound": 1201.8, + "value": 1201.7288, + }, + "relativeSensitivityFactor": 0.278, + "shape": { + "kind": "gaussianLorentzianProduct", + "options": { + "mixingRatio": 30, + }, + }, + "uncorrectedRSF": 0.278, + }, + ], + "energyType": { + "kind": "binding", + "units": "eV", + }, + "from": 294.16, + "region": { + "auger": { + "element": null, + "transition": null, + }, + "name": "C 1s", + "orbital": { + "angularMomentum": "s", + "element": "C", + "shell": 1, + }, + }, + "regions": [ + { + "background": { + "parameters": { + "averageWidth": 1, + "bindingEnergyEnd": { + "units": "eV", + "value": 283.34839999999986, + }, + "bindingEnergyStart": { + "units": "eV", + "value": 293.2871, + }, + "crossSection": [ + 40.442441, + -450, + 0, + 0, + ], + "endOffset": 0, + "kineticEnergyEnd": { + "units": "eV", + "value": 1203.2516, + }, + "kineticEnergyStart": { + "units": "eV", + "value": 1193.3129, + }, + "relativeSensitivityFactor": 0.278, + "startOffset": 0, + }, + "rawParameters": "1193.3129 1203.2516 0.278 2 0 0 40.442441 -450 0 0", + "type": "Shirley", + }, + "block": { + "atomicMass": 12.011, + "regionBlockID": "C 1s", + "relativeSensitivityFactor": 0.278, + }, + "regionID": "C 1s", + }, + ], + "speciesLabel": "C", + "to": 282.16, +} +`; exports[`fromVamas Cellulose with CASA information, regions and components 1`] = ` { diff --git a/src/from/__tests__/fromVamas.test.js b/src/from/__tests__/fromVamas.test.js index 3e2b33f..10c7a46 100644 --- a/src/from/__tests__/fromVamas.test.js +++ b/src/from/__tests__/fromVamas.test.js @@ -1,6 +1,8 @@ import { readFileSync } from 'fs'; import { join } from 'path'; +import { describe, it, expect } from 'vitest'; + import { fromVamas } from '../fromVamas'; describe('fromVamas', () => { diff --git a/src/from/__tests__/getNormalizedMeta.test.js b/src/from/__tests__/getNormalizedMeta.test.js index 28e5187..4f724dd 100644 --- a/src/from/__tests__/getNormalizedMeta.test.js +++ b/src/from/__tests__/getNormalizedMeta.test.js @@ -1,3 +1,5 @@ +import { test, expect } from 'vitest'; + import { getNormalizedMeta } from '../getNormalizedMeta'; import meta from './meta.json'; diff --git a/src/from/__tests__/mapComponents.test.js b/src/from/__tests__/mapComponents.test.js index 6d16044..81de2ca 100644 --- a/src/from/__tests__/mapComponents.test.js +++ b/src/from/__tests__/mapComponents.test.js @@ -1,4 +1,5 @@ import { parseCASA } from 'vamas'; +import { describe, it, expect } from 'vitest'; import { mapComponents } from '../mapComponents'; diff --git a/src/from/__tests__/parseRegion.test.js b/src/from/__tests__/parseRegion.test.js index 5c3bc59..675bc40 100644 --- a/src/from/__tests__/parseRegion.test.js +++ b/src/from/__tests__/parseRegion.test.js @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest'; + import { parseRegion } from '../parseRegion.js'; describe('XPS region parser', () => { diff --git a/src/utilities/background/__tests__/appendBackground.test.js b/src/utilities/background/__tests__/appendBackground.test.js index 1a7f836..98b27e2 100644 --- a/src/utilities/background/__tests__/appendBackground.test.js +++ b/src/utilities/background/__tests__/appendBackground.test.js @@ -1,6 +1,8 @@ import { readFileSync } from 'fs'; import { join } from 'path'; +import { test } from 'vitest'; + import { fromVamas } from '../../../from/fromVamas.js'; import { appendBackground } from '../appendBackground.js'; diff --git a/src/utilities/background/__tests__/linear.test.js b/src/utilities/background/__tests__/linear.test.js index 535268b..a6573fa 100644 --- a/src/utilities/background/__tests__/linear.test.js +++ b/src/utilities/background/__tests__/linear.test.js @@ -1,3 +1,5 @@ +import { test, expect } from 'vitest'; + import { linear } from '../linear'; test('linear', () => { diff --git a/src/utilities/background/__tests__/shirley.test.js b/src/utilities/background/__tests__/shirley.test.js index f68b1cb..5de7913 100644 --- a/src/utilities/background/__tests__/shirley.test.js +++ b/src/utilities/background/__tests__/shirley.test.js @@ -1,3 +1,5 @@ +import { test, expect } from 'vitest'; + import { shirley } from '../shirley'; test('shirley', () => { diff --git a/src/utilities/prediction/__tests__/predictPolymer.test.js b/src/utilities/prediction/__tests__/predictPolymer.test.js index 5f5a4d3..3674c50 100644 --- a/src/utilities/prediction/__tests__/predictPolymer.test.js +++ b/src/utilities/prediction/__tests__/predictPolymer.test.js @@ -1,4 +1,5 @@ import { Molecule } from 'openchemlib'; +import { test } from 'vitest'; import { predictPolymer } from '../predictPolymer'; diff --git a/src/utilities/prediction/__tests__/predictUsingAI.test.js b/src/utilities/prediction/__tests__/predictUsingAI.test.js index 2e430c5..0109060 100644 --- a/src/utilities/prediction/__tests__/predictUsingAI.test.js +++ b/src/utilities/prediction/__tests__/predictUsingAI.test.js @@ -1,4 +1,5 @@ import OCL from 'openchemlib'; +import { test, expect } from 'vitest'; import { predictUsingAI } from '../predictUsingAI.js'; diff --git a/src/utilities/prediction/__tests__/predictUsingHoseCodes.test.js b/src/utilities/prediction/__tests__/predictUsingHoseCodes.test.js index 455a742..0f2124c 100644 --- a/src/utilities/prediction/__tests__/predictUsingHoseCodes.test.js +++ b/src/utilities/prediction/__tests__/predictUsingHoseCodes.test.js @@ -1,4 +1,5 @@ import OCL from 'openchemlib'; +import { test, expect } from 'vitest'; import { predictUsingHoseCodes } from '../predictUsingHoseCodes.js';