Tests are the safety net that protects your codebase from unexpected issues and regressions. They provide immediate feedback, ensure business logic remains intact, and make refactoring less risky.
The Cost of Skipping Tests
Skipping tests might save time in the short term, but it leads to technical debt and slows down future development. Unverified changes can cause subtle bugs that are costly to diagnose and fix later.
Enforcing Test Coverage with Danger.js
To make testing a non-negotiable part of your workflow, you can use Danger.js to automate PR checks. Danger.js lets you define rules for pull requests, including requiring tests for every bug fix or new feature. For example, you can write a Danger.js rule that fails the PR if no test files are modified or added:
// dangerfile.js
const modifiedFiles = danger.git.modified_files;
const createdFiles = danger.git.created_files;
const testPattern = /__tests__|\.test\.js$/;
const containsTest = [...modifiedFiles, ...createdFiles].some(file => testPattern.test(file));
if (!containsTest) {
fail('Every PR must include relevant tests. Please add or update tests for your change.');
}
Fostering a Culture of Quality
Automating the rejection of PRs without tests sends a clear message: code quality is a shared responsibility. With a simple Danger.js rule, you can help your team stay focused on long-term quality without compromising on shipping speed.
Run the example or inspect the source inline.