● 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 https://jestjs.io/docs/configuration.html
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
return
}
if (arg.startsWith('--')) {
const sub = arg.substring('--'.length)
if (Object.keys(config).includes(sub)) {
if (typeof config[sub] === 'boolean') {
config[cmd] = true
return
}
return sub
}
}
argv.push(arg)
})
// Store configuration on env
process.env.__CONFIGURATION = JSON.stringify(config)
// Setting real ARGV
process.argv = argv
// Calling jest runner
require('jest-cli/bin/jest')
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.