DianaSuvorova / atom-karma-test-runner

Run karma tests directly from atom IDE.
https://atom.io/packages/atom-karma-test-runner
MIT License
4 stars 0 forks source link

Running on win32 causes node syntax error #4

Closed jh3141 closed 6 years ago

jh3141 commented 6 years ago

When you try to run tests on win32, the runner tries to execute the command <node path> <project path>\node_modules\.bin\karma.cmd. karma.cmd is a windows batch file, not a JS script file, so this fails with the following error:

(function (exports, require, module, __filename, __dirname) { @IF EXIST "%~dp0\node.exe" (
                                                              ^
SyntaxError: Invalid or unexpected token
  at createScript (vm.js:56:10)
  ...

This is apparently because, despite the fact that the npm documentation states

On install, npm will symlink [files listed in the bin field of package.json] into prefix/bin for global installs, or ./node_modules/.bin/ for local installs

this isn't actually true on win32; on win32 it creates a batch file that attempts to find an installed copy of node and use it to run the configured script.

A suggested resolution may be to change the karmaBinary property returned from getContext to path.join(root, 'node_modules', 'karma-cli', 'bin', 'karma') which ought to work correctly. This does depend on internal details of the organisation of the karma packages, though, so if you're feeling adventurous it might make more sense to try parsing karma.cmd to extract the correct filename to execute directly. For reference, in case you don't have a windows machine to test on, the karma.cmd file generated on my system is:

@IF EXIST "%~dp0\node.exe" (
  "%~dp0\node.exe"  "%~dp0\..\karma-cli\bin\karma" %*
) ELSE (
  @SETLOCAL
  @SET PATHEXT=%PATHEXT:;.JS;=;%
  node  "%~dp0\..\karma-cli\bin\karma" %*
)
DianaSuvorova commented 6 years ago

@jh3141 thanks for giving this plugin a try and the detailed description for the issue. On macOS karma-cli is not installed as a package dependency when one installs karma. So path.join(root, 'node_modules', 'karma-cli', 'bin', 'karma') does not exist. Is it different on win? Or does one need to explicitly install karma-cli?

DianaSuvorova commented 6 years ago

@jh3141 fixed with 1.1.1 release. Thanks for reporting!