Skip to content

Commit 7736cb2

Browse files
authored
chore: migrate from jest to vitest (#895)
* chore: remove jest dependencies * chore: add vitest * test: refactor tests from jest to vitest * test: refactor to use assert.fail * style: consistent test file names * chore: add vitest vscode extension recommendation * test: enable skipped test
1 parent 11bcd3b commit 7736cb2

File tree

112 files changed

+744
-1862
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+744
-1862
lines changed

.vscode/extensions.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"recommendations": ["streetsidesoftware.code-spell-checker"]
2+
"recommendations": [
3+
"streetsidesoftware.code-spell-checker",
4+
"vitest.explorer"
5+
]
36
}

jest.config.ts

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

package.json

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
"start": "rollup -c --watch",
2222
"build": "rollup -c",
2323
"build:prod": "rollup -c --environment BUILD:production",
24-
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
25-
"test:path": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathPattern",
26-
"test:cov": "NODE_OPTIONS=--experimental-vm-modules jest --collect-coverage=true",
27-
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch",
24+
"test": "vitest run",
25+
"test:path": "vitest --watch --testNamePattern",
26+
"test:cov": "vitest run --coverage",
27+
"test:watch": "vitest watch",
2828
"lint": "eslint --fix --ignore-path .gitignore \"./**/*.ts*\"",
2929
"lint:check": "eslint --ignore-path .gitignore \"./**/*.ts*\"",
3030
"typecheck": "tsc --skipLibCheck --noEmit",
@@ -45,7 +45,6 @@
4545
"devDependencies": {
4646
"@commitlint/cli": "17.7.1",
4747
"@commitlint/config-conventional": "17.7.0",
48-
"@jest/globals": "29.7.0",
4948
"@rollup/plugin-node-resolve": "15.2.3",
5049
"@rollup/plugin-terser": "0.4.3",
5150
"@rollup/plugin-typescript": "11.1.6",
@@ -54,7 +53,6 @@
5453
"@semantic-release/git": "10.0.1",
5554
"@semantic-release/github": "9.2.6",
5655
"@semantic-release/npm": "11.0.2",
57-
"@types/jest": "29.5.11",
5856
"@types/node": "20.11.10",
5957
"@typescript-eslint/eslint-plugin": "6.18.1",
6058
"@typescript-eslint/parser": "6.18.1",
@@ -66,17 +64,15 @@
6664
"eslint-plugin-prettier": "4.2.1",
6765
"ethers": "6.11.0",
6866
"husky": "8.0.3",
69-
"jest": "29.7.0",
70-
"jest-mock": "29.7.0",
7167
"lint-staged": "15.2.2",
7268
"node-fetch": "3.3.2",
7369
"prettier": "2.8.7",
7470
"rollup": "4.9.6",
7571
"rollup-plugin-filesize": "10.0.0",
7672
"semantic-release": "21.0.1",
77-
"ts-jest": "29.2.5",
7873
"ts-node": "10.9.2",
79-
"typescript": "5.3.3"
74+
"typescript": "5.3.3",
75+
"vitest": "^2.1.4"
8076
},
8177
"packageManager": "yarn@1.22.19",
8278
"engines": {

src/crypto/bls.spec.ts renamed to src/crypto/bls.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { stringToBytes } from '@scure/base';
2+
import { describe, it, expect } from 'vitest';
3+
24
import { hexToBuffer } from '../utils/buffer';
35
import * as bls from './bls';
46

src/crypto/secp256k1.spec.ts renamed to src/crypto/secp256k1.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { sha256 } from '@noble/hashes/sha256';
2+
import { describe, it, expect } from 'vitest';
3+
24
import { base58check } from '../utils/base58';
35
import { bufferToHex, hexToBuffer } from '../utils/buffer';
46
import * as secp256k1 from './secp256k1';

src/fixtures/utils/expectTx.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { expect } from 'vitest';
2+
13
export const expectTxs = (result: any, expected: any) => {
24
expect(JSON.stringify(result, null, 2)).toEqual(
35
JSON.stringify(expected, null, 2),

src/fixtures/utils/makeList.spec.ts renamed to src/fixtures/utils/makeList.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { concatBytes } from '../../utils/buffer';
2+
import { describe, it, expect } from 'vitest';
3+
24
import { address, addressBytes } from '../common';
35
import { bytesForInt } from './bytesFor';
46
import { makeList, makeListBytes } from './makeList';

src/fixtures/utils/serializable.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import type { Codec } from '../../serializable/codec';
2+
import { describe, it, expect } from 'vitest';
3+
24
import type {
35
Serializable,
46
SerializableStatic,

src/serializable/avax/signedTx.spec.ts renamed to src/serializable/avax/signedTx.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { signedTx, signedTxBytes } from '../../fixtures/avax';
2+
import { describe, it, expect } from 'vitest';
3+
24
import { getAVMManager } from '../avm/codec';
35
import { SignedTx } from './signedTx';
46

src/serializable/avax/transferableInput.spec.ts renamed to src/serializable/avax/transferableInput.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { TransferableInput } from '.';
2+
import { describe, it, expect } from 'vitest';
3+
24
import {
35
transferableInput,
46
transferableInputBytes,

src/serializable/avax/utxo.spec.ts renamed to src/serializable/avax/utxo.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { hexToBuffer } from '../../utils/buffer';
2+
import { describe, it } from 'vitest';
3+
24
import { getPVMManager } from '../pvm/codec';
35
import { Utxo } from './utxo';
46

src/serializable/avax/utxoId.spec.ts renamed to src/serializable/avax/utxoId.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { UTXOID } from './utxoId';
2+
import { describe, it, expect } from 'vitest';
3+
24
import { utxoId, utxoIdBytes } from '../../fixtures/avax';
35
import { testSerialization } from '../../fixtures/utils/serializable';
46
import { Id } from '../fxs/common';

src/serializable/avm/typeGuards.spec.ts renamed to src/serializable/avm/typeGuards.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
isOperationTx,
66
isCreateAssetTx,
77
} from './typeGuards';
8+
import { describe, it, expect } from 'vitest';
9+
810
import { TypeSymbols } from '../constants';
911
import type { Serializable } from '../common/types';
1012
import { onlyChecksOneGuard } from '../../fixtures/utils/typeguards';

src/serializable/codec/codec.spec.ts renamed to src/serializable/codec/codec.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Codec } from '.';
2+
import { describe, beforeEach, it, expect } from 'vitest';
3+
24
import { id, idBytes } from '../../fixtures/common';
35
import {
46
mintOutput,

src/serializable/codec/manager.spec.ts renamed to src/serializable/codec/manager.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
12
import { Codec, Manager } from '.';
23
import { createAssetTx, createAssetTxBytes } from '../../fixtures/avax';
34
import { bytesForInt } from '../../fixtures/utils/bytesFor';
45
import { concatBytes } from '../../utils/buffer';
56
import { CreateAssetTx } from '../avm/createAssetTx';
67
import { Bytes, Short, Stringpr } from '../primitives';
7-
import { jest } from '@jest/globals';
8-
import type { Mock } from 'jest-mock';
98

109
describe('Manager', () => {
1110
it('registers multiple codecs', () => {
@@ -37,14 +36,14 @@ describe('using the codecs', () => {
3736
});
3837

3938
afterEach(() => {
40-
jest.clearAllMocks();
39+
vi.clearAllMocks();
4140
});
4241

4342
it('chooses the right codec', () => {
44-
CreateAssetTx.fromBytes = jest.fn(() => [
43+
CreateAssetTx.fromBytes = vi.fn<() => [CreateAssetTx, Uint8Array]>(() => [
4544
createAssetTx(),
4645
new Uint8Array(),
47-
]) as Mock<() => [CreateAssetTx, Uint8Array]>;
46+
]);
4847

4948
const input = concatBytes(new Short(1).toBytes(), createAssetTxBytes());
5049

@@ -58,7 +57,7 @@ describe('using the codecs', () => {
5857

5958
it('packs with correct prefix', () => {
6059
const tx = createAssetTx();
61-
codec1.PackPrefix = jest.fn(() =>
60+
codec1.PackPrefix = vi.fn(() =>
6261
concatBytes(bytesForInt(2), createAssetTxBytes()),
6362
);
6463
const bytes = m.packCodec(tx, 1);

src/serializable/evm/typeGuards.spec.ts renamed to src/serializable/evm/typeGuards.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
isImportExportTx,
55
isEvmTx,
66
} from './typeGuards';
7+
import { describe, it, expect } from 'vitest';
8+
79
import { TypeSymbols } from '../constants';
810
import type { Transaction } from '../../vms/common';
911
import { onlyChecksOneGuard } from '../../fixtures/utils/typeguards';

src/serializable/fxs/common/id.spec.ts renamed to src/serializable/fxs/common/id.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { id, idBytes } from '../../../fixtures/common';
2+
import { describe, it, expect } from 'vitest';
3+
24
import { testSerialization } from '../../../fixtures/utils/serializable';
35
import { Id } from './id';
46

src/serializable/pvm/proofOfPossession.test.ts

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

34
const publicKey = new Uint8Array([
45
0x85, 0x02, 0x5b, 0xca, 0x6a, 0x30, 0x2d, 0xc6, 0x13, 0x38, 0xff, 0x49, 0xc8,

src/serializable/pvm/typeGuards.spec.ts renamed to src/serializable/pvm/typeGuards.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { TypeSymbols } from '../constants';
2+
import { describe, test, expect } from 'vitest';
3+
24
import { onlyChecksOneGuard } from '../../fixtures/utils/typeguards';
35
import {
46
isImportTx,

src/signer/addTxSignatures.spec.ts renamed to src/signer/addTxSignatures.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { jest } from '@jest/globals';
2-
1+
import { beforeEach, describe, expect, it, vi } from 'vitest';
32
import { UnsignedTx } from '../vms';
43
import { BaseTx as AvaxBaseTx, TransferableInput } from '../serializable/avax';
54
import { bigIntPr, bytes, int } from '../fixtures/primitives';
@@ -22,12 +21,12 @@ import { secp256k1 } from '../crypto';
2221

2322
describe('addTxSignatures', () => {
2423
beforeEach(() => {
25-
jest.clearAllMocks();
24+
vi.clearAllMocks();
2625
});
2726

2827
it('adds the signatures correctly', async () => {
29-
const hasPubkeySpy = jest.spyOn(UnsignedTx.prototype, 'hasPubkey');
30-
const addSignatureSpy = jest.spyOn(UnsignedTx.prototype, 'addSignature');
28+
const hasPubkeySpy = vi.spyOn(UnsignedTx.prototype, 'hasPubkey');
29+
const addSignatureSpy = vi.spyOn(UnsignedTx.prototype, 'addSignature');
3130
const unknownPrivateKey = hexToBuffer(
3231
'1d4ff8f6582d995354f5c03a28a043d22aa1bb6aa15879a632134aaf1f225cf4',
3332
);

src/utils/address.spec.ts renamed to src/utils/address.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { base58check } from './base58';
2+
import { describe, it, expect } from 'vitest';
3+
24
import { secp256k1 } from '../crypto';
35
import * as address from './address';
46

src/utils/addressMap.spec.ts renamed to src/utils/addressMap.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { jest } from '@jest/globals';
1+
import { beforeEach, describe, expect, it, vi } from 'vitest';
22
import { address } from '../fixtures/common';
33
import { Address } from '../serializable/fxs/common';
44
import { AddressMap, AddressMaps, matchOwners } from './addressMap';
@@ -14,7 +14,7 @@ describe('AddressMap', () => {
1414
let testMap: AddressMap;
1515

1616
beforeEach(() => {
17-
jest.resetAllMocks();
17+
vi.resetAllMocks();
1818
testMap = new AddressMap();
1919
});
2020

@@ -40,7 +40,7 @@ describe('AddressMap', () => {
4040

4141
describe('forEachHex', () => {
4242
it('iterates over the storage correctly', () => {
43-
const callbackMock = jest.fn();
43+
const callbackMock = vi.fn();
4444
testMap.set(testAddress1, 3);
4545
testMap.set(testAddress2, 1);
4646

@@ -62,7 +62,7 @@ describe('AddressMap', () => {
6262
});
6363

6464
it('reorders and iterates over the storage correctly', () => {
65-
const callbackMock = jest.fn();
65+
const callbackMock = vi.fn();
6666
testMap.set(testAddress1, 3);
6767
testMap.set(testAddress2, 1);
6868

@@ -111,12 +111,12 @@ describe('AddressMaps', () => {
111111
testAddressMaps.push(testMap2);
112112

113113
beforeEach(() => {
114-
jest.resetAllMocks();
114+
vi.resetAllMocks();
115115
});
116116

117117
describe('forEach', () => {
118118
it('iterates over the indices correctly', () => {
119-
const callbackMock = jest.fn();
119+
const callbackMock = vi.fn();
120120
testAddressMaps.forEach(callbackMock);
121121

122122
expect(callbackMock).toBeCalledTimes(3);
@@ -141,7 +141,7 @@ describe('AddressMaps', () => {
141141
});
142142

143143
it('iterates over the ordered indices correctly', () => {
144-
const callbackMock = jest.fn();
144+
const callbackMock = vi.fn();
145145
testAddressMaps.forEach(callbackMock, true);
146146

147147
expect(callbackMock).toBeCalledTimes(3);

src/utils/base58.spec.ts renamed to src/utils/base58.test.ts

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

34
describe('base58', () => {
45
it('encodes and decodes correctly', async () => {

src/utils/buffer.spec.ts renamed to src/utils/buffer.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { bufferToBigInt, bufferToNumber, padLeft } from './buffer';
2+
import { describe, it, expect } from 'vitest';
23

34
describe('bufferToBigInt', () => {
45
it('converts Uint8Arrays correctly', async () => {

src/utils/bytesCompare.spec.ts renamed to src/utils/bytesCompare.test.ts

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

34
describe('bytesCompare', () => {
45
it('compares bytes', () => {

src/utils/consolidate.spec.ts renamed to src/utils/consolidate.test.ts

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

34
describe('consolidate', () => {
45
it('combines elements', () => {

src/utils/getBurnedAmountByTx.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import type { AvaxTx } from '../serializable/avax';
2+
import { describe, it, expect } from 'vitest';
3+
24
import { UTXOID } from '../serializable/avax';
35
import { TransferableOutput } from '../serializable/avax';
46
import { newExportTxFromBaseFee, newImportTxFromBaseFee } from '../vms/evm';

src/utils/getTransferableInputsByTx.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {
33
importTx as avmImportTx,
44
transferableInputs,
55
} from '../fixtures/avax';
6+
import { describe, it, expect } from 'vitest';
7+
68
import { importTx as pvmImportTx } from '../fixtures/pvm';
79
import {
810
importTx as evmImportTx,

src/utils/getTransferableOutputsByTx.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {
22
exportTx as evmExportTx,
33
importTx as evmImportTx,
44
} from '../fixtures/evm';
5+
import { describe, it, expect } from 'vitest';
6+
57
import { getTransferableOutputsByTx } from './getTransferableOutputsByTx';
68
import {
79
avmBaseTx,

src/utils/serializeList.spec.ts renamed to src/utils/serializeList.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { TransferableInput } from '../serializable/avax';
2+
import { describe, it, expect } from 'vitest';
3+
24
import { transferableInputs, transferableInputsBytes } from '../fixtures/avax';
35
import { testCodec } from '../fixtures/codec';
46
import { address, addressesBytes } from '../fixtures/common';

0 commit comments

Comments
 (0)