|
2 | 2 |
|
3 | 3 | import { createRequire } from "node:module";
|
4 | 4 | import process from "node:process";
|
| 5 | +import { resolve } from "node:path"; |
| 6 | +import {fileURLToPath} from "node:url"; |
5 | 7 |
|
6 |
| -import { parse } from "https://deno.land/std/flags/mod.ts" |
7 |
| -const args = parse(Deno.args); |
| 8 | +import { spawn } from "node:child_process"; |
8 | 9 |
|
9 | 10 | Error.stackTraceLimit = 100;
|
10 | 11 |
|
11 | 12 | const require = createRequire(import.meta.url);
|
12 | 13 |
|
13 |
| -const Mocha = require('mocha'); |
14 |
| -const fs = require('fs'); |
15 |
| -const path = require('path'); |
| 14 | +const fixtures = require('./mocha-fixtures.js') |
16 | 15 |
|
17 |
| -// const fixtures = require('./mocha-fixtures.js'); |
| 16 | +await fixtures.mochaGlobalSetup(); |
18 | 17 |
|
19 |
| -const mocha = new Mocha({ |
20 |
| - timeout: 8000, |
21 |
| - ...(args.g ? { fgrep: '' + args.g } : {}) |
22 |
| -}); |
23 |
| - |
24 |
| -// the following is required because mocha somehow does not load "require" options and so needs to be manually set-up |
25 |
| -// mocha.globalSetup(fixtures.mochaGlobalSetup); |
26 |
| -// mocha.globalTeardown(fixtures.mochaGlobalTeardown); |
| 18 | +const child_args = [ |
| 19 | + // args is required to be set manually, because there is currently no way to get all arguments from deno |
| 20 | + '--allow-env', '--allow-read', '--allow-net', '--allow-run', '--allow-sys', '--allow-write', |
| 21 | + ...Deno.args, |
| 22 | + resolve(fileURLToPath(import.meta.url), '../deno_mocha.js') |
| 23 | +]; |
27 | 24 |
|
28 |
| -const testDir = 'test'; |
| 25 | +const child = spawn(process.execPath, child_args, { stdio: 'inherit' }); |
29 | 26 |
|
30 |
| -const files = fs.readdirSync(testDir). |
31 |
| - concat(fs.readdirSync(path.join(testDir, 'docs')).map(file => path.join('docs', file))). |
32 |
| - concat(fs.readdirSync(path.join(testDir, 'helpers')).map(file => path.join('helpers', file))); |
33 |
| - |
34 |
| -const ignoreFiles = new Set(['browser.test.js']); |
| 27 | +child.on('exit', (code, signal) => { |
| 28 | + signal ? doExit(-100) : doExit(code); |
| 29 | +}); |
35 | 30 |
|
36 |
| -for (const file of files) { |
37 |
| - if (!file.endsWith('.test.js') || ignoreFiles.has(file)) { |
38 |
| - continue; |
39 |
| - } |
| 31 | +Deno.addSignalListener("SIGINT", () => { |
| 32 | + console.log("SIGINT"); |
| 33 | + child.kill("SIGINT"); |
| 34 | + doExit(-2); |
| 35 | +}); |
40 | 36 |
|
41 |
| - mocha.addFile(path.join(testDir, file)); |
| 37 | +async function doExit(code) { |
| 38 | + await fixtures.mochaGlobalTeardown(); |
| 39 | + Deno.exit(code); |
42 | 40 | }
|
43 |
| - |
44 |
| -mocha.run(function(failures) { |
45 |
| - process.exitCode = failures ? 1 : 0; // exit with non-zero status if there were failures |
46 |
| - process.exit(process.exitCode); |
47 |
| -}); |
0 commit comments