Emitting rerun on more than one file makes the runner throw:
Uncaught TypeError: Cannot read property 'stop' of null
at $Cypress.stop (cypress_runner.js:59712)
at Object._reRun (cypress_runner.js:163510)
at Socket.rerun (cypress_runner.js:163243)
at Socket.Emitter.emit (cypress_runner.js:167896)
at Socket.onevent (cypress_runner.js:170798)
at Socket.onpacket (cypress_runner.js:170756)
at Manager.<anonymous> (cypress_runner.js:164988)
at Manager.Emitter.emit (cypress_runner.js:167896)
at Manager.ondecoded (cypress_runner.js:170272)
at Decoder.<anonymous> (cypress_runner.js:164988)
at Decoder.Emitter.emit (cypress_runner.js:165126)
at Decoder.add (cypress_runner.js:171421)
at Manager.ondata (cypress_runner.js:170262)
at Socket.<anonymous> (cypress_runner.js:164988)
at Socket.Emitter.emit (cypress_runner.js:167896)
at Socket.onPacket (cypress_runner.js:166017)
This might not be a bug per se, but I couldn't figure out how we should properly write a watch plugin. E.g. the cypress-app-watcher-preprocessor does it the same.
As a workaround, instead of looping through every open file, I emit the rerun on a randomly chosen open file which triggers re-run of everything open, anyway --- but this feels weird.
Check plugins/index.js from https://github.com/dwelle/cypress-test-tiny
Repro yourself:
git clone https://github.com/dwelle/cypress-test-tiny && cd cypress-test-tiny &&\
npm i && npx cypress open
Check the devTools console.
cypress: 3.1.5
node: v10.12.0
os: win7
Can you describe what your goal is with this preprocessor?
Simply re-run whatever is currently open (based on an IPC message, but that's irrelevant). Same as cypress-app-watcher-preprocessor is doing.
Not sure what pattern to use, but even the docs don't state anything about how to handle multiple files at once (which is almost always the case, due to support/index.js being one of them).
Thus, considering many people may run into this, cypress should take into account people may try to emit('rerun') on multiple files at once, and either display a warning, or handle it properly.
I see. We need to debounce the handler for rerun events to handle this case and prevent this error.
For the time-being, your workaround of only emitting on a single file should work.
@chrisbreiding
Can you prioritize this please, as it is resulting a crash in cypress open?
@Uzlopak can you elaborate? The workaround is to emit the even on any single file that's currently open (pick one at random).
Same thing happens when using the @cypress/webpack-preprocessor
https://github.com/cypress-io/cypress-webpack-preprocessor/blob/175abcf9fcecccdc324bfb9ae318d36f12c4bde9/index.js#L157