DEV Community

Ramu Narasinga
Ramu Narasinga

Posted on • Edited on

Istanbul usage in tRPC source code

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",
Enter fullscreen mode Exit fullscreen mode

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/**',
 ],
},
Enter fullscreen mode Exit fullscreen mode

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\"",
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

tRPC uses this below command:

conc -c \"green,blue\" \"vitest run\" \"pnpm -F tests test-run:tsc\"
Enter fullscreen mode Exit fullscreen mode

About me:

Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.

I am open to work on an interesting project. Send me an email at ramu.narasinga@gmail.com

My Github - https://github.com/ramu-narasinga
My website - https://ramunarasinga.com
My Youtube channel - https://www.youtube.com/@thinkthroo
Learning platform - https://thinkthroo.com
Codebase Architecture - https://app.thinkthroo.com/architecture
Best practices - https://app.thinkthroo.com/best-practices
Production-grade projects - https://app.thinkthroo.com/production-grade-projects

References:

  1. https://github.com/trpc/trpc/blob/next/packages/client/src/links/httpBatchLink.ts#L91C12-L91C30

  2. https://github.com/gotwarlost/istanbul

  3. https://istanbul.js.org/

  4. https://github.com/istanbuljs

  5. https://github.com/trpc/trpc/blob/d603d860a3aeb12bbf6e836abd8c5a30c7b5d7a5/vitest.config.ts#L45

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay