Debian Codegraph @

closure-library/closure/goog/testing/parallel_closure_test_suite_test.js

raw
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
15 goog.module('goog.testing.parallelClosureTestSuiteTest');
16 goog.setTestOnly('goog.testing.parallelClosureTestSuiteTest');
17
18 var ArgumentMatcher = goog.require('goog.testing.mockmatchers.ArgumentMatcher');
19 var MockControl = goog.require('goog.testing.MockControl');
20 var MultiTestRunner = goog.require('goog.testing.MultiTestRunner');
21 var PropertyReplacer = goog.require('goog.testing.PropertyReplacer');
22 var TestCase = goog.require('goog.testing.TestCase');
23 var dom = goog.require('goog.dom');
24 var jsunit = goog.require('goog.testing.jsunit');
25 var mockmatchers = goog.require('goog.testing.mockmatchers');
26 var parallelClosureTestSuite = goog.require('goog.testing.parallelClosureTestSuite');
27 var testSuite = goog.require('goog.testing.testSuite');
28
29 var mocks = new MockControl();
30 var stubs = new PropertyReplacer();
31
32 function setTestRunnerGlobals(
33 testTimeout, allTests, parallelFrames, parallelTimeout) {
34 var tr = goog.global['G_parallelTestRunner'] = {};
35 tr['testTimeout'] = testTimeout;
36 tr['allTests'] = allTests;
37 tr['parallelFrames'] = parallelFrames;
38 tr['parallelTimeout'] = parallelTimeout;
39 }
40
41 testSuite({
42 tearDown: function() {
43 goog.global['G_parallelTestRunner'] = undefined;
44 mocks.$tearDown();
45 stubs.reset();
46 },
47
48 testProcessAllTestResultsEmptyResults: function() {
49 var testResults = [];
50 var allResults =
51 parallelClosureTestSuite.processAllTestResults(testResults);
52 assertEquals(0, allResults.totalTests);
53 assertEquals(0, allResults.totalFailures);
54 assertEquals('', allResults.failureReports);
55 assertObjectEquals({}, allResults.allResults);
56 },
57
58 testProcessAllTestResultsNoFailures: function() {
59 var testResults = [{'testA': []}, {'testB': []}];
60 var allResults =
61 parallelClosureTestSuite.processAllTestResults(testResults);
62 assertEquals(2, allResults.totalTests);
63 assertEquals(0, allResults.totalFailures);
64 assertEquals('', allResults.failureReports);
65 assertObjectEquals({'testA': [], 'testB': []}, allResults.allResults);
66 },
67
68 testProcessAllTestResultsWithFailures: function() {
69 var testResults = [{'testA': []}, {'testB': ['testB Failed!']}];
70 var allResults =
71 parallelClosureTestSuite.processAllTestResults(testResults);
72 assertEquals(2, allResults.totalTests);
73 assertEquals(1, allResults.totalFailures);
74 assertEquals('testB Failed!\n', allResults.failureReports);
75 assertObjectEquals(
76 {'testA': [], 'testB': ['testB Failed!']}, allResults.allResults);
77
78 var testResults =
79 [{'testA': ['testA Failed!']}, {'testB': ['testB Failed!']}];
80 var allResults =
81 parallelClosureTestSuite.processAllTestResults(testResults);
82 assertEquals(2, allResults.totalTests);
83 assertEquals(2, allResults.totalFailures);
84 assertContains('testB Failed!\n', allResults.failureReports);
85 assertContains('testA Failed!\n', allResults.failureReports);
86 assertObjectEquals(
87 {'testA': ['testA Failed!'], 'testB': ['testB Failed!']},
88 allResults.allResults);
89 },
90
91 testSetUpPageTestRunnerInitializedProperly: function() {
92 setTestRunnerGlobals(100, ['foo.html'], 8, 360);
93 var mockRender =
94 mocks.createMethodMock(MultiTestRunner.prototype, 'render');
95 var elementMatcher = new ArgumentMatcher(function(container) {
96 return dom.isElement(container);
97 });
98 var testCaseObj = {promiseTimeout: -1};
99 stubs.set(
100 TestCase, 'getActiveTestCase', function() { return testCaseObj; });
101
102 mockRender(elementMatcher);
103
104 mocks.$replayAll();
105
106 var testRunner = parallelClosureTestSuite.setUpPage();
107 assertArrayEquals(['foo.html'], testRunner.getAllTests());
108 assertEquals(8, testRunner.getPoolSize());
109 assertEquals(100000, testRunner.getTimeout());
110 assertEquals(360000, testCaseObj.promiseTimeout);
111 mocks.$verifyAll();
112 testRunner.dispose();
113 },
114
115 testRunAllTestsFailures: function() {
116 setTestRunnerGlobals(100, ['foo.html', 'bar.html'], 8, 360);
117 var mockStart = mocks.createMethodMock(MultiTestRunner.prototype, 'start');
118 var mockFail = mocks.createMethodMock(goog.global, 'fail');
119 var failureMatcher = new ArgumentMatcher(function(failMsg) {
120 return /testA Failed!/.test(failMsg) &&
121 /1 of 2 test\(s\) failed/.test(failMsg);
122 });
123 // Don't want this test case's timeout overwritten, so set a stub for
124 // getActiveTestCase.
125 stubs.set(
126 TestCase, 'getActiveTestCase', function() { return {timeout: 100}; });
127
128 mockStart();
129 fail(failureMatcher);
130
131 mocks.$replayAll();
132
133 var testRunner = parallelClosureTestSuite.setUpPage();
134 var testPromise = parallelClosureTestSuite.testRunAllTests();
135 testRunner.dispatchEvent({
136 'type': MultiTestRunner.TESTS_FINISHED,
137 'allTestResults': [{'testA': ['testA Failed!']}, {'testB': []}]
138 });
139
140 return testPromise.then(function() {
141 mocks.$verifyAll();
142 testRunner.dispose();
143 });
144 },
145
146 testRunAllTestsSuccess: function() {
147 setTestRunnerGlobals(100, ['foo.html', 'bar.html'], 8, 360);
148 var mockStart = mocks.createMethodMock(MultiTestRunner.prototype, 'start');
149 var mockFail = mocks.createMethodMock(goog.global, 'fail');
150 var failureMatcher = new ArgumentMatcher(function(failMsg) {
151 return /testA Failed!/.test(failMsg) &&
152 /1 of 2 test\(s\) failed/.test(failMsg);
153 });
154 // Don't want this test case's timeout overwritten, so set a stub for
155 // getActiveTestCase.
156 stubs.set(
157 TestCase, 'getActiveTestCase', function() { return {timeout: 100}; });
158
159 mockStart();
160 fail(mockmatchers.ignoreArgument).$times(0);
161
162 mocks.$replayAll();
163
164 var testRunner = parallelClosureTestSuite.setUpPage();
165 var testPromise = parallelClosureTestSuite.testRunAllTests();
166 testRunner.dispatchEvent({
167 'type': MultiTestRunner.TESTS_FINISHED,
168 'allTestResults': [{'testA': []}, {'testB': []}]
169 });
170
171 return testPromise.then(function() {
172 mocks.$verifyAll();
173 testRunner.dispose();
174 });
175 }
176 });