parallel_closure_test_suite_test.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // Copyright 2015 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the 'License');
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an 'AS-IS' BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. goog.module('goog.testing.parallelClosureTestSuiteTest');
  15. goog.setTestOnly('goog.testing.parallelClosureTestSuiteTest');
  16. var ArgumentMatcher = goog.require('goog.testing.mockmatchers.ArgumentMatcher');
  17. var MockControl = goog.require('goog.testing.MockControl');
  18. var MultiTestRunner = goog.require('goog.testing.MultiTestRunner');
  19. var PropertyReplacer = goog.require('goog.testing.PropertyReplacer');
  20. var TestCase = goog.require('goog.testing.TestCase');
  21. var dom = goog.require('goog.dom');
  22. var jsunit = goog.require('goog.testing.jsunit');
  23. var mockmatchers = goog.require('goog.testing.mockmatchers');
  24. var parallelClosureTestSuite = goog.require('goog.testing.parallelClosureTestSuite');
  25. var testSuite = goog.require('goog.testing.testSuite');
  26. var mocks = new MockControl();
  27. var stubs = new PropertyReplacer();
  28. function setTestRunnerGlobals(
  29. testTimeout, allTests, parallelFrames, parallelTimeout) {
  30. var tr = goog.global['G_parallelTestRunner'] = {};
  31. tr['testTimeout'] = testTimeout;
  32. tr['allTests'] = allTests;
  33. tr['parallelFrames'] = parallelFrames;
  34. tr['parallelTimeout'] = parallelTimeout;
  35. }
  36. testSuite({
  37. tearDown: function() {
  38. goog.global['G_parallelTestRunner'] = undefined;
  39. mocks.$tearDown();
  40. stubs.reset();
  41. },
  42. testProcessAllTestResultsEmptyResults: function() {
  43. var testResults = [];
  44. var allResults =
  45. parallelClosureTestSuite.processAllTestResults(testResults);
  46. assertEquals(0, allResults.totalTests);
  47. assertEquals(0, allResults.totalFailures);
  48. assertEquals('', allResults.failureReports);
  49. assertObjectEquals({}, allResults.allResults);
  50. },
  51. testProcessAllTestResultsNoFailures: function() {
  52. var testResults = [{'testA': []}, {'testB': []}];
  53. var allResults =
  54. parallelClosureTestSuite.processAllTestResults(testResults);
  55. assertEquals(2, allResults.totalTests);
  56. assertEquals(0, allResults.totalFailures);
  57. assertEquals('', allResults.failureReports);
  58. assertObjectEquals({'testA': [], 'testB': []}, allResults.allResults);
  59. },
  60. testProcessAllTestResultsWithFailures: function() {
  61. var testResults = [{'testA': []}, {'testB': ['testB Failed!']}];
  62. var allResults =
  63. parallelClosureTestSuite.processAllTestResults(testResults);
  64. assertEquals(2, allResults.totalTests);
  65. assertEquals(1, allResults.totalFailures);
  66. assertEquals('testB Failed!\n', allResults.failureReports);
  67. assertObjectEquals(
  68. {'testA': [], 'testB': ['testB Failed!']}, allResults.allResults);
  69. var testResults =
  70. [{'testA': ['testA Failed!']}, {'testB': ['testB Failed!']}];
  71. var allResults =
  72. parallelClosureTestSuite.processAllTestResults(testResults);
  73. assertEquals(2, allResults.totalTests);
  74. assertEquals(2, allResults.totalFailures);
  75. assertContains('testB Failed!\n', allResults.failureReports);
  76. assertContains('testA Failed!\n', allResults.failureReports);
  77. assertObjectEquals(
  78. {'testA': ['testA Failed!'], 'testB': ['testB Failed!']},
  79. allResults.allResults);
  80. },
  81. testSetUpPageTestRunnerInitializedProperly: function() {
  82. setTestRunnerGlobals(100, ['foo.html'], 8, 360);
  83. var mockRender =
  84. mocks.createMethodMock(MultiTestRunner.prototype, 'render');
  85. var elementMatcher = new ArgumentMatcher(function(container) {
  86. return dom.isElement(container);
  87. });
  88. var testCaseObj = {promiseTimeout: -1};
  89. stubs.set(
  90. TestCase, 'getActiveTestCase', function() { return testCaseObj; });
  91. mockRender(elementMatcher);
  92. mocks.$replayAll();
  93. var testRunner = parallelClosureTestSuite.setUpPage();
  94. assertArrayEquals(['foo.html'], testRunner.getAllTests());
  95. assertEquals(8, testRunner.getPoolSize());
  96. assertEquals(100000, testRunner.getTimeout());
  97. assertEquals(360000, testCaseObj.promiseTimeout);
  98. mocks.$verifyAll();
  99. testRunner.dispose();
  100. },
  101. testRunAllTestsFailures: function() {
  102. setTestRunnerGlobals(100, ['foo.html', 'bar.html'], 8, 360);
  103. var mockStart = mocks.createMethodMock(MultiTestRunner.prototype, 'start');
  104. var mockFail = mocks.createMethodMock(goog.global, 'fail');
  105. var failureMatcher = new ArgumentMatcher(function(failMsg) {
  106. return /testA Failed!/.test(failMsg) &&
  107. /1 of 2 test\(s\) failed/.test(failMsg);
  108. });
  109. // Don't want this test case's timeout overwritten, so set a stub for
  110. // getActiveTestCase.
  111. stubs.set(
  112. TestCase, 'getActiveTestCase', function() { return {timeout: 100}; });
  113. mockStart();
  114. fail(failureMatcher);
  115. mocks.$replayAll();
  116. var testRunner = parallelClosureTestSuite.setUpPage();
  117. var testPromise = parallelClosureTestSuite.testRunAllTests();
  118. testRunner.dispatchEvent({
  119. 'type': MultiTestRunner.TESTS_FINISHED,
  120. 'allTestResults': [{'testA': ['testA Failed!']}, {'testB': []}]
  121. });
  122. return testPromise.then(function() {
  123. mocks.$verifyAll();
  124. testRunner.dispose();
  125. });
  126. },
  127. testRunAllTestsSuccess: function() {
  128. setTestRunnerGlobals(100, ['foo.html', 'bar.html'], 8, 360);
  129. var mockStart = mocks.createMethodMock(MultiTestRunner.prototype, 'start');
  130. var mockFail = mocks.createMethodMock(goog.global, 'fail');
  131. var failureMatcher = new ArgumentMatcher(function(failMsg) {
  132. return /testA Failed!/.test(failMsg) &&
  133. /1 of 2 test\(s\) failed/.test(failMsg);
  134. });
  135. // Don't want this test case's timeout overwritten, so set a stub for
  136. // getActiveTestCase.
  137. stubs.set(
  138. TestCase, 'getActiveTestCase', function() { return {timeout: 100}; });
  139. mockStart();
  140. fail(mockmatchers.ignoreArgument).$times(0);
  141. mocks.$replayAll();
  142. var testRunner = parallelClosureTestSuite.setUpPage();
  143. var testPromise = parallelClosureTestSuite.testRunAllTests();
  144. testRunner.dispatchEvent({
  145. 'type': MultiTestRunner.TESTS_FINISHED,
  146. 'allTestResults': [{'testA': []}, {'testB': []}]
  147. });
  148. return testPromise.then(function() {
  149. mocks.$verifyAll();
  150. testRunner.dispose();
  151. });
  152. }
  153. });