- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2
 
Testing
Now node-webkit's testing works have two parts: automatic tests and manual test. Node-webkit uses Mocha to run automatic tests.
How to run node-webkit's test cases
In folder automatic_tests, every subdirectory has a file called mocha_test.js. In mocha_test.js, there are test cases written using mocha. Finally we load these test cases and run them in index.html. The structure is:
node-webkit/
|-- src/
`-- tests/
    |-- index.html
    |-- ...
    `-- automatic_tests/
        |-- ...
        `-- node/
            |-- mocha_test.js
Mocha is easy to use, we can directly write mocha code in mocha_test.js. But if we have a simple app and want to use it, there are some traps.
We need to spawn a new process for the app, but there would be a problem with using the communication method of node.js' child_process module. So we need to use other method for the data transporting like using socket.
In node-webkit testing system, we have implemented a simple module nw_test_app for the job. How to use it:
mocha_test.js:
var child = app_test.createChildProcess({
  execPath: process.execPath,
  appPath: 'path_to_app',
  end: function(data, app) {
    if (data.ok) {
      done();
    } else {
      done('error');
    }
  }
});app:
var client = require('nw_test_app').createClient({
  argv: gui.App.argv,
  data: {ok : true},
});