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