Monday, 15 August 2011

javascript - How to setup unit testing for multiple require module -


I am working on a code base, where the code is divided into multiple requirement modules. That is, in each section its main main.js are required.

I want to set up code coverage for the whole code base using Karma.

Since each section has its requirejs config, I created a test-main.js for each module.

And there is more karma. Config load loads - main.js files

I'm running into issues. There is a conflict between the base URL

Any thoughts?

You can chain several karma runners through Karma program . Karma to work it programmatically (which is not clear IMHO - some examples can improve it)

First of all you need an array of configurations, so you need to call and call the Karma program. / P>

Create an array of configurations

  function getConfiguration (filename) {return {// You can enrich the template file if you want // example configuration, etc. Add some preprocessor based on. // // If the configuration is not set in template then // Karma launches a single server along with server runner. TRAN: True, // point to configure template: __dirname + filename}; } Configuration to create the function () {return [getconfiguration ('conf1.js'), getConfiguration ('conf2.js'), etc ...]; }  

Karma program initially

  start the function (conf, next) {karma.server.start (conf, function (exitcode) {// Exit code === 0 OK (! ExitCode) {console.log ('\ tTests ran successfully. \ N'); // Redo again with a different configuration ();} else {// bus Exit error code (ExitCode);}});  

Karma Runner

  // Use the Async Library to do things as cleaner works async = require ('async'); Var karma = requirement ('karma'); Var confs = createConfigurations (); Async.eachSeries (Confus, startKarma, function (mistake) {if (err) {console.log ('some went wrong in a runner'); else {console.log ('Yay! All runners have ended' );}});  

No comments:

Post a Comment