Skip to content

Commit c7bdf1f

Browse files
committed
Add test:worker script that runs the mocha tests inside a worker
1 parent 1b5aa3a commit c7bdf1f

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
"prepublishOnly": "npm ls",
5151
"install": "node-pre-gyp install --fallback-to-build",
5252
"pretest": "node test/support/createdb.js",
53-
"test": "mocha -R spec --timeout 480000"
53+
"test": "mocha -R spec --timeout 480000",
54+
"test:worker": "node --experimental-worker scripts/mocha-as-worker.js -R spec --timeout 480000"
5455
},
5556
"license": "BSD-3-Clause",
5657
"keywords": [

scripts/mocha-as-worker.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Run the mocha tests in a worker
2+
// Not a clean approach, but is sufficient to verify correctness
3+
const worker_threads = require("worker_threads");
4+
const path = require("path");
5+
6+
if (worker_threads.isMainThread) {
7+
const worker = new worker_threads.Worker(__filename, { workerData: { windowSize: process.stdout.getWindowSize() } });
8+
worker.on("error", console.error);
9+
} else {
10+
process.stdout.getWindowSize = () => worker_threads.workerData.windowSize;
11+
const mochaPath = path.resolve(require.resolve("mocha"), "../bin/_mocha");
12+
require(mochaPath);
13+
}

0 commit comments

Comments
 (0)