PageRenderTime 60ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/test/test-node/tests/instrumentation_test.js

https://github.com/geekdave/blanket
JavaScript | 127 lines | 112 code | 15 blank | 0 comment | 13 complexity | 12ae5ff67dfb5174fa47dc141755e379 MD5 | raw file
Possible License(s): MIT
  1. var core_fixtures = require("../fixture/core_fixtures");
  2. var assert = require("assert"),
  3. blanketCore = require("../../../src/blanket").blanket;
  4. describe('when instrumenting a file', function(){
  5. it('should instrument comments correctly', function(done){
  6. blanketCore.instrument({
  7. inputFile: core_fixtures.comment_test_file_js,
  8. inputFileName: "comment_test_file"
  9. },function(result){
  10. assert.equal(core_fixtures.comment_test_file_instrumented_js,result);
  11. done();
  12. });
  13. });
  14. it('should instrument branches correctly', function(done){
  15. blanketCore.options("branchTracking",true);
  16. blanketCore.instrument({
  17. inputFile: core_fixtures.branch_test_file_js,
  18. inputFileName: "branch_test_file"
  19. },function(result){
  20. assert.equal(core_fixtures.branch_test_file_instrumented_js,result);
  21. blanketCore.options("branchTracking",false);
  22. done();
  23. });
  24. });
  25. it('should instrument complex branches correctly', function(done){
  26. blanketCore.options("branchTracking",true);
  27. blanketCore.instrument({
  28. inputFile: core_fixtures.branch_complex_test_file_js,
  29. inputFileName: "branch_complex_test_file"
  30. },function(result){
  31. assert.equal(core_fixtures.branch_complex_test_file_instrumented_js,result);
  32. blanketCore.options("branchTracking",false);
  33. done();
  34. });
  35. });
  36. it('should instrument multi-line branches correctly', function(done){
  37. blanketCore.options("branchTracking",true);
  38. blanketCore.instrument({
  39. inputFile: core_fixtures.branch_multi_line_test_file_js,
  40. inputFileName: "multi_line_branch_test_file"
  41. },function(result){
  42. assert.equal(core_fixtures.branch_multi_line_test_file_instrumented_js,result);
  43. blanketCore.options("branchTracking",false);
  44. done();
  45. });
  46. });
  47. });
  48. describe('when a file is instrumented', function(){
  49. describe('if we run the code', function(){
  50. it('should output correct stats', function(done){
  51. blanketCore.options("branchTracking",true);
  52. blanketCore.instrument({
  53. inputFile: core_fixtures.branch_test_file_js,
  54. inputFileName: "branch_test_file2"
  55. },function(result){
  56. eval(result);
  57. BRANCHTEST(0);
  58. var fileResults = global._$jscoverage["branch_test_file2"];
  59. var branchResults = fileResults.branchData[2][7];
  60. assert.equal(branchResults.length > 0,true);
  61. var bothHit = (
  62. typeof branchResults[0] !=='undefined' && branchResults[0].length > 0 &&
  63. typeof branchResults[1] !=='undefined' && branchResults[1].length > 0
  64. );
  65. assert.equal(bothHit,false,"both are not hit.");
  66. BRANCHTEST(1);
  67. bothHit = (
  68. typeof branchResults[0] !=='undefined' && branchResults[0].length > 0 &&
  69. typeof branchResults[1] !=='undefined' && branchResults[1].length > 0
  70. );
  71. assert.equal(bothHit,true,"both are hit.");
  72. blanketCore.options("branchTracking",false);
  73. done();
  74. });
  75. });
  76. it('should output correct stats. even if more complex', function(done){
  77. blanketCore.options("branchTracking",true);
  78. blanketCore.instrument({
  79. inputFile: core_fixtures.branch_complex_test_file_js,
  80. inputFileName: "branch_test_file3"
  81. },function(result){
  82. eval(result);
  83. COMPLEXBRANCHTEST(1,0,0);
  84. COMPLEXBRANCHTEST(0,0,0);
  85. COMPLEXBRANCHTEST(0,2,0);
  86. COMPLEXBRANCHTEST(0,2,3);
  87. var fileResults = global._$jscoverage["branch_test_file3"];
  88. var branchResults = fileResults.branchData[2][7];
  89. assert.equal(branchResults.length > 0,true);
  90. var bothHit = (
  91. typeof branchResults[0] !=='undefined' && branchResults[0].length > 0 &&
  92. typeof branchResults[1] !=='undefined' && branchResults[1].length > 0
  93. );
  94. branchResults = fileResults.branchData[2][24];
  95. assert.equal(branchResults.length > 0,true);
  96. bothHit = bothHit && (
  97. typeof branchResults[0] !=='undefined' && branchResults[0].length > 0 &&
  98. typeof branchResults[1] !=='undefined' && branchResults[1].length > 0
  99. );
  100. branchResults = fileResults.branchData[2][34];
  101. assert.equal(branchResults.length > 0,true);
  102. bothHit = bothHit && (
  103. typeof branchResults[0] !=='undefined' && branchResults[0].length > 0 &&
  104. typeof branchResults[1] !=='undefined' && branchResults[1].length > 0
  105. );
  106. assert.equal(bothHit,true,"all are hit.");
  107. blanketCore.options("branchTracking",false);
  108. done();
  109. });
  110. });
  111. });
  112. });