node.js - How do I test child processes using chai and mocha? -


i'm creating framework execute processes @ specific time (cron-like) , test i'm using chai-mocha-grunt.

the architecture of solution based on this example. basically, have:

  • a master process, calls child (via child_process.fork) specific number of times.
  • a child process, executes using setinverval();
  • a process call master.start() function.

with architecture how test ensure threads executed @ correct time using mocha , chai (with 'assert' library)?

in other words, how make chai 'listen' threads , check if executed @ correct time?

i'm not sure need chai listen threads. if you're building off of example linked should pretty straight forward because master.js eventemitter , it's emitting events hears child processes.

your test structure simple this:

describe('forkexample test', function() {     // set appropriate test timeout here     this.timeout(1000);      it('should stuff @ right time', function(done) {         var fe = new forkexample();         fe.start(1);         fe.on('event', function(type, pid, e) {             if (type === 'child message') {                 // check here timing within expected range                 done();             }         });     }); }); 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -