How to run Jest programmatically in node.js (Jest JavaScript API)

Slava Fomin II
A Path of Developer
1 min readJan 17, 2019

When working on a special build framework for DomClick I’ve stumbled upon a task to execute Jest test runner as part of our existing node.js process.

Sadly, the official documentation was lacking for this use case so I had to dig around a bit.

I’m going to post here a small example of how I’ve managed to finally achieve this. I’m going to use the amazing TypeScript.

Installing the dependencies

npm i -S jest-cli
npm i -D @types/jest-cli @types/jest

Making a call to Jest

The following code could be used to call Jest API internally:

However, please notice, that this API is not pubic so the implementation could change in the future versions of Jest. Actually, let me know in the comments if this happens.

--

--