Tabcorp / atom-mocha-test-runner

Mocha test runner for Atom Editor
https://atom.io/packages/mocha-test-runner
MIT License
38 stars 18 forks source link

Add support for nvm #61

Open gustavnikolaj opened 8 years ago

gustavnikolaj commented 8 years ago

I work with many different apps on different node versions, and having to manually enter the path to the correct node version before running the tests is a bit annoying. It would be completely awesome if you could add support for nvm.

The problem is to discover

a) Which node version to use b) Where nvm is located

I propose to solve problem a by using .nvmrc files that are already an established convention for tools that rely on nvm. (nvm use will use a .nvmrc file, and so will travis ci if you don't specify the version). Problem b could be solved by adding a new configuration option to point at the nvm directory.

I love this plugin, and it's exactly the kind of integration I'm looking for, I just cannot make it work without nvm support :)

nguyenchr commented 8 years ago

hey @gustavnikolaj thanks for the feedback

I think this is a great idea

What do you think of this approach

Have a new option in settings * Use NVM

If this is selected we will execute the nvm which command which will return the path to the binary for the version specified in the .nvmrc file

we can then use that version of node to run the specs

if there if a nvmrc file but the user does not have the version installed, we can put the output into the atom console so that the user knows to install

if there is no nvmrc file we fallback to using the specified node path or global node

gustavnikolaj commented 8 years ago

@nguyenchr Thanks for the quick reply!

I love your idea.

But I'm afraid that it still doesn't solve the problem b. Normally nvm is sourced in a .bashrc file, which is unlikely to be loaded into the environment where Atom is executing. nvm which is a function registered by the nvm.sh script that is sourced in .bashrc. So I think that we would still need the user to point us at their $NVM_DIR. We could of course try a few educated guesses about the path of it. I think the default installation process will put the files in ~/.nvm/ so that could be the default, which would work for most people :-)

I could be wrong though, but even though it's not perfect, the workaround suggested above seems OK to me.

nguyenchr commented 8 years ago

yep that's a good point about the $NVM_DIR I'll have a play around and see if I can source that in any way

worst case scenario we can get the user to put their nvm path in the settings