From 24f0ea2103500ff4dbfe42939cdfe7ae1724ce09 Mon Sep 17 00:00:00 2001 From: cedar Date: Mon, 8 Jun 2026 10:14:10 +0800 Subject: [PATCH] Fix npm test runner on Windows --- package.json | 2 +- test/run-mocha.js | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/run-mocha.js diff --git a/package.json b/package.json index 5335436..6258e2c 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "cover": "nyc --reporter=html --reporter=text npm test", "dependencies": "docker-compose up -d BGLd BGLd-ssl BGLd-username-only", "lint": "eslint src test", - "test": "NODE_ENV=test mocha $npm_package_options_mocha", + "test": "node test/run-mocha.js", "testdocker": "docker-compose run --rm sut", "version": "npm run changelog --future-release=$npm_package_version && git add -A CHANGELOG.md" }, diff --git a/test/run-mocha.js b/test/run-mocha.js new file mode 100644 index 0000000..a7eadbc --- /dev/null +++ b/test/run-mocha.js @@ -0,0 +1,26 @@ +'use strict'; + +const path = require('path'); +const { spawnSync } = require('child_process'); + +process.env.NODE_ENV = 'test'; + +const mochaBin = path.join(__dirname, '..', 'node_modules', 'mocha', 'bin', 'mocha'); +const result = spawnSync(process.execPath, [ + mochaBin, + '--timeout', + '20000', + '--recursive', + '--require', + 'should' +].concat(process.argv.slice(2)), { + cwd: path.join(__dirname, '..'), + env: process.env, + stdio: 'inherit' +}); + +if (result.error) { + throw result.error; +} + +process.exit(result.status === null ? 1 : result.status);