Skip to content

Commit c1f010b

Browse files
authored
Replace Jest with the native Node test runner and update project tsconfig (#728)
1 parent 6088f99 commit c1f010b

File tree

11 files changed

+51
-73
lines changed

11 files changed

+51
-73
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1717

1818
## Unreleased
1919

20+
## [0.22.7](https://github.com/o1-labs/zkapp-cli/compare/v0.22.6...v0.22.7) - 2025-04-13
21+
22+
### Changed
23+
24+
- Replaces Jest with the native Node test runner in default project and examples. The template tsconfig was updated to support all features in o1js and to be compatible with projects like mina attestatons. [#728](https://github.com/o1-labs/zkapp-cli/pull/728)
25+
26+
## [0.22.6](https://github.com/o1-labs/zkapp-cli/compare/v0.22.5...v0.22.6) - 2025-04-09
27+
2028
### Added
2129

2230
- Adds a new ZkProgram default example that is included with CLI generated projects, coupled with a new example template UI that demonstrates an end to end flow of generating proofs with a ZkProgram, and settling the state on Mina. [#725](https://github.com/o1-labs/zkapp-cli/pull/725)

examples/sudoku/ts/src/sudoku.test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { Sudoku, SudokuZkApp } from './sudoku';
2-
import { cloneSudoku, generateSudoku, solveSudoku } from './sudoku-lib';
1+
import { Sudoku, SudokuZkApp } from './sudoku.js';
2+
import { cloneSudoku, generateSudoku, solveSudoku } from './sudoku-lib.js';
33
import { PrivateKey, PublicKey, Mina, AccountUpdate } from 'o1js';
4+
import { describe, it, beforeEach } from 'node:test';
5+
import assert from 'node:assert';
46

57
describe('sudoku', () => {
68
let zkApp: SudokuZkApp,
@@ -25,7 +27,7 @@ describe('sudoku', () => {
2527
await deploy(zkApp, zkAppPrivateKey, sudoku, sender, senderKey);
2628

2729
let isSolved = zkApp.isSolved.get().toBoolean();
28-
expect(isSolved).toBe(false);
30+
assert.strictEqual(isSolved, false);
2931

3032
const solution = solveSudoku(sudoku);
3133
if (solution === undefined) throw Error('cannot happen');
@@ -37,7 +39,7 @@ describe('sudoku', () => {
3739
await tx.sign([senderKey]).send();
3840

3941
isSolved = zkApp.isSolved.get().toBoolean();
40-
expect(isSolved).toBe(true);
42+
assert.strictEqual(isSolved, true);
4143
});
4244

4345
it('rejects an incorrect solution', async () => {
@@ -49,7 +51,7 @@ describe('sudoku', () => {
4951
const noSolution = cloneSudoku(solution);
5052
noSolution[0][0] = (noSolution[0][0] % 9) + 1;
5153

52-
await expect(async () => {
54+
await assert.rejects(async () => {
5355
const tx = await Mina.transaction(sender, async () => {
5456
const zkApp = new SudokuZkApp(zkAppAddress);
5557
await zkApp.submitSolution(
@@ -59,10 +61,10 @@ describe('sudoku', () => {
5961
});
6062
await tx.prove();
6163
await tx.sign([senderKey]).send();
62-
}).rejects.toThrow(/array contains the numbers 1...9/);
64+
}, /array contains the numbers 1...9/);
6365

6466
const isSolved = zkApp.isSolved.get().toBoolean();
65-
expect(isSolved).toBe(false);
67+
assert.strictEqual(isSolved, false);
6668
});
6769
});
6870

examples/tictactoe/ts/src/tictactoe.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TicTacToe } from './tictactoe';
1+
import { TicTacToe } from './tictactoe.js';
22
import {
33
Field,
44
Bool,
@@ -8,6 +8,8 @@ import {
88
AccountUpdate,
99
Signature,
1010
} from 'o1js';
11+
import { describe, it, beforeEach } from 'node:test';
12+
import assert from 'node:assert';
1113

1214
describe('tictactoe', () => {
1315
let player1: Mina.TestPublicKey,
@@ -37,7 +39,7 @@ describe('tictactoe', () => {
3739
await txn.prove();
3840
await txn.sign([zkAppPrivateKey, player1Key]).send();
3941
const board = zkApp.board.get();
40-
expect(board).toEqual(Field(0));
42+
assert.deepStrictEqual(board, Field(0));
4143
});
4244

4345
it('deploys tictactoe & accepts a correct move', async () => {
@@ -63,6 +65,6 @@ describe('tictactoe', () => {
6365

6466
// check next player
6567
const isNextPlayer2 = zkApp.nextIsPlayer2.get();
66-
expect(isNextPlayer2).toEqual(Bool(true));
68+
assert.deepStrictEqual(isNextPlayer2, Bool(true));
6769
});
6870
});

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zkapp-cli",
3-
"version": "0.22.6",
3+
"version": "0.22.7",
44
"description": "CLI to create zkApps (zero-knowledge apps) for Mina Protocol",
55
"homepage": "https://github.com/o1-labs/zkapp-cli/",
66
"repository": {

src/lib/project.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ function scaffoldSvelte() {
208208
const customTsConfig = `{
209209
"extends": "./.svelte-kit/tsconfig.json",
210210
"compilerOptions": {
211-
"target": "es2020",
211+
"target": "es2021",
212212
"module": "es2022",
213213
"lib": ["dom", "esnext"],
214214
"strict": true,
@@ -224,7 +224,9 @@ function scaffoldSvelte() {
224224
"sourceMap": true,
225225
"noFallthroughCasesInSwitch": true,
226226
"allowSyntheticDefaultImports": true,
227-
"isolatedModules": true
227+
"isolatedModules": true,
228+
"useDefineForClassFields": false,
229+
"importHelpers": true,
228230
},
229231
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
230232
//
@@ -443,7 +445,7 @@ const __dirname = path.dirname(__filename);
443445

444446
const tsconfig = `{
445447
"compilerOptions": {
446-
"target": "es2020",
448+
"target": "es2021",
447449
"module": "esnext",
448450
"lib": ["dom", "dom.iterable", "esnext"],
449451
"strict": true,
@@ -464,6 +466,8 @@ const __dirname = path.dirname(__filename);
464466
"incremental": true,
465467
"resolveJsonModule": true,
466468
"jsx": "preserve",
469+
"useDefineForClassFields": false,
470+
"importHelpers": true,
467471
"paths": {
468472
"@/*": ["./src/*"]
469473
},

templates/project-ts/jest-resolver.cjs

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

templates/project-ts/jest.config.js

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

templates/project-ts/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,17 @@
1818
"buildw": "tsc --watch",
1919
"coverage": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
2020
"format": "prettier --write --ignore-unknown **/*",
21-
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
22-
"testw": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watch",
21+
"test": "npm run build && find build/src -name '*.test.js' -exec node --test {} \\;",
22+
"testw": "npm run build && find build/src -name '*.test.js' -exec node --test --watch {} \\;",
2323
"lint": "npx eslint src/* --fix"
2424
},
2525
"devDependencies": {
2626
"@babel/preset-env": "^7.16.4",
2727
"@babel/preset-typescript": "^7.16.0",
28-
"@types/jest": "^29.5.12",
2928
"@typescript-eslint/eslint-plugin": "^5.5.0",
3029
"@typescript-eslint/parser": "^5.5.0",
3130
"eslint": "^8.7.0",
3231
"eslint-plugin-o1js": "^0.4.0",
33-
"jest": "^29.7.0",
3432
"prettier": "^2.3.2",
3533
"ts-jest": "^29.2.4",
3634
"typescript": "^5.4.5"

templates/project-ts/src/Add.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { AccountUpdate, Field, Mina, PrivateKey, PublicKey } from 'o1js';
2-
import { Add } from './Add';
3-
import { AddZkProgram } from './AddZkProgram';
2+
import { Add } from './Add.js';
3+
import { AddZkProgram } from './AddZkProgram.js';
4+
import { describe, it, before, beforeEach } from 'node:test';
5+
import assert from 'node:assert';
46

57
/*
68
* This file specifies how to test the `Add` example smart contract. It is safe to delete this file and replace
@@ -20,7 +22,7 @@ describe('Add', () => {
2022
zkAppPrivateKey: PrivateKey,
2123
zkApp: Add;
2224

23-
beforeAll(async () => {
25+
before(async () => {
2426
await AddZkProgram.compile({ proofsEnabled });
2527
if (proofsEnabled) {
2628
await Add.compile();
@@ -54,7 +56,7 @@ describe('Add', () => {
5456

5557
const { proof } = await AddZkProgram.init(Field(1));
5658

57-
expect(proof.publicOutput).toEqual(Field(1));
59+
assert.deepStrictEqual(proof.publicOutput, Field(1));
5860
});
5961

6062
it('correctly settles `AddZKprogram` state on the `Add` smart contract', async () => {
@@ -72,6 +74,6 @@ describe('Add', () => {
7274
await txn.sign([senderKey]).send();
7375

7476
const updatedNum = zkApp.num.get();
75-
expect(updatedNum).toEqual(Field(1));
77+
assert.deepStrictEqual(updatedNum, Field(1));
7678
});
7779
});

templates/project-ts/tsconfig.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
3-
"target": "es2020",
4-
"module": "es2022",
3+
"target": "es2021", // goal: ship *the most modern syntax* that is supported by *all* browsers that support our Wasm
4+
"module": "nodenext", // allow top-level await
55
"lib": ["dom", "esnext"],
66
"outDir": "./build",
77
"rootDir": ".",
@@ -10,15 +10,17 @@
1010
"skipLibCheck": true,
1111
"forceConsistentCasingInFileNames": true,
1212
"esModuleInterop": true,
13-
"moduleResolution": "node",
14-
"experimentalDecorators": true,
15-
"emitDecoratorMetadata": true,
16-
"allowJs": true,
13+
"moduleResolution": "nodenext", // comply with node + "type": "module"
14+
"experimentalDecorators": true, // needed for decorators used in o1js
15+
"emitDecoratorMetadata": true, // needed for decorators used in o1js
16+
"allowJs": true, // to use JSDoc in some places where TS would be too cumbersome
1717
"declaration": true,
1818
"sourceMap": true,
1919
"noFallthroughCasesInSwitch": true,
2020
"allowSyntheticDefaultImports": true,
21-
"useDefineForClassFields": false,
21+
"useDefineForClassFields": false, // ensure correct behaviour of class fields with decorators
22+
"importHelpers": true, // bundle optimization to reduce size
23+
"baseUrl": "." // base directory for module resolution
2224
},
23-
"include": ["./src"],
25+
"include": ["./src"]
2426
}

0 commit comments

Comments
 (0)