Skip to content

Commit 4b5178a

Browse files
mverzilliclaude
andauthored
chore: kv store test fully on vitest (#23096)
Deprecates mocha as a test runner for kv-store (we currently half part in mocha part in vitest). The seemingly off-topic change in stdlib stems from L2TipsStore tests being generated from there but consumed from kv-store. It's a bit of a strange pattern that maybe we should reconsider. --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f3911a8 commit 4b5178a

20 files changed

Lines changed: 571 additions & 860 deletions

yarn-project/kv-store/.mocharc.json

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

yarn-project/kv-store/package.json

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
"build": "yarn clean && ../scripts/tsc.sh",
1616
"build:dev": "../scripts/tsc.sh --watch",
1717
"clean": "rm -rf ./dest .tsbuildinfo",
18-
"test:node": "NODE_NO_WARNINGS=1 mocha --config ./.mocharc.json",
18+
"test:node": "vitest run --project node",
1919
"test:browser": "bash scripts/run-browser-tests.sh",
20-
"bench:browser": "VITE_BENCH=1 vitest run --config ./vitest.config.ts src/bench",
21-
"test": "yarn test:node && yarn test:browser",
20+
"bench:browser": "VITE_BENCH=1 vitest run --project browser src/bench",
21+
"test": "vitest run",
2222
"test:jest": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
2323
},
2424
"inherits": [
@@ -39,28 +39,18 @@
3939
"ordered-binary": "^1.5.3"
4040
},
4141
"devDependencies": {
42-
"@jest/globals": "^30.0.0",
43-
"@types/chai": "^5.0.1",
44-
"@types/chai-as-promised": "^8.0.1",
4542
"@types/jest": "^30.0.0",
46-
"@types/mocha": "^10.0.10",
47-
"@types/mocha-each": "^2.0.4",
4843
"@types/node": "^22.15.17",
49-
"@types/sinon": "^17.0.3",
5044
"@typescript/native-preview": "7.0.0-dev.20260113.1",
5145
"@vitest/browser-playwright": "^4.0.0",
5246
"buffer": "^6.0.3",
53-
"chai": "^5.1.2",
54-
"chai-as-promised": "^8.0.1",
5547
"jest": "^30.0.0",
56-
"mocha": "^10.8.2",
57-
"mocha-each": "^2.0.1",
5848
"playwright": "1.49.0",
59-
"sinon": "^19.0.2",
60-
"ts-node": "^10.9.1",
6149
"typescript": "^5.3.3",
6250
"util": "^0.12.5",
63-
"vitest": "^4.0.0"
51+
"vitest": "^4.0.0",
52+
"@jest/globals": "^30.0.0",
53+
"ts-node": "^10.9.1"
6454
},
6555
"files": [
6656
"dest",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"scripts": {
3-
"test": "yarn test:node && yarn test:browser",
3+
"test": "vitest run",
44
"test:browser": "bash scripts/run-browser-tests.sh"
55
}
66
}
Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
#!/usr/bin/env bash
2-
# Runs a single kv-store test file. Dispatches to vitest+chromium for
3-
# browser tests (under src/indexeddb or src/sqlite-opfs) and to mocha for
4-
# everything else. Emitted by yarn-project/kv-store/bootstrap.sh test_cmds
5-
# for CI per-file fan-out and runnable directly for local reproduction:
6-
#
7-
# yarn-project/kv-store/scripts/run_test.sh src/lmdb-v2/store.test.ts
2+
# Runs a single kv-store test file via vitest. The vitest config
3+
# (vitest.config.ts, projects array) determines whether the file runs
4+
# in node or browser environment based on its path.
85
source $(git rev-parse --show-toplevel)/ci3/source
96

107
test=${1:?"Usage: $0 <test-file relative to kv-store/>"}
118
cd ..
129

