0

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.

Andre Maia
  • 152
  • 1
  • 16

1 Answers1

0

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.

Andre Maia
  • 152
  • 1
  • 16