PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/test/performance/blanket_performance_test.js

https://github.com/geekdave/blanket
JavaScript | 58 lines | 50 code | 8 blank | 0 comment | 2 complexity | 9095492015eb65dc798874417abc1bb1 MD5 | raw file
Possible License(s): MIT
  1. var test1 = function() {
  2. blanket.options("instrumentCache",true);
  3. blanket.options("debug",true);
  4. expect(2);
  5. var infile = "var a=1;if(a==1){a=2;}if(a==3){a=4;}console.log(a);";
  6. var infilename= "testfile";
  7. blanket.instrument({
  8. inputFile: infile,
  9. inputFileName: infilename
  10. },function(instrumented){
  11. ok( instrumented.length > infile.length, "instrumented." );
  12. ok(instrumented.indexOf("_$blanket['"+infilename+"']") > -1,"added enough instrumentation.");
  13. });
  14. };
  15. var test2 = function() {
  16. expect(1);
  17. blanket.options("instrumentCache",true);
  18. blanket.options("debug",true);
  19. var expected = 4,
  20. result;
  21. var infile = "var a=3;if(a==1){a=2;}else if(a==3){a="+expected+";}\nresult=a;";
  22. var infilename= "testfile2";
  23. blanket.instrument({
  24. inputFile: infile,
  25. inputFileName: infilename
  26. },function(instrumented){
  27. eval(instrumented);
  28. ok( result == expected, "instrumented properly." );
  29. });
  30. };
  31. var test3 = function() {
  32. expect(1);
  33. var result;
  34. blanket.options("instrumentCache",true);
  35. blanket.options("debug",true);
  36. var infile = "var arr=[]; result = window.alert ? (function() {\n for ( var key in arr ) {\n arr[ key ]=0; \n}return true; \n})() : false;";
  37. var infilename= "testfile3";
  38. blanket.instrument({
  39. inputFile: infile,
  40. inputFileName: infilename
  41. },function(instrumented){
  42. eval(instrumented);
  43. ok( result, "instrumented properly." );
  44. });
  45. };
  46. for (var i=0;i<1000;i++){
  47. test( "blanket instrument: "+i, test1);
  48. test( "blanket instrument elseif block: "+i, test2);
  49. test( "blanket instrument for in: "+i, test3);
  50. }