13-
case "$test" in
14-
src/indexeddb/*|src/sqlite-opfs/*)
15-
exec yarn vitest run --config ./vitest.config.ts "$test"
16-
;;
17-
*)
18-
NODE_NO_WARNINGS=1 exec yarn mocha --config ./.mocharc.json "$test"
19-
;;
20-
esac
10+
NODE_NO_WARNINGS=1 exec yarn vitest run --config ./vitest.config.ts "$test"

yarn-project/kv-store/src/indexeddb/version_management.test.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { EthAddress } from '@aztec/foundation/eth-address';
22
import { DatabaseVersion } from '@aztec/stdlib/database-version/version';
33

4-
import { expect } from 'chai';
5-
64
import { mockLogger } from '../interfaces/utils.js';
75
import { initStoreForRollupAndSchemaVersion } from '../utils.js';
86
import { AztecIndexedDBStore } from './store.js';
@@ -31,8 +29,8 @@ describe('IndexedDB Version Management', () => {
3129
const stored = await versionSingleton.getAsync();
3230

3331
const storedVersion = DatabaseVersion.fromBuffer(Buffer.from(stored!, 'utf-8'));
34-
expect(storedVersion.schemaVersion).to.equal(schemaVersion);
35-
expect(storedVersion.rollupAddress.toString()).to.equal(rollupAddress.toString());
32+
expect(storedVersion.schemaVersion).toBe(schemaVersion);
33+
expect(storedVersion.rollupAddress.toString()).toBe(rollupAddress.toString());
3634
});
3735
});
3836

@@ -46,7 +44,7 @@ describe('IndexedDB Version Management', () => {
4644
await initStoreForRollupAndSchemaVersion(store, schemaVersion, rollupAddress, mockLogger);
4745

4846
// Data should still exist
49-
expect(await testMap.getAsync('key')).to.equal('value');
47+
expect(await testMap.getAsync('key')).toBe('value');
5048
});
5149
});
5250

@@ -60,7 +58,7 @@ describe('IndexedDB Version Management', () => {
6058
const newRollupAddress = EthAddress.random();
6159
await initStoreForRollupAndSchemaVersion(store, schemaVersion, newRollupAddress, mockLogger);
6260

63-
expect(await testMap.getAsync('key')).to.be.undefined;
61+
expect(await testMap.getAsync('key')).toBeUndefined();
6462
});
6563
});
6664

@@ -73,7 +71,7 @@ describe('IndexedDB Version Management', () => {
7371

7472
await initStoreForRollupAndSchemaVersion(store, schemaVersion + 1, rollupAddress, mockLogger);
7573

76-
expect(await testMap.getAsync('key')).to.be.undefined;
74+
expect(await testMap.getAsync('key')).toBeUndefined();
7775
});
7876

7977
it('clears store when schema version decreases', async () => {
@@ -84,7 +82,7 @@ describe('IndexedDB Version Management', () => {
8482

8583
await initStoreForRollupAndSchemaVersion(store, schemaVersion - 1, rollupAddress, mockLogger);
8684

87-
expect(await testMap.getAsync('key')).to.be.undefined;
85+
expect(await testMap.getAsync('key')).toBeUndefined();
8886
});
8987
});
9088

@@ -98,7 +96,7 @@ describe('IndexedDB Version Management', () => {
9896

9997
await initStoreForRollupAndSchemaVersion(store, schemaVersion, rollupAddress, mockLogger);
10098

101-
expect(await testMap.getAsync('key')).to.be.undefined;
99+
expect(await testMap.getAsync('key')).toBeUndefined();
102100
});
103101

104102
it('clears store when version has wrong structure', async () => {
@@ -110,7 +108,7 @@ describe('IndexedDB Version Management', () => {
110108

111109
await initStoreForRollupAndSchemaVersion(store, schemaVersion, rollupAddress, mockLogger);
112110

113-
expect(await testMap.getAsync('key')).to.be.undefined;
111+
expect(await testMap.getAsync('key')).toBeUndefined();
114112
});
115113
});
116114

@@ -126,13 +124,13 @@ describe('IndexedDB Version Management', () => {
126124
// Init with new version management should clear the old data
127125
await initStoreForRollupAndSchemaVersion(store, schemaVersion, rollupAddress, mockLogger);
128126

129-
expect(await testMap.getAsync('key')).to.be.undefined;
127+
expect(await testMap.getAsync('key')).toBeUndefined();
130128

131129
const versionSingleton = store.openSingleton<string>('dbVersion');
132130
const stored = await versionSingleton.getAsync();
133131
const storedVersion = DatabaseVersion.fromBuffer(Buffer.from(stored!, 'utf-8'));
134-
expect(storedVersion.schemaVersion).to.equal(schemaVersion);
135-
expect(storedVersion.rollupAddress.toString()).to.equal(rollupAddress.toString());
132+
expect(storedVersion.schemaVersion).toBe(schemaVersion);
133+
expect(storedVersion.rollupAddress.toString()).toBe(rollupAddress.toString());
136134
});
137135

138136
it('clears store with old format even if rollup address matches', async () => {
@@ -145,7 +143,7 @@ describe('IndexedDB Version Management', () => {
145143

146144
await initStoreForRollupAndSchemaVersion(store, schemaVersion, rollupAddress, mockLogger);
147145

148-
expect(await testMap.getAsync('key')).to.be.undefined;
146+
expect(await testMap.getAsync('key')).toBeUndefined();
149147
});
150148
});
151149
});

yarn-project/kv-store/src/interfaces/array_test_suite.ts

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { toArray } from '@aztec/foundation/iterable';
22

3-
import { expect } from 'chai';
4-
53
import type { AztecArray, AztecAsyncArray } from './array.js';
64
import type { AztecAsyncKVStore, AztecKVStore } from './store.js';
75
import { isSyncStore } from './utils.js';
@@ -53,64 +51,64 @@ export function describeAztecArray(
5351
await arr.push(2);
5452
await arr.push(3);
5553

56-
expect(await length()).to.equal(3);
54+
expect(await length()).toBe(3);
5755

58-
expect(await arr.pop()).to.equal(3);
59-
expect(await arr.pop()).to.equal(2);
60-
expect(await arr.pop()).to.equal(1);
61-
expect(await arr.pop()).to.equal(undefined);
56+
expect(await arr.pop()).toBe(3);
57+
expect(await arr.pop()).toBe(2);
58+
expect(await arr.pop()).toBe(1);
59+
expect(await arr.pop()).toBe(undefined);
6260
});
6361

6462
it('should be able to get values by index', async () => {
6563
await arr.push(1);
6664
await arr.push(2);
6765
await arr.push(3);
6866

69-
expect(await at(0)).to.equal(1);
70-
expect(await at(1)).to.equal(2);
71-
expect(await at(2)).to.equal(3);
72-
expect(await at(3)).to.equal(undefined);
73-
expect(await at(-1)).to.equal(3);
74-
expect(await at(-2)).to.equal(2);
75-
expect(await at(-3)).to.equal(1);
76-
expect(await at(-4)).to.equal(undefined);
67+
expect(await at(0)).toBe(1);
68+
expect(await at(1)).toBe(2);
69+
expect(await at(2)).toBe(3);
70+
expect(await at(3)).toBe(undefined);
71+
expect(await at(-1)).toBe(3);
72+
expect(await at(-2)).toBe(2);
73+
expect(await at(-3)).toBe(1);
74+
expect(await at(-4)).toBe(undefined);
7775
});
7876

7977
it('should be able to set values by index', async () => {
8078
await arr.push(1);
8179
await arr.push(2);
8280
await arr.push(3);
8381

84-
expect(await arr.setAt(0, 4)).to.equal(true);
85-
expect(await arr.setAt(1, 5)).to.equal(true);
86-
expect(await arr.setAt(2, 6)).to.equal(true);
82+
expect(await arr.setAt(0, 4)).toBe(true);
83+
expect(await arr.setAt(1, 5)).toBe(true);
84+
expect(await arr.setAt(2, 6)).toBe(true);
8785

88-
expect(await arr.setAt(3, 7)).to.equal(false);
86+
expect(await arr.setAt(3, 7)).toBe(false);
8987

90-
expect(await at(0)).to.equal(4);
91-
expect(await at(1)).to.equal(5);
92-
expect(await at(2)).to.equal(6);
93-
expect(await at(3)).to.equal(undefined);
88+
expect(await at(0)).toBe(4);
89+
expect(await at(1)).toBe(5);
90+
expect(await at(2)).toBe(6);
91+
expect(await at(3)).toBe(undefined);
9492

95-
expect(await arr.setAt(-1, 8)).to.equal(true);
96-
expect(await arr.setAt(-2, 9)).to.equal(true);
97-
expect(await arr.setAt(-3, 10)).to.equal(true);
93+
expect(await arr.setAt(-1, 8)).toBe(true);
94+
expect(await arr.setAt(-2, 9)).toBe(true);
95+
expect(await arr.setAt(-3, 10)).toBe(true);
9896

99-
expect(await arr.setAt(-4, 11)).to.equal(false);
97+
expect(await arr.setAt(-4, 11)).toBe(false);
10098

101-
expect(await at(-1)).to.equal(8);
102-
expect(await at(-2)).to.equal(9);
103-
expect(await at(-3)).to.equal(10);
104-
expect(await at(-4)).to.equal(undefined);
99+
expect(await at(-1)).toBe(8);
100+
expect(await at(-2)).toBe(9);
101+
expect(await at(-3)).toBe(10);
102+
expect(await at(-4)).toBe(undefined);
105103
});
106104

107105
it('should be able to iterate over values', async () => {
108106
await arr.push(1);
109107
await arr.push(2);
110108
await arr.push(3);
111109

112-
expect(await values()).to.deep.equal([1, 2, 3]);
113-
expect(await entries()).to.deep.equal([
110+
expect(await values()).toEqual([1, 2, 3]);
111+
expect(await entries()).toEqual([
114112
[0, 1],
115113
[1, 2],
116114
[2, 3],
@@ -123,8 +121,8 @@ export function describeAztecArray(
123121
await arr.push(3);
124122

125123
const arr2 = store.openArray<number>('test');
126-
expect(await length(arr2)).to.equal(3);
127-
expect(await values(arr2)).to.deep.equal(await values());
124+
expect(await length(arr2)).toBe(3);
125+
expect(await values(arr2)).toEqual(await values());
128126
});
129127
});
130128
}

0 commit comments

Comments
 (0)