karma-runner / karma-runner/karma
karma watch tends to fail with large streamed bundles
- Dominant language
- JavaScript
- Stars
- 12k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
i currently use gulp to produce two large JS bundles from TypeScript with browserify and factor-bundle. One bundle has all the main code and the other has all the specs.
The problem is when I use watch mode and update the bundles, karma detects two file change events on both files. I notice karma picks up the first change where the file is empty. This is confirmed by doing a readFileSync around [here](https://github.com/karma-runner/karma/blob/39d378d20dee61a88572225db9e1855da3adb346/lib/file-list.js#L362). Additionally, the syntax error message from the test execution also confirms this (i.e. `Unexpected end of input`).
Setting `autoWatchBatchDelay` to a higher number doesn't mitigate this problem. There is usually a 0.5 second delay between the first change event (empty file) and the second one (file generated). I'm not exactly sure what's going on there (maybe there's a race condition somewhere?) I remember adding a `console.log(self.files)` somewhere in the aforementioned section of code and since the output is very long, it takes time to flush to the terminal and the problem stops occurring (however waiting a long time is not a very productive activity!)
By enabling awaitWriteFinish in [chokidar](https://github.com/paulmillr/chokidar), the problem is mitigated. Maybe this is the solution?
https://github.com/karma-runner/karma/compare/master...khoomeister:ck-awaitwritefinish#diff-3c250c1426c199f7eccf17c774f0adfaR84
It'd be great to find a permanent fix for this as this is vital to our TDD workflow.
Contributor guide
Research direction
Start in lib/file-list.js around the readFileSync call at line 362 and review how chokidar change events are handled. Reproduce the issue with large streamed bundles in watch mode, then compare the proposed awaitWriteFinish behavior; done means generated files are not tested while empty and the syntax error no longer occurs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100