Skip to content

Commit

Permalink
feat: jest fast transpile. no more ts-jest. (#5530)
Browse files Browse the repository at this point in the history
`ts-jest` is slow. It performs full type checking before we even hit a
line of code. This can lead to upwards of 7+ seconds of wait time in
some cases (like e2e tests).

It's not really necessary to do such type-checking when in a development
cycle, as:
1. Your IDE is likely running tsc.
2. You're likely running an `yarn tsc -b --watch` in the root of the
project, to ensure you're getting incremental builds applied to `dest`
folders for cross module imports.
3. CI will do a full build as a backstop for devs that didn't do
incrementals and forgot to sanity check the project with a `yarn build`.

This PR swaps `ts-jest` for `@swc/jest`, a rust transpiler which can
leverage the explicit `type` imports in the previous PR to do very fast
ts->js transpilation.

I think swapping out type-safety in this point of the dev cycle is worth
the improved feedback cycle. Especially given points above.

It also knocks about a second off startup time by not calling `yarn bin
jest` in the test script, as yarn startup itself is annoyingly slow.

Running foundation tests:
* before: `7.8s`
* after: `3.7s`

Running circuits.js tests:
* before: `13.3s`
* after: `5.8s`

I expect the performance improves even more as you higher up the stack
and ts-jest had more to transpile.
  • Loading branch information
charlielye authored Apr 3, 2024
1 parent a5076ca commit 1912802
Show file tree
Hide file tree
Showing 46 changed files with 545 additions and 292 deletions.
4 changes: 2 additions & 2 deletions yarn-project/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ end-to-end:
RUN yarn workspaces focus @aztec/end-to-end --production && yarn cache clean
SAVE ARTIFACT /usr/src/*

end-to-end-minimal:
end-to-end-minimal:
# end to end test runner
BUILD +aztec
FROM node:18.19.1-slim
RUN apt-get update && apt-get install jq chromium -y
RUN apt-get update && apt-get install jq chromium netcat-openbsd -y
ENV CHROME_BIN="/usr/bin/chromium"
COPY +end-to-end/. /usr/src
WORKDIR /usr/src/yarn-project/end-to-end
Expand Down
14 changes: 10 additions & 4 deletions yarn-project/accounts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,26 @@
"clean": "rm -rf ./dest .tsbuildinfo ./src/artifacts",
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests"
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests"
},
"inherits": [
"../package.common.json",
"./package.local.json"
],
"jest": {
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src"
"rootDir": "./src",
"transform": {
"^.+\\.tsx?$": [
"@swc/jest"
]
},
"extensionsToTreatAsEsm": [
".ts"
]
},
"dependencies": {
"@aztec/aztec.js": "workspace:^",
Expand All @@ -61,7 +68,6 @@
"@types/node": "^18.7.23",
"jest": "^29.5.0",
"jest-mock-extended": "^3.0.3",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.4",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
Expand Down
14 changes: 10 additions & 4 deletions yarn-project/archiver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"clean": "rm -rf ./dest .tsbuildinfo",
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests",
"start": "node ./dest",
"start:dev": "tsc-watch -p tsconfig.json --onSuccess 'yarn start'",
"test:integration": "concurrently -k -s first -c reset,dim -n test,anvil \"yarn test:integration:run\" \"anvil\"",
Expand All @@ -26,13 +26,20 @@
"../package.common.json"
],
"jest": {
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src",
"workerThreads": true
"workerThreads": true,
"transform": {
"^.+\\.tsx?$": [
"@swc/jest"
]
},
"extensionsToTreatAsEsm": [
".ts"
]
},
"dependencies": {
"@aztec/circuit-types": "workspace:^",
Expand Down Expand Up @@ -63,7 +70,6 @@
"concurrently": "^8.0.1",
"jest": "^29.5.0",
"jest-mock-extended": "^3.0.4",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
},
Expand Down
14 changes: 10 additions & 4 deletions yarn-project/aztec-faucet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,25 @@
"clean": "rm -rf ./dest .tsbuildinfo",
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests"
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests"
},
"inherits": [
"../package.common.json"
],
"jest": {
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src"
"rootDir": "./src",
"transform": {
"^.+\\.tsx?$": [
"@swc/jest"
]
},
"extensionsToTreatAsEsm": [
".ts"
]
},
"dependencies": {
"@aztec/ethereum": "workspace:^",
Expand All @@ -44,7 +51,6 @@
"@types/jest": "^29.5.0",
"@types/node": "^18.7.23",
"jest": "^29.5.0",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
},
Expand Down
14 changes: 10 additions & 4 deletions yarn-project/aztec-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,25 @@
"clean": "rm -rf ./dest .tsbuildinfo",
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests"
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests"
},
"inherits": [
"../package.common.json"
],
"jest": {
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src"
"rootDir": "./src",
"transform": {
"^.+\\.tsx?$": [
"@swc/jest"
]
},
"extensionsToTreatAsEsm": [
".ts"
]
},
"dependencies": {
"@aztec/archiver": "workspace:^",
Expand All @@ -56,7 +63,6 @@
"@types/jest": "^29.5.0",
"@types/node": "^18.7.23",
"jest": "^29.5.0",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
},
Expand Down
14 changes: 10 additions & 4 deletions yarn-project/aztec.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,26 @@
"clean": "rm -rf ./dest .tsbuildinfo ./src/account_contract/artifacts",
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests"
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests"
},
"inherits": [
"../package.common.json",
"./package.local.json"
],
"jest": {
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src"
"rootDir": "./src",
"transform": {
"^.+\\.tsx?$": [
"@swc/jest"
]
},
"extensionsToTreatAsEsm": [
".ts"
]
},
"dependencies": {
"@aztec/circuit-types": "workspace:^",
Expand All @@ -69,7 +76,6 @@
"process": "^0.11.10",
"resolve-typescript-plugin": "^2.0.1",
"stream-browserify": "^3.0.0",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.4",
"ts-node": "^10.9.1",
"tty-browserify": "^0.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type AztecAddress, FunctionData, TxContext } from '@aztec/circuits.js';
import { type FunctionAbi, FunctionType, encodeArguments } from '@aztec/foundation/abi';

import { type Wallet } from '../account/wallet.js';
import { BaseContractInteraction, SendMethodOptions } from './base_contract_interaction.js';
import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js';

export { SendMethodOptions };

Expand Down
14 changes: 10 additions & 4 deletions yarn-project/aztec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
"build:dev": "tsc -b --watch",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests",
"run:example:token": "DEBUG='aztec:*' node ./dest/examples/token.js"
},
"inherits": [
Expand Down Expand Up @@ -62,17 +62,23 @@
"@types/jest": "^29.5.0",
"@types/koa": "^2.13.6",
"jest": "^29.5.0",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
},
"jest": {
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src"
"rootDir": "./src",
"transform": {
"^.+\\.tsx?$": [
"@swc/jest"
]
},
"extensionsToTreatAsEsm": [
".ts"
]
},
"engines": {
"node": ">=18"
Expand Down
14 changes: 10 additions & 4 deletions yarn-project/circuit-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,25 @@
"clean": "rm -rf ./dest .tsbuildinfo",
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests"
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests"
},
"inherits": [
"../package.common.json"
],
"jest": {
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src"
"rootDir": "./src",
"transform": {
"^.+\\.tsx?$": [
"@swc/jest"
]
},
"extensionsToTreatAsEsm": [
".ts"
]
},
"dependencies": {
"@aztec/circuits.js": "workspace:^",
Expand All @@ -56,7 +63,6 @@
"@types/node": "^18.7.23",
"jest": "^29.5.0",
"jest-mock-extended": "^3.0.3",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
},
Expand Down
12 changes: 0 additions & 12 deletions yarn-project/circuits.js/jest.config.ts

This file was deleted.

22 changes: 20 additions & 2 deletions yarn-project/circuits.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"name": "@aztec/circuits.js",
"version": "0.1.0",
"type": "module",
"inherits": [
"../package.common.json",
"./package.local.json"
],
"exports": {
".": "./dest/index.js",
"./hash": "./dest/hash/index.js",
Expand Down Expand Up @@ -29,7 +33,7 @@
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
"remake-constants": "node --loader ts-node/esm src/scripts/constants.in.ts && prettier -w src/constants.gen.ts && cd ../../l1-contracts && ./.foundry/bin/forge fmt",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests"
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests"
},
"dependencies": {
"@aztec/bb.js": "portal:../../barretenberg/ts",
Expand All @@ -46,7 +50,6 @@
"@types/node": "^18.7.23",
"jest": "^29.5.0",
"prettier": "^2.8.4",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
},
Expand All @@ -58,5 +61,20 @@
"types": "./dest/index.d.ts",
"engines": {
"node": ">=18"
},
"jest": {
"extensionsToTreatAsEsm": [
".ts"
],
"transform": {
"^.+\\.tsx?$": [
"@swc/jest"
]
},
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src"
}
}
5 changes: 5 additions & 0 deletions yarn-project/circuits.js/package.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"scripts": {
"build": "yarn clean && yarn generate && tsc -b"
}
}
14 changes: 10 additions & 4 deletions yarn-project/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,26 @@
"clean": "rm -rf ./dest .tsbuildinfo",
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests",
"start": "node --no-warnings ./dest/bin/index.js"
},
"inherits": [
"../package.common.json"
],
"jest": {
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src"
"rootDir": "./src",
"transform": {
"^.+\\.tsx?$": [
"@swc/jest"
]
},
"extensionsToTreatAsEsm": [
".ts"
]
},
"dependencies": {
"@aztec/accounts": "workspace:^",
Expand Down Expand Up @@ -64,7 +71,6 @@
"@types/source-map-support": "^0.5.10",
"jest": "^29.5.0",
"jest-mock-extended": "^3.0.5",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
},
Expand Down
Loading

0 comments on commit 1912802

Please sign in to comment.