In previous chapters, the default Karma configuration was used, but no explanation about this default configuration has been given yet. File watching is a useful default behavior that will now be reviewed.
File watching is enabled by default when the Karma init
command is used.
File watching in Karma is configured with the following definition in the
karma.conf.js
file:
autoWatch: true,
The file watching feature works as expected and watches the files defined in the configuration's files
array. When a file is updated, changed, or deleted, Karma responds by rerunning the tests. From a TDD perspective, this is a great feature, as tests will continue to run without any manual intervention.
The main point to watch out for is the addition of files. If the file being added doesn't match the criteria in the files
array, the autoWatch
parameter won't respond to the change. As an example, let's consider that the files are defined as follows:
files : [ 'dir1/*...