unexpected token errors when running karma plugin in WebStorm with jasmine and angular directives using external templates

I'm trying to test angular directives that uses an external template with Jasmine running with Karma in WebStorm. I'm using OS X Mavericks and use WebStorm 7.0.2 and Karma version 0.10.2. I'm using the Karma runner in Webstorm that comes with Webstorm 7+.
I cloned Vojta Jina's angular directive testing project from git: https://github.com/vojtajina/ng-directive-testing.git . I haven't made any changes to the karma config file. If I run Karma from WebStorm I get the errors:


/usr/local/bin/node /Applications/WebStorm.app/plugins/js-karma/js_reporter/karma-intellij/lib/intellijRunner.js --karmaPackageDir=/Users/mags/WebstormProjects/node_modules/karma --serverPort=9876 --urlRoot=/
Testing started at 4:11 PM ...

Uncaught SyntaxError: Unexpected token <
at http://localhost:9876/base/tpl/pane.html?1387211367000:1

Uncaught SyntaxError: Unexpected token <
at http://localhost:9876/base/tpl/tabs.html?1387211367000:1

Process finished with exit code 0

If I run karma from terminal or just open a terminal window inside of WebStorm it executes fine:


karma start
WARN [karma]: Port 9876 in use
INFO [karma]: Karma v0.10.2 server started at http://localhost:9877/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 31.0.1650 (Mac OS X 10.9.0)]: Connected on socket X9kMCrZtNco2FEPaSEfb
Chrome 31.0.1650 (Mac OS X 10.9.0): Executed 9 of 9 SUCCESS (0.418 secs / 0.101 secs)


I have installed the karma-ng-html2js-preprocessor before but I think it comes bundled with karma now anyway.

Is there anything that needs to be changed in configuration karma configuration in WebStorm? I have also tried to set it up differently in a separate project without using any of the code from Vojta's repository but I get the same errors when I run it from WebStorm.

Thanks,
Magnus

6 comments

Hello!

all I needed to do to make your project run successfully in WebStorm was installing the karma-ng-html2js-preprocessor (npm install karma-ng-html2js-preprocessor -g). I got exactly the same errors on first run (not having karma-ng-html2js-preprocessor installed) plus a message from karma server about missing module. Installing the module fixed the issue for me

0

Thanks Elena. I've tried it before, I tried it again but I keep getting  the same error as before. Thanks for your input!

-Magnus

0

Please can you provide the full content of the Karma server tab of the Run tool window (when you run karma from WebStorm)?

Just tried this on MacOSX 10.9.0, without themodule installed:

/usr/local/bin/node "/Applications/WebStorm 2.app/plugins/js-karma/js_reporter/karma-intellij/lib/intellijServer.js" --karmaPackageDir=/usr/local/lib/node_modules/karma --configFile=/Users/tester/WebstormProjects/angular_dir_karma/karma.conf.js --coverageTempDir=/private/var/folders/_v/5_pp_vxx6gx4_y3x3qnl_bh00000gq/T/karma-intellij-coverage-5639959271835623119.tmp
INFO [karma]: Karma v0.10.8 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
WARN [preprocess]: Can not load "ng-html2js", it is not registered!
Perhaps you are missing some plugin?




Installing the module globally cured the problem immediately - tests run fine
0

Thanks Elena. If I had the same behavior when I ran the same project with the same config file with karma from the command line, I would agree that it seems like something is missing. I am getting the same warning you showed regarding that karma can't load ng-html2js when run from WebStorm. I assume the only way to install it the plugin is via a terminal window either outside of WebStorm or opening up a terminal window from inside of WebStorm. I use the same statement you displayed earlier with the global flag set.

/usr/local/bin/node /Applications/WebStorm.app/plugins/js-karma/js_reporter/karma-intellij/lib/intellijServer.js --karmaPackageDir=/Users/magnus/WebstormProjects/node_modules/karma --configFile=/Users/magnus/WebstormProjects/ng-directive-testing/ng-directive-testing/karma.conf.js --coverageTempDir=/private/var/folders/38/wcpstnd93cb0s3586kq8fypw0000gn/T/karma-intellij-coverage-3954902076857415882.tmp
DEBUG [plugin]: Loading karma-* from /Users/magnus/WebstormProjects/node_modules
DEBUG [plugin]: Loading plugin /Users/magnus/WebstormProjects/node_modules/karma-chrome-launcher.
DEBUG [plugin]: Loading plugin /Users/magnus/WebstormProjects/node_modules/karma-coffee-preprocessor.
DEBUG [plugin]: Loading plugin /Users/magnus/WebstormProjects/node_modules/karma-coverage.
DEBUG [plugin]: Loading plugin /Users/magnus/WebstormProjects/node_modules/karma-firefox-launcher.
DEBUG [plugin]: Loading plugin /Users/magnus/WebstormProjects/node_modules/karma-html2js-preprocessor.
DEBUG [plugin]: Loading plugin /Users/magnus/WebstormProjects/node_modules/karma-jasmine.
DEBUG [plugin]: Loading plugin /Users/magnus/WebstormProjects/node_modules/karma-phantomjs-launcher.
DEBUG [plugin]: Loading plugin /Users/magnus/WebstormProjects/node_modules/karma-requirejs.
DEBUG [plugin]: Loading plugin /Users/magnus/WebstormProjects/node_modules/karma-script-launcher.
DEBUG [plugin]: Loading plugin /Applications/WebStorm.app/plugins/js-karma/js_reporter/karma-intellij/lib/intellijPlugin.js.
DEBUG [plugin]: Loading inlined plugin (defining ).
INFO [karma]: Karma v0.10.2 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
DEBUG [launcher]: Creating temp dir at /var/folders/38/wcpstnd93cb0s3586kq8fypw0000gn/T/karma-46936471
DEBUG [launcher]: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --user-data-dir=/var/folders/38/wcpstnd93cb0s3586kq8fypw0000gn/T/karma-46936471 --no-default-browser-check --no-first-run --disable-default-apps --start-maximized http://localhost:9876/?id=46936471
WARN [preprocess]: Can not load "ng-html2js", it is not registered!
  Perhaps you are missing some plugin?
