From e7c3c68bd666cfe33b71cd13feabc1d805cd70dc Mon Sep 17 00:00:00 2001 From: Jeff Robbins Date: Wed, 11 Dec 2024 16:07:42 -0500 Subject: [PATCH] feat: nodePath & mochaPath --- README.md | 3 +++ package.json | 12 +++++++++++- src/configurationFile.ts | 3 ++- src/node.ts | 7 +++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d0a398b..0095aed 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,9 @@ This extension automatically discovers and works with the `.mocharc.js/cjs/yaml/ - `mocha-vscode.env`: Additional environment variables set when executing tests. This is useful for setting things like `NODE_ENV`. +- `mocha-vscode.mochaPath`: Specifies the path to the Mocha executable. If not set, the extension will attempt to resolve the Mocha executable from the local `node_modules` directory. +- `mocha-vscode.nodePath`: Specifies the path to the Node.js executable. If not set, the extension will use the default Node.js executable. + ## Features ### Show, Running and Debugging Tests diff --git a/package.json b/package.json index ab4f6da..43a0f01 100644 --- a/package.json +++ b/package.json @@ -105,6 +105,16 @@ "type": "object", "additionalProperties": true, "markdownDescription": "Additional environment variables set when executing tests. This is useful for setting things like `NODE_ENV`." + }, + "mocha-vscode.nodePath": { + "type": "string", + "default": "", + "description": "Path to the Node.js executable." + }, + "mocha-vscode.mochaPath": { + "type": "string", + "default": "", + "description": "Path to the Mocha executable." } } } @@ -205,4 +215,4 @@ "version": "v1.2.3+d27e65f", "date": "2024-10-20T15:38:24.261Z" } -} +} \ No newline at end of file diff --git a/src/configurationFile.ts b/src/configurationFile.ts index b196dba..b2a439c 100644 --- a/src/configurationFile.ts +++ b/src/configurationFile.ts @@ -93,7 +93,8 @@ export class ConfigurationFile implements vscode.Disposable { } async getMochaSpawnArgs(customArgs: readonly string[]): Promise { - this._pathToMocha ??= await this._resolveLocalMochaBinPath(); + const mochaPath = vscode.workspace.getConfiguration('mocha-vscode').get('mochaPath'); + this._pathToMocha = mochaPath || (await this._resolveLocalMochaBinPath()); return [ await getPathToNode(this.logChannel), diff --git a/src/node.ts b/src/node.ts index 7c27258..c8e9219 100644 --- a/src/node.ts +++ b/src/node.ts @@ -25,6 +25,13 @@ export async function getPathTo(logChannel: vscode.LogOutputChannel, bin: string let pathToNode: string | null = null; export async function getPathToNode(logChannel: vscode.LogOutputChannel) { + // Check if the nodePath setting is defined + const nodePath = vscode.workspace.getConfiguration('mocha-vscode').get('nodePath'); + if (nodePath) { + logChannel.debug(`Using nodePath from settings: '${nodePath}'`); + return nodePath; + } + // We cannot use process.execPath as this points to code.exe which is an electron application // also with ELECTRON_RUN_AS_NODE this can lead to errors (e.g. with the --import option) // we prefer to use the system level node