tessl install tessl/npm-jest-circus@29.7.0The next-gen flux-based test runner for Jest that provides test framework globals and event-driven test execution
Agent Success
Agent success rate when using this tile
82%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.91x
Baseline
Agent success rate without this tile
43%
Build a simple test suite for an asynchronous file watcher module that notifies callbacks when file changes are detected.
You are working with a file watcher utility that monitors files and triggers callbacks when changes occur. The watcher uses callback-based APIs rather than promises. You need to write tests for this callback-based asynchronous behavior.
Create a test suite that validates the file watcher's callback-based behavior:
The file watcher module has the following interface:
class FileWatcher {
// Starts watching a file and calls callback when changes occur
// callback signature: (error, filePath) => void
watch(filePath, callback) { }
// Simulates a file change (for testing purposes)
simulateChange(filePath) { }
// Simulates an error (for testing purposes)
simulateError(filePath, error) { }
}file-watcher.js that implements the FileWatcher class with the interface described above. The implementation should invoke callbacks asynchronously (e.g., using setTimeout) to simulate real async file system operations.Your test suite must include the following test cases:
@generates
/**
* A simple file watcher that monitors files and triggers callbacks on changes.
*/
class FileWatcher {
/**
* Start watching a file and register a callback to be invoked on changes.
* @param {string} filePath - The path of the file to watch
* @param {Function} callback - Callback function with signature (error, filePath) => void
*/
watch(filePath, callback) { }
/**
* Simulate a file change for testing purposes.
* Invokes all registered callbacks for the file with (null, filePath).
* @param {string} filePath - The path of the file that changed
*/
simulateChange(filePath) { }
/**
* Simulate an error for testing purposes.
* Invokes all registered callbacks for the file with (error, null).
* @param {string} filePath - The path of the file
* @param {Error} error - The error to pass to callbacks
*/
simulateError(filePath, error) { }
}
module.exports = FileWatcher;Provides the testing framework for writing callback-based asynchronous tests.