Validation Error when running jest command within node child process

● Validation Error:
Jul 2 09:49:39 AM  
Jul 2 09:49:39 AM    Module <rootDir>/test/setup.ts in the setupFilesAfterEnv option was not found.
Jul 2 09:49:39 AM           <rootDir> is: /opt/render/project/src/.blitz/build
Jul 2 09:49:39 AM  
Jul 2 09:49:39 AM    Configuration Documentation:
Jul 2 09:49:39 AM

What I’m trying to do is pretty complex so I’ll explain it as best I can.

I have cheerio parsers that run against HTML and each one has a test associated with it.

When I receive an email at an address it is configured with sendgrid to trigger a webhook and send a post request to a blitz app that is running on the service.

From there the endpoint for that parse process tries to parse that email. It runs a function that uses the execSync method in child-process to run the corresponding parser test for the sender of that email.

The command that gets run executes a custom jest test runner.

'use strict'

const config = {
	html: undefined,
	flag: false
const argv = process.argv.slice(0, 3)

// Naive argv parsing
process.argv.reduce((cmd, arg) => {
	if (cmd) {
		config[cmd] = arg

	if (arg.startsWith('--')) {
		const sub = arg.substring('--'.length)
		if (Object.keys(config).includes(sub)) {
			if (typeof config[sub] === 'boolean') {
				config[cmd] = true

			return sub


// Store configuration on env
process.env.__CONFIGURATION = JSON.stringify(config)

// Setting real ARGV
process.argv = argv

// Calling jest runner

This runner lets me pass extra arguments, this is where it gets fun.

I can’t pass the direct HTML as an argument so I have to create a temp file and pass the path to it into the HTML option of the runner. Each test is set up to load that temp file and pass the HTML string into the cheerio test. If the test fails it will not store the parsed result in the DB instead it will send a message to my email from SendGrid with a result of why the parsing failed.

An example command:

yarn test app/core/logic/parsers/test/test-parser.spec.ts --html /temp/temp-ljkklk/test_file

The test command runs:

node runner.js

It’s possible that the command is being executed in the wrong directory. If I run any of these commands in the shell tab it works. So I might have to configure how jest should run in this case.

Hi @JohnGrisham,

Welcome to the Render community! I took a look over the jest documentation and it looks like you can configure jest with the setupFilesAfterEnv to include that setup.ts file. Their docs give an example jest.config.js that for your case might look like:

module.exports = {
  setupFilesAfterEnv: ['<rootDir>/test/setup.ts'],

They have more information about it here:

I am not super familiar with jest but from that error message it looks like this might be a good place to start.

So after looking into this more. It seems the problem is that the command was being run in the .blitz/build folder since that is where the build files go. The build folder has no tests or jest configuration so that explains why nothing worked. I was able to get it to run by executing the commands at the src folder of the render project.

cd ~/project/src && yarn test