@@ -36,11 +36,33 @@ exports.watchParallelRun = (
36
36
watchFiles,
37
37
watchIgnore,
38
38
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
+
40
62
// in parallel mode, the main Mocha process doesn't actually load the
41
63
// files. this flag prevents `mocha.run()` from autoloading.
42
- mocha . lazyLoadFiles ( true ) ;
43
- return mocha ;
64
+ newMocha . lazyLoadFiles ( true ) ;
65
+ return newMocha ;
44
66
} ,
45
67
afterRun ( { watcher} ) {
46
68
blastCache ( watcher ) ;
0 commit comments