forked from NomicFoundation/hardhat-vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
58 lines (53 loc) · 1.54 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import path from "path";
// eslint-disable-next-line import/no-extraneous-dependencies
import Mocha from "mocha";
// eslint-disable-next-line import/no-extraneous-dependencies
import glob from "glob";
import vscode from "vscode";
import { sleep } from "./helpers/sleep";
export function run(): Promise<void> {
// Create the mocha test
const mocha = new Mocha({
ui: "tdd",
color: true,
rootHooks: {
beforeAll: async () => {
// Wait until extension is fully initialized (index + analysis + validation ready)
while (
vscode.extensions
.getExtension("nomicfoundation.hardhat-solidity")
?.exports.isReady() !== true
) {
await sleep(100);
}
// await sleep(5000); // Wait for the extension to be loaded
},
},
timeout: 30000,
retries: 5,
});
const testsRoot = path.resolve(__dirname, "tests");
return new Promise((resolve, reject) => {
glob("**/*.test.js", { cwd: testsRoot }, (err, files) => {
if (err) {
return reject(err);
}
// Add files to the test suite
files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f)));
try {
// Run the mocha test
mocha.run((failures) => {
if (failures > 0) {
reject(new Error(`${failures} tests failed.`));
} else {
resolve();
}
});
} catch (innerErr) {
// eslint-disable-next-line no-console
console.error(innerErr);
reject(innerErr);
}
});
});
}