Skip to content

Commit f8d76a4

Browse files
committed
Migrate to Vitest
1 parent ce817c8 commit f8d76a4

24 files changed

+1214
-2131
lines changed

eslint.config.mjs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import base, { createConfig } from '@metamask/eslint-config';
2-
import jest from '@metamask/eslint-config-jest';
2+
import vitest from '@metamask/eslint-config-vitest';
33
import nodejs from '@metamask/eslint-config-nodejs';
44
import typescript from '@metamask/eslint-config-typescript';
55

@@ -92,11 +92,7 @@ const config = createConfig([
9292

9393
{
9494
files: ['**/*.test.ts', '**/*.test.js'],
95-
extends: [jest, nodejs],
96-
97-
rules: {
98-
'jest/no-conditional-in-test': 'off',
99-
},
95+
extends: [vitest, nodejs],
10096
},
10197
]);
10298

jest.config.js

Lines changed: 0 additions & 208 deletions
This file was deleted.

package.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
"lint:fix": "yarn lint:eslint --fix && yarn lint:constraints --fix && yarn lint:misc --write && yarn lint:dependencies && yarn lint:changelog",
4444
"lint:misc": "prettier '**/*.json' '**/*.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
4545
"prepack": "./scripts/prepack.sh",
46-
"test": "jest && jest-it-up && attw --pack",
47-
"test:watch": "jest --watch"
46+
"test": "vitest && attw --pack",
47+
"test:watch": "vitest --watch"
4848
},
4949
"dependencies": {
5050
"@metamask/scure-bip39": "^2.1.1",
@@ -59,12 +59,13 @@
5959
"@lavamoat/preinstall-always-fail": "^2.0.0",
6060
"@metamask/auto-changelog": "^4.0.0",
6161
"@metamask/eslint-config": "^14.0.0",
62-
"@metamask/eslint-config-jest": "^14.0.0",
6362
"@metamask/eslint-config-nodejs": "^14.0.0",
6463
"@metamask/eslint-config-typescript": "^14.0.0",
64+
"@metamask/eslint-config-vitest": "^1.0.0",
6565
"@ts-bridge/cli": "^0.6.0",
66-
"@types/jest": "^28.1.6",
6766
"@types/node": "^18.18",
67+
"@vitest/coverage-istanbul": "3.0.8",
68+
"@vitest/eslint-plugin": "^1.1.4",
6869
"@yarnpkg/types": "^4.0.0-rc.52",
6970
"depcheck": "^1.4.3",
7071
"eslint": "^9.11.0",
@@ -77,15 +78,15 @@
7778
"eslint-plugin-n": "^17.10.3",
7879
"eslint-plugin-prettier": "^5.2.1",
7980
"eslint-plugin-promise": "^7.1.0",
80-
"jest": "^28.1.3",
81-
"jest-it-up": "^2.0.2",
8281
"prettier": "^3.3.3",
8382
"prettier-plugin-packagejson": "^2.3.0",
8483
"ts-jest": "^28.0.7",
8584
"ts-node": "^10.9.1",
8685
"typedoc": "^0.26.11",
8786
"typescript": "~5.4.5",
88-
"typescript-eslint": "^8.6.0"
87+
"typescript-eslint": "^8.6.0",
88+
"vite": "^6.2.0",
89+
"vitest": "^3.0.7"
8990
},
9091
"packageManager": "yarn@4.1.1",
9192
"engines": {
@@ -97,7 +98,8 @@
9798
},
9899
"lavamoat": {
99100
"allowScripts": {
100-
"@lavamoat/preinstall-always-fail": false
101+
"@lavamoat/preinstall-always-fail": false,
102+
"vite>esbuild": true
101103
}
102104
}
103105
}

src/BIP44CoinTypeNode.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { bytesToHex } from '@metamask/utils';
2+
import { describe, expect, it, vi } from 'vitest';
23

