How to integrate Karma with SlimerJS for testing ES6 code? - slimerjs

I'm trying to integrate SlimerJS with Karma to be able to test ECMAScript 6 and AngularJS code.
When I tested ES6 code directly with SlimerJS it loads the version 0.10.2 that I installed and its works for my ES6 code.
My Firefox installed is version 50.1.0 and it works correctly with the SlimerJS when I call it directly through SlimerJS. My SLIMERJSLAUNCHER variable has been configured correctly as the SlimerJS documentation indicates to do.
But I need test AngularJS and ES6 code, so I need Karma, but don't found a way to integrate SlimerJS with Karma.
I tryed to use karma-slimerjs-launcher, but it is loading an older version of both Firefox and SlimerJS.
When I call Karma the karma-slimerjs-launcher is running Firefox 38 and SlimerJS 0.9.6 and so I lose support for ECMAScript 6.
There is a way to make karma-slimerjs-launcher call the versions of Firefox and SlimerJS that I have installed on my system instead of calling those "embedded" versions that it seems to bring?
Or there is a better way to integrate Karma and SlimerJS without karma-slimerjs-launcher?
Thanks.

I discovered the answer to the problem.
Instead of using the launcher that comes with outdated versions it is possible to simply start karma normally without any browser.
Just enter:
karma start
Then it is possible to start the SlimerJS headless with the command:
Xvfb-run ./slimerjs myscript.js
In the JS script we point the navigation to the karma server:
window.location.href = 'http://localhost:9876/';
Once the SlimerJS enters the Karma server the tests start to run.
The disadvantage of this method is that it takes two terminal windows to run the tests, so I did a little script in Python to solve this and serve as a launcher:
#!/usr/bin/env python3
import subprocess
import time
karma = ''
slimerjs = ''
while True:
try:
if not karma:
# Load a Karma server
print('\nKarma is loading...\n')
karma = subprocess.Popen('./karma start', shell=True)
# delays for 2 seconds for waiting Karma server
time.sleep(2)
# Load a headless SlimerJS that points to Karma server
slimerjs = subprocess.Popen(
'xvfb-run slimerjs slimerjs-cfg.js > slimerjs.log', shell=True)
print('\nSlimerJS is running...\n')
except KeyboardInterrupt:
karma.kill()
print('\n\nKarma is stopped...\n')
slimerjs.kill()
print('\nSlimerJS is stopped...\n')
break
With this to start the karma together with the slimerJS in a single console window just type:
./karma-run.py
If someone else has the same problem integrating karma with slimerjs to test ES6 this was my solution.

Related

Cannot debug Nodejs with node-inspector: websocket_closed and Assertion failed: Unknown experiment canvasInspection

I try to debug my server.js app with node-inspector (v0.12.8), nodejs (v5.9.1) and chrome (v49.0.2623.112 m) under windows environment.
In a shell i do
node-inspector
Node Inspector v0.12.8 Visit http://127.0.0.1:8080/?port=5858 to start debugging.
In a second shell i do
node --debug server.js
When i go to chrome tab i obtain a message:
Detached from target
remote debug has been terminated with reason: websocket_closed
please reattach to the new target
In the console dev tool of chrome i can see either a message that inspector can't find experimental function canvasInspection (removed in the latest chrome version).
I'm doing something wrong?
Not the answer specifically, but as of Node v6, you can actually just use the --inspect flag when you start a process, and it will let you use the Chrome debugging tools instead of relying on node-inspector. Check it out:
https://nodejs.org/docs/latest/api/debugger.html#debugger_v8_inspector_integration_for_node_js
Hope this helps!
I had the same problem, I fixed it the way below:
1- Go and edit the following file in your currently in use nodejs path:
...\node_modules\node-inspector\lib\InjectorClient.js
2- Go to line 111. if you're using vim as text editor you can do it by command :111
3- Add the following if statement at line 111 and indent the next line.
if(NM.length > 0)
cb(error, NM[0].ref);
4- Save and re-run node-inspector.
Cheers!
I'm using MacOS Sierra, Node v6.3.1. But the solution is general.
I had also faced this issue , but after lots of googling and finding about this issue. The only thing work for me is listed below :
Open your Command Promp(cmd) & type node -v, it will show you the version of node installed on your machine.
If the installed version is something 5.x.x or 6.x.x , then proceed further.
just uninstall this node version from control panel.
Install the node release with version 4 . I've tested with Node version v4.5.0 & I hope it will work fine for all Node with version v4.x.x.
Uninstall the previous node-inspector with command npm uninstall node-inspector -g.
Then Install again with command npm install node-inspector -g.
Then start debugging .. :)

Protactor error, Unexpected token )

