@@ -36,11 +36,33 @@ exports.watchParallelRun = (
3636 watchFiles,
3737 watchIgnore,
3838 beforeRun ( { mocha} ) {
39- mocha . files = collectFiles ( fileCollectParams ) ;
39+ // I don't know why we're cloning the root suite.
40+ const rootSuite = mocha . suite . clone ( ) ;
41+
42+ // this `require` is needed because the require cache has been cleared. the dynamic
43+ // exports set via the below call to `mocha.ui()` won't work properly if a
44+ // test depends on this module (see `required-tokens.spec.js`).
45+ const Mocha = require ( '../mocha' ) ;
46+
47+ // ... and now that we've gotten a new module, we need to use it again due
48+ // to `mocha.ui()` call
49+ const newMocha = new Mocha ( mocha . options ) ;
50+ // don't know why this is needed
51+ newMocha . suite = rootSuite ;
52+ // nor this
53+ newMocha . suite . ctx = new Context ( ) ;
54+
55+ // reset the list of files
56+ newMocha . files = collectFiles ( fileCollectParams ) ;
57+
58+ // because we've swapped out the root suite (see the `run` inner function
59+ // in `createRerunner`), we need to call `mocha.ui()` again to set up the context/globals.
60+ newMocha . ui ( newMocha . options . ui ) ;
61+
4062 // in parallel mode, the main Mocha process doesn't actually load the
4163 // files. this flag prevents `mocha.run()` from autoloading.
42- mocha . lazyLoadFiles ( true ) ;
43- return mocha ;
64+ newMocha . lazyLoadFiles ( true ) ;
65+ return newMocha ;
4466 } ,
4567 afterRun ( { watcher} ) {
4668 blastCache ( watcher ) ;
0 commit comments