DEBUG [watcher]: Resolved files:
/Users/magnus/WebstormProjects/node_modules/karma-jasmine/lib/jasmine.js
/Users/magnus/WebstormProjects/node_modules/karma-jasmine/lib/adapter.js
/Users/magnus/WebstormProjects/ng-directive-testing/ng-directive-testing/lib/jquery-1.8.1.min.js
/Users/magnus/WebstormProjects/ng-directive-testing/ng-directive-testing/lib/angular.js
/Users/magnus/WebstormProjects/ng-directive-testing/ng-directive-testing/lib/angular-mocks.js
/Users/magnus/WebstormProjects/ng-directive-testing/ng-directive-testing/js/app.js
/Users/magnus/WebstormProjects/ng-directive-testing/ng-directive-testing/js/tabs.js
/Users/magnus/WebstormProjects/ng-directive-testing/ng-directive-testing/test/helpers.js
/Users/magnus/WebstormProjects/ng-directive-testing/ng-directive-testing/test/tabsSpec.js
/Users/magnus/WebstormProjects/ng-directive-testing/ng-directive-testing/tpl/pane.html
/Users/magnus/WebstormProjects/ng-directive-testing/ng-directive-testing/tpl/tabs.html
DEBUG [web-server]: serving: /Users/magnus/WebstormProjects/node_modules/karma/static/client.html
DEBUG [web-server]: serving: /Users/magnus/WebstormProjects/node_modules/karma/static/karma.js
DEBUG [karma]: A browser has connected on socket DYza9OjEEz60E2y2GpCQ
INFO [Chrome 31.0.1650 (Mac OS X 10.9.1)]: Connected on socket DYza9OjEEz60E2y2GpCQ
DEBUG [karma]: Execution (fired by runner)
DEBUG [karma]: Setting client.args to  undefined
DEBUG [karma]: All browsers are ready, executing
DEBUG [web-server]: serving: /Users/magnus/WebstormProjects/node_modules/karma/static/context.html
DEBUG [web-server]: serving: /Users/magnus/WebstormProjects/node_modules/karma-jasmine/lib/jasmine.js
DEBUG [web-server]: serving: /Users/magnus/WebstormProjects/node_modules/karma-jasmine/lib/adapter.js
DEBUG [web-server]: serving: /Users/magnus/WebstormProjects/ng-directive-testing/ng-directive-testing/lib/angular-mocks.js
DEBUG [web-server]: serving: /Users/magnus/WebstormProjects/ng-directive-testing/ng-directive-testing/lib/angular.js
DEBUG [web-server]: serving: /Users/magnus/WebstormProjects/ng-directive-testing/ng-directive-testing/lib/jquery-1.8.1.min.js
DEBUG [web-server]: serving: /Users/magnus/WebstormProjects/ng-directive-testing/ng-directive-testing/js/tabs.js
DEBUG [web-server]: serving: /Users/magnus/WebstormProjects/ng-directive-testing/ng-directive-testing/js/app.js
DEBUG [web-server]: serving: /Users/magnus/WebstormProjects/ng-directive-testing/ng-directive-testing/test/helpers.js
DEBUG [web-server]: serving: /Users/magnus/WebstormProjects/ng-directive-testing/ng-directive-testing/test/tabsSpec.js
DEBUG [web-server]: serving: /Users/magnus/WebstormProjects/ng-directive-testing/ng-directive-testing/tpl/pane.html
DEBUG [web-server]: serving: /Users/magnus/WebstormProjects/ng-directive-testing/ng-directive-testing/tpl/tabs.html

0

hmm... Seems you have karma installed locally (karmaPackageDir=/Users/magnus/WebstormProjects/node_modules/karma)? I have both karma and
ng-html2js installed globally

See also http://stackoverflow.com/questions/19069183/karma-throws-error-can-not-load-ng-html2js-it-is-not-registered, https://github.com/karma-runner/karma/issues/735

0

Thanks Elena, you nailed down the problem! I have karma installed globally too but I overlooked the karma configuration in WebStorm. Karma node package was pointing to the local directory in each of my  WebStorm projects instead of /usr/local/lib/node_modules/karma. After I changed it, it works great.

0

Please sign in to leave a comment.