I was about start learning protractor and following the simple tutorial in there http://www.protractortest.org/#/tutorial
but unfortunately getting weird error after run this command protractor conf.js
[launcher] Process exited with error code 1
/usr/local/lib/node_modules/protractor/node_modules/q/q.js:126
throw e;
SyntaxError: Unexpected token )
at goog.loadModuleFromSource_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1123:19)
at Object.goog.loadModule (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1085:46)
at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1:6
at Object.Context.closure.goog.retrieveAndExecModule_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/_base.js:135:8)
at <anonymous>:1:6
at Context.closure.closure.vm.createContext.CLOSURE_IMPORT_SCRIPT (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/_base.js:104:12)
at Object.goog.importScript_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:879:9)
at Object.goog.importModule_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:900:14)
at Object.goog.writeScripts_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1323:16)
at Object.goog.require (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:663:14)
node version : v0.10.37
java version : 1.8.0_66
protractor : Version 3.0.0
jadmine : jasmine v2.3.2 jasmine-core v2.3.4
UPDATE
already clone the repository https://github.com/angular/protractor
run following command
./bin/webdriver-manager update --standalone
./bin/webdriver-manager start
open new terminal tab
change to website direcotry
run the website folder using npm start and the website already running on port 8080
open new terminal tab, still under website folder
run test command npm test then chrome browser open up in a few second
and show same error above
Protractor upgraded to WebDriver 2.48.2 with their release of version 3.0.0. This version of WebDriver is not compatible with Node.js versions < 4.
From CHANGELOG.md in the Protractor project:
(18e1f71) chore(webdriver): upgrade Protractor to webdriver 2.48.2
BREAKING CHANGE:
1) Users will no longer be able to use node versions < 4.
2) There are significant changes to the control flow, and tests may need to be modified to be compliant with the new control flow. See Changes
Downgrading Protractor to 2.5.1 or upgrading Node.js to >= v4.0.0 should solve your problem. See here for more info on breaking changes in Protractor v3.0.0.

Karma Unit Testing

I'm having trouble trying to figure out the reason for this error when trying to start karma:
bash-3.2$ NODE_ENV=test karma start
INFO [karma]: Karma v0.12.31 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.8 (Mac OS X)]: Connected on socket FONtQ1oNxIxRecRxYgnS with id 73511945
PhantomJS 1.9.8 (Mac OS X) ERROR
ReferenceError: Can't find variable: require
at /public/components/angular-cookies/index.js:1
The index.js file contains:
require('./angular-cookies');
module.exports = 'ngCookies';
Please help!!
One way to fix this is to npm install karma-browserify --save-dev. That should work and you will have to do that if the actual file you need uses require.
index.js is not the actual file you need. angular-cookies.js is.
I find that using browserify makes debugging test errors more difficult because the stack trace you get from karma would refer to line numbers from temporary .browserify bundles that already got deleted by the time your test is done.
A simple solution is to point files in karma.conf.js directly to angular-cookies.js instead of using wildcards. This way, index.js and its usage of require will not cause unnecessary issue.
require is nodejs feature
try install this karma-browserify, it allow you to use "require"
Try adding browserify as a
preprocessor:
'test/**/*.js': ['browserify']
and add it to your frameworks

Node inspector debugging

I am currently having trouble getting node inspector to work with Google Chrome. I am on Windows 7 64 bit.
here is info about node-inspector:
https://github.com/node-inspector/node-inspector
when I run the following
node-debug app.js
on a simple JavaScript file called app.js:
a = 5;
b = 6;
c = a + b;
console.log(c);
and I open up Chrome with the following URL:
http://localhost:8080/debug?port=5858
all I get is this empty page with nothing loaded except one little part of the Chrome debugging toolbar, no matter what I do, I even reinstalled Chrome ( and the Canary developer version too):
Anyone have any idea what could be going wrong? This is the simplest JavaScript application ever, and there node-inspector directions does not specify any other steps to take. Like I said, I resinstalled Chrome. I have node version v0.10.30, npm version v1.4.21 version and node-inspector version: v0.7.4.
Does anyone have a good idea how I can test Chrome debugging tools without involving node? I am new to all this.
When I installed node-inspector, I did get what looks like a warning:
Try starting it without node-debug wrapper.
So, install node inspector:
npm install -g node-inspector
In one terminal:
node --debug-brk app.js
In a different terminal:
node-inspector
Browse to http://localhost:8080/debug?port=5858
i had the same issue. i then uninstalled node-inspector, installed it again. closed the cmd prompt which installed node-inspector (maybe this step made the difference). opened another cmd prompt to node-debug my.js. i can see the source file now.
I had a similar issue where going to http://localhost:8080/debug?port=5858 would result in an empty page. However going to http://127.0.0.1:8080/debug?port=5858 seems to do the trick.

node inspector with mocha not working with 'debugger' command

I am using mocha to test my code. I am using node inspector to debug my code.
bash
mocha test/test.* --debug-brk
This works but not so well. It stops at the first line of code in mocha. I want it to stop it at my code. I tried using the 'debugger' key word to make a manual breakpoint but some how it does not stop there.
Try placing a breakpoint at the bottom of the mocha library per this issue. For some reason that allows debugger statements in your modules to pause the node debugger.
However it doesn't seem to stop at debugger statements in the spec itself. I have a SO question highlighting that problem.
I was on the latest node version, using the node-debug command (to launch node-inspector and having the same issues you were. Here's what I'm rolling with currently:
Using the following versions:
node: 0.11.13 (I downgraded from latest) <-- I specifically had to use this one
mocha: 2.2.1 <-- might work with any
node-inspector: 0.9.2 <-- might work with any
Start your tests using the following command:
node-debug _mocha test/unit-tests.js
Navigate to your test file and start putting in breakpoints, then hit run. I usually put one up by the 'requires' of my test file, and several within my 'it' functions.
Hope that helps, and that one day this kind of thing will just work :P
Got the idea to downgrade node from here:
https://www.bountysource.com/issues/7978672-script-is-resumed-as-soon-as-node-inspector-is-loaded
And the command from here:
https://github.com/node-inspector/node-inspector#how-do-i-debug-mocha-unit-tests

Resources