I'm trying to set up Karma to run AngularJS unit tests using Jasmine, but I can't get the tests to run. I'm sure I'm overlooking something simple. I'm running this on a Windows 7 machine with Node.js installed and karma installed via npm.
My directory structure looks like this:
js/app/ - contains controllers, app, etc
js/config/ - contains karma.conf.js
js/lib/ - contains angular
js/test/ - contains jasmine specs
I'm starting a command prompt in the js directory and running this command:
karma start config/karma.conf.js
That causes Chrome to run on port 9876, but whenever I change any watched files and check the Karma output, I see this info message:
No captured browser, open http://localhost:9876/
Here's my config file:
module.exports = function(config) {
config.set({
basePath: '../',
frameworks: ['jasmine'],
files: [
'lib/angular.js',
'app/**/*.js',
'test/**/*.js'
],
exclude: [
],
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
captureTimeout: 60000,
singleRun: false
});
};
I'm using Angular 1.2.10 and Karma 0.10.9
I had a face palm moment. karma start needs to be run in the same directory as your karma.conf.js file.
I just had the same issue in a different setup (Linux, QUnit, Firefox), though. The problem disappeared after I killed all karma processes and did a fresh karma start.
This error can mean that the browser can't find the server. Check if you can reach the server at the URL it mentions. It could be a misconfigured port number, or even (as it was in my case), localhost being misconfigured. I suppose it could be the server is not running, or any of a dozen other problems.
Check if you can reach the server manually. If you can't, fix that.
In my case the environment variable CHROME_BIN was set to a wrong path. Fix the value (might be defined in /etc/environment) or unset the environment variable temporarily with unset CHROME_BIN.
To find the cause of the problem it was helpful to set log level to debug in Karma's config file:
logLevel: config.LOG_DEBUG,
I had the same problem and it was a bug in a test. Removing that code fixed the error.
This happened to me when I had an endless loop in my code. Commenting out (using xdescribe in jasmine) recent code I wrote got the tests running again.
I had the same problem and tried a lot of the suggested solutions I found, but what finally solved it for me was to delete the node_modules folder and getting everything new via npm install.
same issue: Karma - Chrome failed 2 times (cannot start). Giving up
I had the same problem, no code changes, just re-running tests that worked a month ago.
When I ran from webstorm, it seemed to be taking a long time to capture the browser, so I wondered if it was timing out.
So I tried setting browser to just Chrome (i was using phantomjs as well), and waiting. Then reset back to Chrome and PhantomJS, now it's fine.
I had the same problem and I did all what everyone from here said without any result. In my case I didn't do the init:
C:\Users>cd c:\xampp\htdocs\angularjs-pro\ch07
c:\xampp\htdocs\angularjs-pro\ch07>karma init
Which testing framework do you want to use ?
Press tab to list possible options. Enter to move to the next question.
> jasmine
Do you want to use Require.js ?
This will add Require.js plugin.
Press tab to list possible options. Enter to move to the next question.
> no
Do you want to capture any browsers automatically ?
Press tab to list possible options. Enter empty string to move to the next question.
> Chrome
The second time when I got in the same situation was when I tried to do
karma start in the wrong folder, not where I put karma init.
In both cases after I fixed the problem I got in widows console:
22 11 2016 14:06:51.697:INFO [karma]: Karma v1.3.0 server started at http://localhost:9876/
22 11 2016 14:06:51.698:INFO [launcher]: Launching browser Chrome with unlimited concurrency
22 11 2016 14:06:51.711:INFO [launcher]: Starting browser Chrome
22 11 2016 14:06:53.936:INFO [Chrome 54.0.2840 (Windows 10 0.0.0)]: Connected on socket /#HnJUQrkRPqtGFa5ZAAAA with id 16058274
Installing karma-cli npm install -g karma-clisolved this issue for me.
Hope this helps.
I was facing the same issue and i resolved it by killing all the chrome instances from Task Manager. It seems that there were 'n' number of test runners running. When you close the karma test runner without stopping the server, it's instance is still alive.
So press 'alt + ctrl + delete', kill all sessions/instances of chrome and restart Karma.
It works!
Had the same error recently:
a project using angular-cli,
tests running on Jenkins in a headless environment.
Turns out I have cancelled a Jenkins job previously in the step where the tests were running, so ng test did not quit (had a handful of running ng processes, paired with [node] <defunct> ones, blocking the further test execution). Solution was to find and kill all hanging ng processes:
$ sudo -su jenkins
# ps aux | grep "ng$" | awk '{print $2}' | xargs kill -9
I had the same message because there was no Chrome installed on my PC. Just Chromium. Well, it turns out that's not the same. Now after installing Chrome, both 'Chrome' and 'ChromeHeadless' browsers are able to start.
Otherwise you might specify 'Chromium' or 'ChromiumHeadless' in config and be fine with it.
TLDR: Make sure you have actually installed the browser you are testing in.
Related
I have a Rails and React app that I'm debugging in IntelliJIdea 2022.2.3. I'm using Vite and not webpack.
I've set breakpoints on both ends of the app, but only the Ruby breakpoints are hitting.
Both debug servers are running on the same ip and port. 0.0.0.0:3000.
I tried setting the debug server to the same port (3000) but I'm still encountering the same problem.
In my case, I needed to start the rails server as I normally would (bundle exec rails s) before trying to start the JavaScript debugger in Intellij. Now my JavaScript breakpoints are hitting.
31 October update
I'm encountering the same issue on my work machine my previous fix isn't working.
I noticed in Google's dev tools that, unlike on my personal machine, the javascript dirs are not being loaded.
Personal machine:
work computer
I wonder if I built the app on my personal computer at some point but I haven't on my work machine?
Solution
The discrepancy I noticed between the browsers was related to sourcemaps. I'd forgotten that I added a flag on my local vite.config.ts that I did not add on my work station:
build: {
outDir: 'build',
sourcemap: true,
}
The azure-functions-cli offers a way to kickoff debugging, but these instructions seem to be Visual Studio specific.
I tried using a similar trick to serverless by setting up a run config in WebStorm to point the JavaScript file to:
\node_modules\azure-functions-cli\lib\main.js
And then passing the Application args:
run myFunctionName --debug
This successfully runs the functions with Azure's tools, but both WebStorm tries to set a debugging port; and when the Azure window opens up it sets its own debugging port.
From Webstorm:
C:\Program Files (x86)\JetBrains\WebStorm 2016.2.3\bin\runnerw.exe" "C:\Program Files\nodejs\node.exe" --debug-brk=60168 --expose_debug_as=v8debug C:\Users\username\AppData\Roaming\npm\node_modules\azure-functions-cli\lib\main.js run myfunction --debug
Debugger listening on [::]:60168
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException:
Likewise, Azure-cli says it opens a debugging port, but they do not match.
As a result, breakpoints set are ignored when the functions are called (Though it does successfully run).
Anybody know how to configure this properly to be able to use WebStorm to debug?
Azure-Functions-CLI was renamed to azure-functions-core-tools. If you still have the Azure-Functions-CLI see my legacy response at the end of this post.
If you're running the new azure-functions-core-tools it looks like they broke the capability to run a remote debugger :-(.
I have the following issue opened and I will update if they tell me otherwise:
https://github.com/Azure/azure-functions-core-tools/issues/378
Fortunately, the new Beta version of the azure-functions-core tools doesn't have all of this C# craziness that prevents it from running on other OSes and requires a remote debugger. To install that version, you can use:
npm i -g azure-functions-core-tools#core
With that version installed, you can launch things with the good 'ol standard Node runtime.
Within WebStorm from Run -> Edit Configurations create a new "Node.JS".
Give the debugging some type of name.
Set the JavaScript file to:
~\AppData\Roaming\npm\node_modules\azure-functions-core-tools\lib\main.js
NOTE: The above assume you installed Azure Functions on a Windows machine with the global flag.
Set the Application Parameters to: start --debug VSCODE
Edit the file ".vscode\launch.json" and change the debug port to 9229 for node.
Within WebStorm choose Run-> Debug:"What_You_Named_the_Remote_Profile"
Add some breakpoints.
Navigate to your API end-point and see that the break-points work.
NOTE: By default it appears the function will be at http://localhost:7071/api/functionName
------------------- EDITED But Below Held for Posterity --------------
Okay, it looks like you can not do this with local debugging, but can with "Remote Debugging" within WebStorm.
Within WebStorm from Run -> Edit Configurations create a new "Node.JS Remote Debug".
Give the debugging some type of name.
Hit the + Sign where it says, "Before Launch: External Tool" and choose "Run External Tool".
Hit the + Sign again and fill it out like the screen-shot (This is assuming you installed the Azure Function CLI globally).
NOTE: The above screenshot has been updated based on the latest version of Azure Functions CLI/. Earlier versions required you to state an app name, and did not require --debug to debug. As a result if you are not updated to the latest version of Azure Functions CLI (now known as Azure-Functions-Core-Tools) you may need to have "run MyApp" in the Parameters field.
Within WebStorm choose Run-> Debug:"What_You_Named_the_Remote_Profile"
Add some breakpoints.
Navigate to your API end-point and see that the break-points work.
NOTE: By default it appears the function will be at http://localhost:7071/api/functionName
Add this to your local.setting.json file under values: "languageWorkers:node:arguments": "--inspect=5858"
Click Edit configuration. Click the plus icon and choose Attachto Node.js/Chrome
Fill in these values for the options: host: localhost - Port: 5858 and set Attac to option to "Crhome or Nod.js>6.3 started with --inpect"
Start the function and run the debugger
See this picture: https://i.stack.imgur.com/hnC74.png
I got an angular application that I need to unit test/debug.
Running the app works.
Running the tests with Karma & Jasmine from console works.
Running the tests with Karma & Jasmine from Intellij "run Configuration" works.
Putting a breakpoint in my tests and launching tests in debug fails.
I configured the latest Chrome as my test browser, installed JetBrains IDE Support extension, configured ok.
The karma server starts, Starts a new Chrome, which gets detected by the output of the Karma server but nothing else happens. Breakpoints are not hit.
Repeating the same process sometimes (!!) work, without changing anything.
Does someone managed to debug a unit test in karma using Jasmine (Mocha runner would work since it is provided in the default configurations of Intellij, but we use Jasmine here.)
Thanks !
I install Webstorm 11 and want to run my tests (for node.js app) implemented with Jasmine.
However it's not easy to do that. I could just type in command line 'jasmine' command and test will be runned, but in this case I'm not able to debug code.
So is there a way to configure Webstorm to deal with jasmine specs as it should?
Ok, so while no one answer at the moment I will try to provide my version:
This flow will allow to run jasmine testsute from Webstrom and debug testcases
install jasmine (ither locally or globally)
in project folder create folder 'spec/support' In this folder place jasmine.json
tests configuration example:
{
"spec_dir": "tests",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
]
}
Create node.js configuration in Webstorm
In this configuration select source file - jasmine executable file (for localy installed
jasmine it will be 'node_modules\jasmine\bin\jasmine.js' )
So you are ready. However at the current moment when trying to debug this configuration - it fails with error:
Cannot stop on breakpoint due to internal error org.jetbrains.v8.V8CommandProcessor$1:
If you faced with it - you need to change Webstom configuration and set this settings:
-Dnodejs.debugger.use.jb.support=false For more details check there:
So this allow you to run jasmine tests and debug them. However there is still some things which this solution not able to do:
Run individual testcases
Run individual testcases with right click button and Run command from menu
Jetbrains, if you reading this - please fix this already. I started play with node in Webstorm 3 years ago and since that moment and dozens of version there is still no nice way to run tests. It's ridiculous.
Jasmine works with the JSTestDriver which you get out-of-the-box with WebStorm 11:
https://www.jetbrains.com/webstorm/help/enabling-javascript-unit-testing-support.html
This page also details how to add Jasmine within JSTestDriver:
https://www.jetbrains.com/webstorm/help/preparing-to-use-jstestdriver-test-runner.html
At a high level you're going to:
Install JSTestDriver from JetBrains plugin repo
Configure it as a WebStorm JavaScript library (https://www.jetbrains.com/webstorm/help/configuring-javascript-libraries.html#configure)
Open jsTestDriver.conf and type the following code in it:
load:
lib/jasmine/jasmine.js
lib/jasmine-jstd-adapter/JasmineAdapter.js
WebStorm doesn't manage test running directly. This job is done by a test runner. WebStorm supports several test runners - Mocha, Karma, JsTestDriver, nodeunit. Most of them can execute Jasmine tests
My general problem is how to run unit tests with karma in IE or other browser installed on a Windows machine, while karma is run on a Linux machine, though in the question below I might ask more specific question based on what I've already tried.
Also it may be worth to mention, that I have Windows installed on a Virtual box machine.
I started karma from a terminal, then opened in IE this url: http://10.0.2.2:9876 and saw the karma page in the browser window (though I spotted some quick blink with a red background, I suppose it is related to an error I'll mention further).
After that I tried to run tests with the command: node_modules/karma/bin/karma run config.js in another terminal tab. When I did this I got this error (I get it even when I use Chrome on my Linux host-machine instead IE on the Virtual box guest, so I suppose the error has nothing to do with networking):
You need to include some adapter that implements __karma__.start method!
I googled for this error and found another question: Error: You need to include some adapter that implements __karma__.start method
Supposing that I need to run tests from the same place I started karma-server I tried to redirect the output to another tab:
$node_modules/karma/bin/karma start &> /dev/pts/17 &
$node_modules/karma/bin/karma run config.js
But this did not help. If I try to start server and run tests in a single command, then I do not have time to register IE.
So could anyone please answer any of the next questions:
how to run unit tests with karma in a browser on other machine?
how to get rid of this error You need to include some adapter that implements __karma__.start method!, if the karma server was started in one terminal tab and the run command was issued in another?
how to start the karma server and run tests in separate steps, i.e. issue the karma start and karma run config.js commands instead of karma start config.js?
My regards and sincerest appreciation in advance for any help.
Currently I've found a workaround for this. I start karma with the config file:
karma start config.js
in the config I have singleRun: false.
Then I manually connect my IE instance, and after this I run the tests from another terminal tab. Why this happens I have no idea. The only inconvenience is that I always have browsers' windows open.