Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit d945752

Browse files
authored
Merge pull request #5782 from trufflesuite/fix/in-test-runnable
Fix missing mocha runner during in-test debugging setup
2 parents 7899cad + 077ca84 commit d945752

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

packages/core/lib/debug/mocha.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class CLIDebugHook {
1818
// turn off timeouts for the current runnable
1919
// HACK we don't turn it back on because it doesn't work...
2020
// tests that take a long time _after_ debug break just won't timeout
21-
this.disableTimeout();
21+
await this.disableTimeout();
2222

2323
const { txHash, result, method } = await this.invoke(operation);
2424
debug("txHash: %o", txHash);
@@ -38,8 +38,8 @@ class CLIDebugHook {
3838

3939
async start() {}
4040

41-
disableTimeout() {
42-
this.runner.currentRunnable.timeout(0);
41+
async disableTimeout() {
42+
(await this.runner).currentRunnable.timeout(0);
4343
}
4444

4545
async invoke(operation) {

packages/test/src/Test.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let Mocha: any; // Late init with "mocha" or "mocha-parallel-tests"
2424
chai.use(require("./assertions").default);
2525

2626
type CreateInTestDebugFunction = (options: {
27-
mochaRunner: any;
27+
mochaRunner: Promise<unknown>;
2828
config: Config;
2929
compilations: Compilation[];
3030
}) => (operation: any) => any;
@@ -90,6 +90,17 @@ export const Test = {
9090

9191
const mocha = this.createMocha(config);
9292

93+
// set up a promise on this instance to resolve to
94+
// Mocha's "runner" returned by `mocha.run(...)`.
95+
//
96+
// do this upfront so that the promise is available
97+
// immediately, even though mocha.run happens at the very
98+
// end of this setup.
99+
let setMochaRunner: (mochaRunner: unknown) => void;
100+
this.mochaRunner = new Promise(resolve => {
101+
setMochaRunner = resolve;
102+
});
103+
93104
const jsTests = config.test_files.filter((file: string) => {
94105
return path.extname(file) !== ".sol";
95106
});
@@ -177,10 +188,14 @@ export const Test = {
177188
});
178189

179190
return new Promise(resolve => {
180-
this.mochaRunner = mocha.run((failures: number) => {
191+
const mochaRunner = mocha.run((failures: number) => {
181192
config.logger.warn = warn;
182193
resolve(failures);
183194
});
195+
196+
// finish setting up the mocha runner so that the
197+
// previously-made promise resolves.
198+
setMochaRunner(mochaRunner);
184199
});
185200
},
186201

0 commit comments

Comments
 (0)