The Simplest Way to Make Jest and New Relic Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams pair Jest and New Relic to send test results to one central place. This setup lets developers track flaky tests, measure build times, and spot slow steps. Jest runs unit and integration tests for JavaScript apps in local and build setups. New Relic stores logs, metrics, and traces so teams can watch system health. When you link them, test runs become clear data points that you can query. You can see which tests fail most often and why builds slow down. How Jest and New Relic share data

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Teams pair Jest and New Relic to send test results to one central place. This setup lets developers track flaky tests, measure build times, and spot slow steps.

Jest runs unit and integration tests for JavaScript apps in local and build setups. New Relic stores logs, metrics, and traces so teams can watch system health. When you link them, test runs become clear data points that you can query. You can see which tests fail most often and why builds slow down.

How Jest and New Relic share data and keys

Jest uses custom reporters to collect test counts, pass rates, and run times. At the end of a test suite, the reporter formats this output as events. The reporter then sends these events over HTTPS to the New Relic intake endpoint. To do this, the build runner needs a valid New Relic ingest key.

Most teams store this ingest key in their continuous integration secret store. When the pipeline starts a test job, it loads the key into memory. Jest reads the key, runs the test suite, and ships the summary metrics. If the test touches a real database, the New Relic agent can trace queries.

You must separate test data from live app traffic in your New Relic account. If Jest loads the standard app agent, test errors look like live outages. This wakes up on-call engineers for false alarms during a normal code build. Teams fix this by turning off the main agent or using a test account.

Common traps with shared keys and broad roles

A common mistake is putting one broad New Relic key in every code repo. If a developer prints build variables to the screen, that key leaks in logs. Anyone who reads the build log can then send fake metrics or read data. You should create a write-only ingest key that only accepts test event data.

Another trap happens when Jest runs tests against shared staging databases. Developers often use one shared database login for all automated test workers. When a slow test locks a table, the traces show the same shared user. You cannot tell which pipeline run or code branch caused the database lock.

End-to-End Encryption + New Relic Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Some test suites also pull sample records that hold real customer details. If a test fails, Jest prints the raw record into the error message. The reporter then ships that error text straight to New Relic log storage. Now your monitoring tool holds sensitive emails, phone numbers, or card numbers.

Scoping permissions and network paths for test runs

Start by giving your test runner its own New Relic key with narrow permissions. This key should only write custom test events and never query account data. Rotate this key on a set schedule using your secret manager tool. If one pipeline gets exposed, you can revoke that single key right away.

Next, tag every test event with the branch name and build ID. This makes it easy to filter test metrics on your dashboards. Keep test traces in a separate workspace so they never trigger live paging rules. You get clear data on test speed while your alerts stay quiet and clean.

Finally, clean your test output before the reporter sends anything over the network. Set up masking rules that rewrite emails, phone numbers, and national IDs in results. Lock down network paths so test runners only talk to isolated test databases. This keeps both your data stores and your metric logs safe.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Should I run the full New Relic agent during Jest unit tests?

No, you should disable the full agent during standard unit test runs. The agent adds startup delay, keeps processes open, and pollutes live app metrics. Use a custom Jest reporter to send simple test results instead.

How do I stop Jest from hanging when New Relic is enabled?

The New Relic agent keeps an active background timer to send data batches. This open handle stops Jest from exiting after the final test finishes. Turn off the agent in your test setup file so Jest closes cleanly.

What is the safest way to send Jest metrics to New Relic?

Use a dedicated write-only ingest key stored in your build runner secret store. Send only test names, statuses, and durations from your Continuous Integration jobs. Never let local developer machines push test metrics with shared production keys.

The query runs. The emails stay hidden.