34
import {
45
BIP_44_COIN_TYPE_DEPTH,
@@ -25,8 +26,8 @@ const defaultBip39BytesToken = mnemonicPhraseToBytes(fixtures.local.mnemonic);
2526
* @returns The mock cryptographic functions.
2627
*/
2728
function getMockFunctions(): CryptographicFunctions {
28-
const mockHmacSha512 = jest.fn().mockImplementation(hmacSha512);
29-
const mockPbkdf2Sha512 = jest.fn().mockImplementation(pbkdf2Sha512);
29+
const mockHmacSha512 = vi.fn().mockImplementation(hmacSha512);
30+
const mockPbkdf2Sha512 = vi.fn().mockImplementation(pbkdf2Sha512);
3031

3132
return {
3233
hmacSha512: mockHmacSha512,

src/BIP44Node.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { bytesToHex } from '@metamask/utils';
2+
import { describe, expect, it, vi } from 'vitest';
23

34
import { BIP44Node, BIP44PurposeNodeToken, secp256k1 } from '.';
45
import type { CryptographicFunctions } from './cryptography';
@@ -20,8 +21,8 @@ const defaultBip39BytesToken = mnemonicPhraseToBytes(fixtures.local.mnemonic);
2021
* @returns The mock cryptographic functions.
2122
*/
2223
function getMockFunctions(): CryptographicFunctions {
23-
const mockHmacSha512 = jest.fn().mockImplementation(hmacSha512);
24-
const mockPbkdf2Sha512 = jest.fn().mockImplementation(pbkdf2Sha512);
24+
const mockHmacSha512 = vi.fn().mockImplementation(hmacSha512);
25+
const mockPbkdf2Sha512 = vi.fn().mockImplementation(pbkdf2Sha512);
2526

2627
return {
2728
hmacSha512: mockHmacSha512,

src/SLIP10Node.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { bytesToHex, hexToBytes } from '@metamask/utils';
2+
import { describe, expect, it, vi } from 'vitest';
23

34
import { BIP44PurposeNodeToken } from './constants';
45
import type { CryptographicFunctions } from './cryptography';
@@ -22,8 +23,8 @@ const defaultBip39BytesToken = mnemonicPhraseToBytes(fixtures.local.mnemonic);
2223
* @returns The mock cryptographic functions.
2324
*/
2425
function getMockFunctions(): CryptographicFunctions {
25-
const mockHmacSha512 = jest.fn().mockImplementation(hmacSha512);
26-
const mockPbkdf2Sha512 = jest.fn().mockImplementation(pbkdf2Sha512);
26+
const mockHmacSha512 = vi.fn().mockImplementation(hmacSha512);
27+
const mockPbkdf2Sha512 = vi.fn().mockImplementation(pbkdf2Sha512);
2728

2829
return {
2930
hmacSha512: mockHmacSha512,

src/cryptography.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { bytesToHex } from '@metamask/utils';
22
// eslint-disable-next-line n/no-unsupported-features/node-builtins
33
import { webcrypto } from 'crypto';
4+
import { describe, expect, it, vi } from 'vitest';
45

56
import {
67
hmacSha512,
@@ -21,7 +22,7 @@ describe('hmacSha512', () => {
2122
const data = new Uint8Array(32);
2223

2324
const hash = new Uint8Array(64).fill(1);
24-
const customHmacSha512 = jest.fn().mockResolvedValue(hash);
25+
const customHmacSha512 = vi.fn().mockResolvedValue(hash);
2526

2627
const result = await hmacSha512(key, data, {
2728
hmacSha512: customHmacSha512,
@@ -42,7 +43,7 @@ describe('hmacSha512', () => {
4243
});
4344

4445
it('returns the HMAC-SHA-512 when using the fallback', async () => {
45-
jest.spyOn(utils, 'isWebCryptoSupported').mockReturnValueOnce(false);
46+
vi.spyOn(utils, 'isWebCryptoSupported').mockReturnValueOnce(false);
4647

4748
const key = new Uint8Array(32);
4849
const data = new Uint8Array(32);
@@ -73,7 +74,7 @@ describe('pbkdf2Sha512', () => {
7374
const keyLength = 64;
7475

7576
const hash = new Uint8Array(64).fill(1);
76-
const customPbkdf2Sha512 = jest.fn().mockResolvedValue(hash);
77+
const customPbkdf2Sha512 = vi.fn().mockResolvedValue(hash);
7778

7879
const result = await pbkdf2Sha512(password, salt, iterations, keyLength, {
7980
pbkdf2Sha512: customPbkdf2Sha512,
@@ -101,7 +102,7 @@ describe('pbkdf2Sha512', () => {
101102
});
102103

103104
it('returns the PBKDF2-SHA-512 when using the fallback', async () => {
104-
jest.spyOn(utils, 'isWebCryptoSupported').mockReturnValueOnce(false);
105+
vi.spyOn(utils, 'isWebCryptoSupported').mockReturnValueOnce(false);
105106

106107
const password = new Uint8Array(32);
107108
const salt = new Uint8Array(32);

src/curves/ed25519.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { hexToBytes, bytesToHex } from '@metamask/utils';
2+
import { describe, expect, it } from 'vitest';
23

34
import {
45
compressPublicKey,

src/curves/ed25519Bip32.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { bytesToHex, hexToBytes } from '@metamask/utils';
2+
import { describe, expect, it } from 'vitest';
23

34
import { ed25519Bip32 } from '.';
45
import {

src/curves/secp256k1.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { bytesToHex, hexToBytes } from '@metamask/utils';
2+
import { describe, expect, it } from 'vitest';
23

34
import { curve, getPublicKey, isValidPrivateKey, publicAdd } from './secp256k1';
45
import fixtures from '../../test/fixtures';

0 commit comments

Comments
 (0)