Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: nodePath & mochaPath #210

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jjeff
Copy link

@jjeff jjeff commented Dec 11, 2024

closes #209

This pull request adds settings for both mochaPath and nodePath. I was hoping this would help me to get electron-mocha working with this extension, but simply swapping out electron-mocha for mocha doesn't seem to do it.

Nonetheless, here's a PR of my changes.

And here's the robot has to say about it:

This pull request introduces new configuration options for specifying the paths to the Mocha and Node.js executables, and updates the code to utilize these configurations. The changes enhance the flexibility of the extension by allowing users to specify custom paths for these executables.

New configuration options:

  • README.md: Added descriptions for mocha-vscode.mochaPath and mocha-vscode.nodePath settings, which specify the paths to the Mocha and Node.js executables, respectively.

  • package.json: Added mocha-vscode.mochaPath and mocha-vscode.nodePath settings to the configuration schema.

Code updates to use new configurations:

  • src/configurationFile.ts: Updated getMochaSpawnArgs method to use the mochaPath setting if defined, falling back to resolving the local Mocha binary path if not.

  • src/node.ts: Updated getPathToNode function to use the nodePath setting if defined, logging the path being used.

Copy link
Member

@Danielku15 Danielku15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some remarks on your proposal:

  1. Did you find out why your change is not working?
  2. We need some unit/integration test for this feature to ensure it is working as expected.
  3. I assume these settings should be shared among users via settings.json commited to the repository. This raises some additional concerns about the "path" design:
    • For the alternative package to be used we likely want to assume relative paths. We have to clarify from where they are handled relatively.
    • Node.js is likely installed somewhere on the system and this cannot be properly shared. It would be incorrect to assume a fixed absolute system path.
    • For security reasons it would be likely good to enforce workspace relative paths.

Maybe the following approach could also serve your needs?

Instead of configuring the path to mocha and node we could launch shell/batch scripts with the respective arguments we would pass to mocha. These could be configurable or we simply search for a "mocha.{bat,sh}" in the workspace root if it exists, its used. In this shell script you can then launch any alternative executable and path with the arguments as you like.

Comment on lines +96 to +97
const mochaPath = vscode.workspace.getConfiguration('mocha-vscode').get<string>('mochaPath');
this._pathToMocha = mochaPath || (await this._resolveLocalMochaBinPath());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change breaks proper caching of the variable and cause re-evaluation on every spawn of mocha. We should keep the caching for the locally resolved path as it can be expensive in some scenarios.

Comment on lines +28 to +33
// Check if the nodePath setting is defined
const nodePath = vscode.workspace.getConfiguration('mocha-vscode').get<string>('nodePath');
if (nodePath) {
logChannel.debug(`Using nodePath from settings: '${nodePath}'`);
return nodePath;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your issue only talks about redirecting Mocha to anoter tooling. What's the real usecase behind redirecting node as well? Depending on your need also NPM would need support for reconfiguration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: mochaPath setting
2 participants