mocha-webpack
mocha-webpack copied to clipboard
Watch and always run entire suite?
Is there an option for this already built in?
No, I thought about it a long time ago but came to the conclusion that there isn't any benefit. Why do you need this?
mocha-webpack detects file changes and all files that were affected by a file change, especially in the latest beta. The latest non-beta (0.7.0) has some issues in the detection.
Still have some issue with file change, sometimes some tests are not re-run. Some co-workers are not using watch
anymore... (with v1.0.0-beta.1
and our 700 tests)
@zinserjan one issue we've seen is that a code change will break dependent files. When we fix the dependent file/test we lose context of all the other breakages.
Say: b.js and c.js import a.js. If I make a change to a.js that causes breakage to b.js and c.js fixing one will cause me to lose the context of the other.
I don't have a good solution other than disable interactive (which is what we do).
I totally get not wanting to run the whole suite (that's the point of watching with webpack's help) but it would be nice for it to re-run whatever is needed (according to webpack) plus any failures from the previous run not already in the webpack set.
Does that make sense?
@castrog Yep, that would make sense. I also thought about this a long time ago... The only problem that I see that we need to know which test files failed before. At the moment we have only the information that something failed, but not which file exactly.
Question is, how can we detect which test files failed?
@serut Do you have the same issue like @castrog or is it something else?
@zinserjan could we do it through a pass-through reporter or something like that? I'm not very familiar with the mocha codebase but seems like the file is there, right? (https://github.com/mochajs/mocha/blob/master/lib/test.js#L49)
Yes that looks good, but I would expect that the file is the same for all tests cause mocha uses the webpack output bundle... I don't have any idea at the moment to get around this :smile:
Could we not use the source map for that? I can understand if the webpack config doesn't use a source map then this whole process wouldn't be attempted but if it's there we should be able to do it, no?
Mocha also seems to know where the failure happened if source maps are configured so I wonder if the file is already mapped if the source map is setup.
Good reason for rerunning some files: before/afterEach
hooks. Related issue: https://github.com/zinserjan/mocha-webpack/issues/166
But i would say that monkey-patching beforeEach or hooking to some events of mocha will make it possible to rerun the before-each and after-each bits
@zinserjan what do you think about this? Is this something you might tackle?
There is a valid use case for this. If some of my spec files fail, and I start working on one spec file until all the tests in it pass... The mocha-webpack output after the fact reports as if all the tests are passing (which they are, but only in that file).
To get back and see the bigger picture again I have to kill the process and run it again or touch the failing files to trigger a reload where they will be re-run.
An option to always re-run the suite sounds like a good idea.
mocha-webpack detects file changes and all files that were affected by a file change, especially in the latest beta. The latest non-beta (0.7.0) has some issues in the detection.
While this is technically a nice feature in some scenarios, it will often times confuse users rather than providing the actual benefit. I saw the magic going on and immediately was like "what is wrong with my test setup".
In the spirit of don't make me think can't we make predictable re-runs of the whole suite the default? The current way of selectively re-running of only change-related files could be opt-in for those who benefit from it, because they have massive test suites.
If there was a way to reliably cause mocha-webpack
to trigger a complete re-run, would that satisfy most users? Something like sending a signal -- e.g. kill SIGHUP
-- or touching a specific file?
Some prior art:
I typically don't use mocha --watch
because it's buggy and rely on nodemon
instead, which supports entering a rs
in the active thread to restart the monitored process (I think it also responds to SIGHUP
to restart). I've also used nodemon
watching the config file paired with karma
watching the test files so that I could just touch
the config to re-start karma
(which tends to crash). I can confirm that touch
-ing the config files for either mocha
or webpack
do NOT trigger a re-run currently. Is there another file that I could try?
Any update on this? I'm missing this feature with my use-case as well