| 1 | import * as path from "node:path"; |
| 2 | |
| 3 | import * as glob from "glob"; |
| 4 | import Mocha from "mocha"; |
| 5 | |
| 6 | export function run() { |
| 7 | // Avoid timing out when stopping on breakpoints during debugging in VSCode |
| 8 | const timeoutOption = process.env.MOCHA_TIMEOUT |
| 9 | ? Number.parseInt(process.env.MOCHA_TIMEOUT) |
| 10 | : // : undefined; |
| 11 | 30_000; |
| 12 | |
| 13 | // Create the mocha test |
| 14 | const mocha = new Mocha({ |
| 15 | ui: "tdd", |
| 16 | color: true, |
| 17 | timeout: timeoutOption, |
| 18 | }); |
| 19 | |
| 20 | // See esbuild.test.mjs for more details |
| 21 | // Assumes this file is in out/test/runner/mochaRunner.js |
| 22 | const compiledTestSuitesDirectory = path.resolve(__dirname); |
| 23 | |
| 24 | glob |
| 25 | .sync("**/**.test.js", { cwd: compiledTestSuitesDirectory }) |
| 26 | .forEach((file) => { |
| 27 | mocha.addFile(path.resolve(compiledTestSuitesDirectory, file)); |
| 28 | }); |
| 29 | |
| 30 | console.log( |
| 31 | `Testing files in ${compiledTestSuitesDirectory}: ${mocha.files}`, |
| 32 | ); |
| 33 | |
| 34 | return new Promise<void>((resolve, reject) => { |
| 35 | try { |
| 36 | // Run the mocha test |
| 37 | mocha.run((failures) => { |
| 38 | if (failures > 0) { |
| 39 | reject(new Error(`${failures} tests failed.`)); |
| 40 | } else { |
| 41 | resolve(); |
| 42 | } |
| 43 | }); |
| 44 | } catch (err) { |
| 45 | console.error(err); |
| 46 | reject(err); |
| 47 | } |
| 48 | }); |
| 49 | } |