In this article, we analyze Istanbul usage in tRPC source code. I found this comment — istanbul ignore if. This hints that tRPC uses Istanbul.js, a tool that makes JavaScript test coverage simple.
This one took me a while to figure out that tRPC repository uses @vitest/coverage-istanbul, I was initially looking to see if there’s any scripts related to test defined in packages/clients but there were none.
After searching for istanbul across the codebase, that is when I saw Istanbul word in vitest.config.ts test scripts are defined in the root level’s package.json.
"test": "turbo codegen-tests && conc -c \"green,blue\" \"vitest run\" \"pnpm -F tests test-run:tsc\"",
"test-ci": "turbo codegen-tests && conc \"CI=true vitest run - coverage\" \"pnpm -F tests test-run:tsc\"",
"test-watch": "vitest",
Below is coverage object picked from vitest.config.ts:
coverage: {
provider: 'istanbul',
include: ['**/src/**'],
exclude: [
'**/www/**',
'**/examples/**',
// skip codecov for experimental features
// FIXME: delete me once they're stable
'**/next/src/app-dir/**',
'**/server/src/adapters/next-app-dir/**',
],
},
Vitest supports another provider as well, it is ‘v8’. By default, provider is set to v8.
Let’s what happens when test
script is run:
test script:
"test": "turbo codegen-tests && conc -c \"green,blue\" \"vitest run\" \"pnpm -F tests test-run:tsc\"",
tRPC uses Turbo. Turbo is an incremental bundler and build system optimized for JavaScript and TypeScript, written in Rust.
turbo codegen-tests:
codegen-tests is a command defined in turbo.json and when you run this, it executes codegen-tests scripts defined in the packages. This is a monorepo setup.
codegen-scripts in packages:
- client/package.json
- next/package.json
- react-query/package.json
- server/package.json
conc -c
conc is a short alias for concurrently. Checkout concurrrently.
Below is an example usage of concurrently.
concurrently "command1 arg" "command2 arg"
(or)
conc "command1 arg" "command2 arg"
tRPC uses this below command:
conc -c \"green,blue\" \"vitest run\" \"pnpm -F tests test-run:tsc\"
About us:
At Thinkthroo, we study large open source projects and provide architectural guides. We have developed resubale Components, built with tailwind, that you can use in your project. We offer Next.js, React and Node development services.
Book a meeting with us to discuss your project.
Top comments (0)