protractor_spec.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // Copyright 2018 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. var allTests = require('./alltests');
  15. // Timeout for individual test package to complete.
  16. var TEST_TIMEOUT = 45 * 1000;
  17. var TEST_SERVER = 'http://localhost:8080';
  18. var IGNORED_TESTS = [
  19. // Test hangs in IE8.
  20. 'closure/goog/ui/plaintextspellchecker_test.html',
  21. // TODO(joeltine): Re-enable once fixed for external testing.
  22. 'closure/goog/testing/multitestrunner_test.html',
  23. // These Promise-based tests all timeout for unknown reasons.
  24. // Disable for now.
  25. 'closure/goog/testing/fs/integration_test.html',
  26. 'closure/goog/debug/fpsdisplay_test.html',
  27. 'closure/goog/net/jsloader_test.html',
  28. 'closure/goog/net/filedownloader_test.html',
  29. 'closure/goog/promise/promise_test.html',
  30. 'closure/goog/editor/plugins/abstractdialogplugin_test.html',
  31. 'closure/goog/net/crossdomainrpc_test.html',
  32. // Causes flaky Adobe Acrobat update popups.
  33. 'closure/goog/useragent/flash_test.html',
  34. 'closure/goog/useragent/jscript_test.html',
  35. ];
  36. describe('Run all Closure unit tests', function() {
  37. var removeIgnoredTests = function(tests) {
  38. for (var i = 0; i < IGNORED_TESTS.length; i++) {
  39. var index = tests.indexOf(IGNORED_TESTS[i]);
  40. if (index != -1) {
  41. tests.splice(index, 1);
  42. }
  43. }
  44. return tests;
  45. };
  46. beforeAll(function() {
  47. allTests = removeIgnoredTests(allTests);
  48. });
  49. beforeEach(function() {
  50. // Ignores synchronization with angular loading. Since we don't use angular,
  51. // enable it.
  52. browser.ignoreSynchronization = true;
  53. });
  54. // Polls currently loaded test page for test completion. Returns Promise that
  55. // will resolve when test is finished.
  56. var waitForTestSuiteCompletion = function(testPath) {
  57. var testStartTime = +new Date();
  58. var waitForTest = function(resolve, reject) {
  59. // executeScript runs the passed method in the "window" context of
  60. // the current test. JSUnit exposes hooks into the test's status through
  61. // the "G_testRunner" global object.
  62. browser
  63. .executeScript(function() {
  64. if (window['G_testRunner'] &&
  65. window['G_testRunner']['isFinished']()) {
  66. var status = {};
  67. status['isFinished'] = true;
  68. status['isSuccess'] = window['G_testRunner']['isSuccess']();
  69. status['report'] = window['G_testRunner']['getReport']();
  70. return status;
  71. } else {
  72. return {'isFinished': false};
  73. }
  74. })
  75. .then(
  76. function(status) {
  77. if (status && status.isFinished) {
  78. resolve(status);
  79. } else {
  80. var currTime = +new Date();
  81. if (currTime - testStartTime > TEST_TIMEOUT) {
  82. status.isSuccess = false;
  83. status.report = testPath + ' timed out after ' +
  84. (TEST_TIMEOUT / 1000) + 's!';
  85. // resolve so tests continue running.
  86. resolve(status);
  87. } else {
  88. // Check every 300ms for completion.
  89. setTimeout(
  90. waitForTest.bind(undefined, resolve, reject), 300);
  91. }
  92. }
  93. },
  94. function(err) {
  95. reject(err);
  96. });
  97. };
  98. return new Promise(function(resolve, reject) {
  99. waitForTest(resolve, reject);
  100. });
  101. };
  102. it('should run all tests with 0 failures', function(done) {
  103. var failureReports = [];
  104. // Navigates to testPath to invoke tests. Upon completion inspects returned
  105. // test status and keeps track of the total number failed tests.
  106. var runNextTest = function(testPath) {
  107. return browser.navigate()
  108. .to(TEST_SERVER + '/' + testPath)
  109. .then(function() {
  110. return waitForTestSuiteCompletion(testPath);
  111. })
  112. .then(function(status) {
  113. if (!status.isSuccess) {
  114. failureReports.push(status.report);
  115. }
  116. return status;
  117. });
  118. };
  119. // Chains the next test to the completion of the previous through its
  120. // promise.
  121. var chainNextTest = function(promise, test) {
  122. return promise.then(function() {
  123. runNextTest(test);
  124. });
  125. };
  126. var testPromise = null;
  127. for (var i = 0; i < allTests.length; i++) {
  128. if (testPromise != null) {
  129. testPromise = chainNextTest(testPromise, allTests[i]);
  130. } else {
  131. testPromise = runNextTest(allTests[i]);
  132. }
  133. }
  134. testPromise.then(function() {
  135. var totalFailures = failureReports.length;
  136. if (totalFailures > 0) {
  137. console.error('There was ' + totalFailures + ' test failure(s)!');
  138. for (var i = 0; i < failureReports.length; i++) {
  139. console.error(failureReports[i]);
  140. }
  141. }
  142. expect(failureReports.length).toBe(0);
  143. done();
  144. });
  145. });
  146. });