lucono/karma-test-explorer

The setting: karmaProcessCommand

chudzikmagda opened this issue · 7 comments

Describe the Bug
I've tried running a few commands eg:
npm run something node_modules/.bin/gulp start node test.js and I've always received a message: 'Extension host terminated unexpectedly.'

[exthost] [info] ExtensionService#_doActivateExtension hbenl.vscode-test-explorer, startup: false, activationEvent: 'onLanguage:javascript', root cause: lucono.karma-test-explorer

Error in the developer tools

%c[Error: Attempt to end execution before starting it%c at rf.end (\.vscode\extensions\lucono.karma-test-explorer-0.5.0\dist\main.js:5122:28)%c	at Server.<anonymous> (\.vscode\extensions\lucono.karma-test-explorer-0.5.0\dist\main.js:31164:174)%c at Server.emit (events.js:327:22)%c at emitCloseNT (net.js:1659:8)%c at processTicksAndRejections (internal/process/task_queues.js:79:21)]

Steps to Reproduce the Behavior

  1. Add e.g. "karmaTestExplorer.karmaProcessCommand":"node test.js" to the VSC settings in the project
  2. Start plugin.

Describe the Expected Behavior
First run the commend form the setting, then start Karma.

Screenshot
Przechwytywanie

System info

  • OS: Windows 10
  • Node Version: 16.13.0
  • VSCode Version: 1.64.2
  • Karma Version: 6.3.11

I have a few questions regarding the issue, basically those in the bug template if you can provide those here. Don't worry about logs and screenshots, but please provide all the other info, including OS and environment info to help better understand the issue.

@lucono ok, done :)

@chudzikm The karmaTestExplorer.karmaProcessCommand setting is for using a different or custom Karma executable, script, or command for launching Karma - rather than the Karma binary installed in your node_modules folder or environment.

It should be the name of a single command, or path to a single script/executable - without any arguments. For a script/executable path, it could either be an absolute path to the script, or a path relative to the project root. Karma Test Explorer will then call that script/command/executable instead - as if it were the Karma binary installed in your project (ie. in node_modules).

For instance, if you had karmaTestExplorer.karmaProcessCommand set to ./my-custom-script.sh, then Karma Test Explorer would run the following command when trying to launch the karma server:

# Normal command with no karmaProcessCommand setting:
npx karma start karma.conf --no-single-run

# Command instead with karmaProcessCommand setting:
./my-custom-script.sh start karma.conf --no-single-run

In your case, if you are trying to execute a command prior to launching Karma for your tests, what you could do is write a custom script (or windows batch file if you're on windows) that runs the command you need, before subsequently invoking Karma with all of the same arguments that were passed to the script. Then set karmaTestExplorer.karmaProcessCommand to your custom script.

@lucono thanks for your explanation.

I asked about it because I use Gulp for starting the tests. Maybe you could add a possibility to launch node.js scripts as well. It would be a more flexible solution because then you don't need to write binary scripts for all systems. What do you think?

@chudzikm Support for node scripts makes sense. Launching Karma is handled by the KarmaCommandLineTestServerExecutor. If you'd like to submit a PR, I'd be willing to review and release it.

@chudzikm Please re-open or open a new issue when ready to contribute the feature.