protractor_spec.js 4.9 KB

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