0.1.0 • Published 9 years ago

karma-addgears-launcher v0.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

Karma Addgears Launcher

Addgears is the application which provides a set of useful tools for e-commerce. Karma Addgears Launcher enables unit tests in Addgears using a Karma test runner.

Addgears is based on the node-webkit and is highly customizable. Addgears extension is just a set of node.js modules and HTML pages. Addgears package along with grunt-addgears delivers Addgears integration with node.js: scripting, access to Addgears API and grunt tasks to automate installation, updates and resource packaging. These tools warrant that anyone may take existing node.js packages, CSS, Javascript and HTML files and reuse them to create rich desktop application running on node-webkit platform.

Still, to make better use of node-webkit and Addgeras APIs, a closer integration may be desired. Karma Addgears Launcher provides all the plumbing necessary to test and develop applications directly in Addgears, using popular open source Karma test runner.

Installation

Install the package using npm command:

npm install karma-addgears-launcher --save-dev

To make developer's path smoother, you may whish to install addgears package, grunt-cli and grunt-addgears first. Karma Addgears Launcher comes with the examples directory, containing simple project setup including Karma and Addgears configuration files, useful grunt configuration and mocha test.

Configuration

Configuring Addgears Launcer is as simple as adding "Addgers" to the browsers list in karma.conf.js:

// start Addgears browser
        browsers: ["Addgears"],   

With this configuration, upon karma start, Karma tests runner starts Addgers application and opens the test in a separate iframe. In this iframe the common node-webkit environment with both node.js modules and HTML DOM becomes accessible.

To debug Javascript files just connect to Addgears on the remote port (http://localhost:9222/), or modify standard node-webkit configuration file package.json in app.nw subdirectory of the Addgears installation directory:

  .........
    "window": {
        // show toolbar with developer tools
        "toolbar": true
    }, 

As Karma test is loaded in a separate domain (e.g. http://localhost:9876), karma tests don't have the direct access to resources loaded to Addgears. To gain access to Addgears resources, the test should load resources to the Karma tests domain. The lib/boot.js file in Karma Launcher subdirectory provides InitAddgears class with install and boot methods (to load resources and provide the access accordingly):

  InitAddgears
  .install({ // loads update asynchronousely
      update:"c:/tmp/update", // directory containing the update bundle
      keepUpdate:true // don't remove update (after applied
  })
  .then(function () {
      return InitAddgears.boot(); // boot before access to _Addgears_ API
  })
  .then(function () {
      assert.equal(!!window["Addgears"], true); // now _Addgears_ object is available
      done();
  });

Other useful tools

To make better use of Addgears, other tools could be useful as well. Consider a simple setup, found in the example directory:

 cd examples
 npm install

Grunt tasks from addgears package (grunt.loadNpmTasks('addgears')) add helpful functionality. Download current Addgear bundle using grunt downloadUpdate. Unzip and load update to the Karma test domain running grunt unzip and grunt addgearsApplyUpdate accordingly. To open later page on Karma test domain run grunt addgearsRun.

// from examples/Gruntfile.js configuration
   downloadUpdate:{
       main:{
           path:'update.zip'                
       }
   },       
   addgearsApplyUpdate:{
       origin:{
           options:{
               updateOrigin:"http://localhost:9876"
           },
           src:["c:/tmp/update"] 
       }
   },
   addgearsRun:{
       origin:{
           page:'http-server.js@open-url.js',
           options:{
               command: [
               "-httpServerRoot", ".",
               "-httpPort", 9876,                    
               "-openUrl","http://localhost:9876/page.html?page=pages/pricer/main.html"
               ]
           }                
       }
   },

Gruntfile.js also contains unzip and karma grunt tasks to unzip update bundle and startKarma tests runner:

        unzip:{
            update: {
                src: ['update.zip'],
                dest: 'c:/tmp'
            }
        },                                     
        karma: {
            options: {
                configFile: 'karma.conf.js'
            },            
            addgears:{
                singleRun: false,
                autoWatch:true,                
                browsers: ['Addgears']
            }            
        }

License

This package is licensed under MIT license. Addgears is licensed separately. To use it you must agree with the terms and conditions first.